nmoo.indicators.delta_f_pareto

ΔF-Pareto performance indicator, which measures how accurately a problem estimates the true objective of pareto individuals, unlike nmoo.indicators.delta_f.DeltaF which considers all individuals.

 1"""
 2ΔF-Pareto performance indicator, which measures how accurately a problem
 3estimates the true objective **of pareto individuals**, unlike
 4`nmoo.indicators.delta_f.DeltaF` which considers **all** individuals.
 5"""
 6__docformat__ = "google"
 7
 8from typing import Any, Dict
 9
10import numpy as np
11
12from nmoo.utils.population import pareto_frontier_mask
13from .delta_f import DeltaF
14
15
16class DeltaFPareto(DeltaF):
17    """
18    The ΔF-Pareto performance indicator. Given
19    * a `nmoo.wrapped_problem.WrappedProblem` with `g` its ground problem,
20    * a population `X`,
21    * and their image (under the objective function) array `F`,
22
23    calculates the vectorized average Euclidean distance between `F'` and `Y`,
24    where `F'` is the subarray corresponding to Pareto individuals in `X`, and
25    where `Y` is obtained by averaging `g(X)` a given number of times.
26
27    You can use this PI in a benchmark as
28    ```py
29    Benchmark(
30        ...
31        performance_indicators=[..., "dfp", ...]
32    )
33    ```
34    """
35
36    # pylint: disable=duplicate-code
37    def _do(self, F: np.ndarray, *args, **kwargs) -> float:
38        """
39        Calculates ΔF. See class documentation.
40        """
41        if not args:
42            raise ValueError(
43                "Need a second argument (namely the X array) when calling "
44                "DeltaF.do"
45            )
46        pfm = pareto_frontier_mask(F)
47        X, F, fs = args[0][pfm], F[pfm], []
48        for _ in range(self._n_evals):
49            out: Dict[str, Any] = {}
50            self._ground_problem._evaluate(X, out, *args, **kwargs)
51            fs.append(out["F"])
52        self._history = {"X": X, "F": np.mean(np.array(fs), axis=0)}
53        self.dump_history()
54        return np.mean(np.linalg.norm(F - self._history["F"], axis=-1))
class DeltaFPareto(nmoo.indicators.delta_f.DeltaF):
17class DeltaFPareto(DeltaF):
18    """
19    The ΔF-Pareto performance indicator. Given
20    * a `nmoo.wrapped_problem.WrappedProblem` with `g` its ground problem,
21    * a population `X`,
22    * and their image (under the objective function) array `F`,
23
24    calculates the vectorized average Euclidean distance between `F'` and `Y`,
25    where `F'` is the subarray corresponding to Pareto individuals in `X`, and
26    where `Y` is obtained by averaging `g(X)` a given number of times.
27
28    You can use this PI in a benchmark as
29    ```py
30    Benchmark(
31        ...
32        performance_indicators=[..., "dfp", ...]
33    )
34    ```
35    """
36
37    # pylint: disable=duplicate-code
38    def _do(self, F: np.ndarray, *args, **kwargs) -> float:
39        """
40        Calculates ΔF. See class documentation.
41        """
42        if not args:
43            raise ValueError(
44                "Need a second argument (namely the X array) when calling "
45                "DeltaF.do"
46            )
47        pfm = pareto_frontier_mask(F)
48        X, F, fs = args[0][pfm], F[pfm], []
49        for _ in range(self._n_evals):
50            out: Dict[str, Any] = {}
51            self._ground_problem._evaluate(X, out, *args, **kwargs)
52            fs.append(out["F"])
53        self._history = {"X": X, "F": np.mean(np.array(fs), axis=0)}
54        self.dump_history()
55        return np.mean(np.linalg.norm(F - self._history["F"], axis=-1))

The ΔF-Pareto performance indicator. Given

calculates the vectorized average Euclidean distance between F' and Y, where F' is the subarray corresponding to Pareto individuals in X, and where Y is obtained by averaging g(X) a given number of times.

You can use this PI in a benchmark as

Benchmark(
    ...
    performance_indicators=[..., "dfp", ...]
)
Inherited Members
nmoo.indicators.delta_f.DeltaF
DeltaF
dump_history
pymoo.core.indicator.Indicator
do