@File : scores.py @Time : 2024/09/18 10:43:17 @Author : Alejandro Marrero @Version : 1.0 @Contact : amarrerd@ull.edu.es @License : (C)Copyright 2024, Alejandro Marrero @Desc : None

maximise_perf_gap_easy(scores, aggregate_fn=np.mean)

Maximum performance bias gap to target.

It tries to maximise the gap between the target solver and the other solvers in the portfolio. Use this metric to generate instances that are EASY to solve by the target algorithm

Parameters:
  • scores (ndarray[float]) –

    Scores of each solver over every instances. It is expected that the first value is the score of the target.

  • aggregate_fn (Callable, default: mean ) –

    Function to aggregate the result of multiple repetitions. by default, it uses np.mean.

Returns:
  • ndarray

    np.ndarray: Performance biases for every instance. Instance.p attribute.

Source code in digneapy/core/_scores.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def maximise_perf_gap_easy(
    scores: np.ndarray, aggregate_fn: Callable = np.mean
) -> np.ndarray:
    """Maximum performance bias gap to target.

    It tries to maximise the gap between the target solver
    and the other solvers in the portfolio.
    Use this metric to generate instances that are EASY to solve by the target algorithm

    Args:
        scores (np.ndarray[float]): Scores of each solver over every instances. It is expected
            that the first value is the score of the target.
        aggregate_fn (Callable): Function to aggregate the result of multiple repetitions.
            by default, it uses np.mean.

    Returns:
        np.ndarray: Performance biases for every instance. Instance.p attribute.
    """
    if scores.ndim < 2 or scores.ndim > 3:
        raise ValueError(
            "Expected a 2d or 3d numpy array (i, solver, repetitions)"
            "Where `i` is the number of instances, `solver` the number of solvers in the portfolio, "
            "and repetitions is the number of repetitions performed by the solver on each instance."
            f" Instead, scores have shape: {scores.shape}"
        )
    elif scores.ndim == 2:
        return scores[:, 0] - np.max(scores[:, 1:], axis=1)
    else:
        aggregated = aggregate_fn(scores, axis=-1)
        return aggregated[:, 0] - np.max(aggregated[:, 1:], axis=-1)

maximise_perf_gap_hard(scores, aggregate_fn=np.mean)

Maximum performance bias gap between others and target.

It tries to maximise the gap between the target solver and the other solvers in the portfolio. Use this metric to generate instances that are HARD to solve by the target algorithm

Parameters:
  • scores (ndarray[float]) –

    Scores of each solver over every instances. It is expected that the first value is the score of the target.

  • aggregate_fn (Callable, default: mean ) –

    Function to aggregate the result of multiple repetitions. by default, it uses np.mean.

Returns:
  • ndarray

    np.ndarray: Performance biases for every instance. Instance.p attribute.

Source code in digneapy/core/_scores.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def maximise_perf_gap_hard(
    scores: np.ndarray, aggregate_fn: Callable = np.mean
) -> np.ndarray:
    """Maximum performance bias gap between others and target.

    It tries to maximise the gap between the target solver
    and the other solvers in the portfolio.
    Use this metric to generate instances that are HARD to solve by the target algorithm

    Args:
        scores (np.ndarray[float]): Scores of each solver over every instances. It is expected
            that the first value is the score of the target.
        aggregate_fn (Callable): Function to aggregate the result of multiple repetitions.
            by default, it uses np.mean.

    Returns:
        np.ndarray: Performance biases for every instance. Instance.p attribute.
    """
    if scores.ndim < 2 or scores.ndim > 3:
        raise ValueError(
            "Expected a 2d or 3d numpy array (i, solver, repetitions)"
            "Where `i` is the number of instances, `solver` the number of solvers in the portfolio, "
            "and repetitions is the number of repetitions performed by the solver on each instance."
            f" Instead, scores have shape: {scores.shape}"
        )
    if scores.ndim == 2:
        return max(scores[:, 0]) - np.min(scores[:, 1:], axis=1)
    else:
        aggregated = aggregate_fn(scores, axis=-1)
        return max(aggregated[:, 0]) - np.min(aggregated[:, 1:], axis=-1)

maximise_runtime_gap(runtimes, aggregate_fn=np.max)

Runtime based metric.

It tries to maximise the gap between the running time of the target solver
and the other solvers in the portfolio. Use this metric with exact solvers
which provide the same objective values for an instance. The goal is that
the instances generated would take less time to solve by the target solver.
Parameters:
  • runtimes (ndarray[float]) –

    Running times of each solver over every instances. It is expected that the first value is the score of the target.

  • aggregate_fn (Callable, default: max ) –

    Function to aggregate the result of multiple repetitions. by default, it uses np.max.

Returns:
    np.ndarray: Performance biases for every instance. Instance.p attribute.
Source code in digneapy/core/_scores.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
def maximise_runtime_gap(
    runtimes: np.ndarray, aggregate_fn: Callable = np.max
) -> np.ndarray:
    """Runtime based metric.

        It tries to maximise the gap between the running time of the target solver
        and the other solvers in the portfolio. Use this metric with exact solvers
        which provide the same objective values for an instance. The goal is that
        the instances generated would take less time to solve by the target solver.

    Args:
            runtimes (np.ndarray[float]): Running times of each solver over every instances.
                It is expected  that the first value is the score of the target.
            aggregate_fn (Callable): Function to aggregate the result of multiple repetitions.
                by default, it uses np.max.

        Returns:
            np.ndarray: Performance biases for every instance. Instance.p attribute.
    """
    if runtimes.ndim < 2 or runtimes.ndim > 3:
        raise ValueError(
            "Expected a 2d or 3d numpy array (i, solver, repetitions)"
            "Where `i` is the number of instances, `solver` the number of solvers in the portfolio, "
            "and repetitions is the number of repetitions performed by the solver on each instance."
            f" Instead, scores have shape: {runtimes.shape}"
        )
    if runtimes.ndim == 2:
        return np.min(runtimes[:, 1:], axis=1) - runtimes[:, 0]
    else:
        aggregated = aggregate_fn(runtimes, axis=-1)
        return np.min(aggregated[:, 1:], axis=-1) - aggregated[:, 0]