Skip to content

Benchmarks

deap_er.benchmarks

MovingPeaks(dimensions, **kwargs)

A fitness landscape whose peaks change over time.

Peaks move in height, width, and location. If npeaks is a list of three integers, the peak count fluctuates between the first and third values, starting at the second. Fluctuating the count requires change_severity in kwargs. The default preset is MPConfigs.DEFAULT.

.. dropdown:: Table of Kwargs :margin: 0 5 0 0

pfunc (Callable) The peak function or a list of peak functions. bfunc (Callable) Basis function for static landscape. npeaks (NumOrSeq) Number of peaks. An integer or a list of three integers [min, initial, max]. change_severity (float) The fraction of the number of peaks that is allowed to change. min_coord (float) Minimum coordinate for the centre of the peaks. max_coord (float) Maximum coordinate for the centre of the peaks. min_height (float) Minimum height of the peaks. max_height (float) Maximum height of the peaks. uniform_height (float) Starting height of all peaks. Random, if uniform_height <= 0. min_width (float) Minimum width of the peaks. max_width (float) Maximum width of the peaks uniform_width (float) Starting width of all peaks. Random, if uniform_width <= 0. lambda_ (float) Correlation between changes. move_severity (float) The distance a single peak moves when peaks change. height_severity (float) The standard deviation of the change to the height of a peak when peaks change. width_severity (float) The standard deviation of the change to the width of a peak when peaks change. period (int) Period between two changes.

Build a moving-peaks landscape.

Parameters:

Name Type Description Default
dimensions int

Dimensionality of the search domain.

required
**kwargs Any

Optional landscape settings. See the class docstring table of kwargs.

{}
Source code in deap_er/private/benchmarks/moving_peaks.py
def __init__(self, dimensions: int, **kwargs: Any) -> None:
    """Build a moving-peaks landscape.

    Args:
        dimensions: Dimensionality of the search domain.
        **kwargs: Optional landscape settings. See the class
            docstring table of kwargs.
    """
    self.dim = dimensions
    sc: dict[str, Any] = dict(MPConfigs.DEFAULT)
    sc.update(kwargs)

    n_peaks_val = cast(int | Sequence[int], sc["npeaks"])
    pfunc = cast(PeakFunc | Sequence[PeakFunc], sc["pfunc"])

    self.min_peaks: int | None = None
    self.max_peaks: int | None = None
    self.number_severity: float = 0.0
    if isinstance(n_peaks_val, Sequence) and not isinstance(n_peaks_val, (str, bytes)):
        self.min_peaks, n_peaks, self.max_peaks = n_peaks_val
        severity = sc["change_severity"]
        self.number_severity = 0.0 if severity is None else float(severity)
    else:
        n_peaks = int(n_peaks_val)

    if isinstance(pfunc, Sequence):
        funcs = list(pfunc)
        if len(funcs) == n_peaks:
            self.peaks_function = funcs
        else:
            self.peaks_function = rng.sample(funcs, n_peaks)
        self.pfunc_pool: tuple[PeakFunc, ...] = tuple(funcs)
    else:
        self.peaks_function = list(itertools.repeat(pfunc, n_peaks))
        self.pfunc_pool = (pfunc,)

    self.last_change_vector = [
        [rng.random() - 0.5 for _ in range(dimensions)] for _ in range(n_peaks)
    ]
    self.min_coord = float(sc["min_coord"])
    self.max_coord = float(sc["max_coord"])
    self.peaks_position = [
        [rng.uniform(self.min_coord, self.max_coord) for _ in range(dimensions)]
        for _ in range(n_peaks)
    ]
    uniform_height = float(sc["uniform_height"])
    self.min_height = float(sc["min_height"])
    self.max_height = float(sc["max_height"])
    if uniform_height != 0:
        self.peaks_height = [uniform_height for _ in range(n_peaks)]
    else:
        self.peaks_height = [
            rng.uniform(self.min_height, self.max_height) for _ in range(n_peaks)
        ]

    uniform_width = float(sc["uniform_width"])
    self.min_width = float(sc["min_width"])
    self.max_width = float(sc["max_width"])
    if uniform_width != 0:
        self.peaks_width = [uniform_width for _ in range(n_peaks)]
    else:
        self.peaks_width = [rng.uniform(self.min_width, self.max_width) for _ in range(n_peaks)]

    self.basis_function: Callable[[Sequence[float]], float] | None = sc.get("bfunc")
    self.move_severity = float(sc["move_severity"])
    self.height_severity = float(sc["height_severity"])
    self.width_severity = float(sc["width_severity"])
    self.period = int(sc["period"])
    self.lamb = float(sc["lambda_"])
    self._optimum: float | None = None
    self._error: float | None = None
    self._offline_error = 0.0
    self.nevals = 0

global_maximum property

Returns the value and position of the largest peak.

sorted_maxima property

Return visible peak values and positions, largest first.

offline_error property

Returns the offline error of the landscape, or 0.0 before the first evaluation.

current_error property

Returns the current error of the landscape.

__call__(individual, count=True)

Evaluate the given individual in the context of the current configuration.

Parameters:

Name Type Description Default
individual Sequence[float]

Individual to evaluate.

required
count bool

Whether to include this evaluation in the evaluation count and error statistics.

True

Returns:

Type Description
tuple[float]

The fitness of the individual.

Source code in deap_er/private/benchmarks/moving_peaks.py
def __call__(self, individual: Sequence[float], count: bool = True) -> tuple[float]:
    """Evaluate the given **individual** in the context of the current configuration.

    Args:
        individual: Individual to evaluate.
        count: Whether to include this evaluation in the
            evaluation count and error statistics.

    Returns:
        The fitness of the individual.
    """
    possible_values = []
    zipper = zip(
        self.peaks_function,
        self.peaks_position,
        self.peaks_height,
        self.peaks_width,
        strict=False,
    )
    for func, pos, height, width in zipper:
        result = func(individual, pos, height, width)
        possible_values.append(result)

    if self.basis_function:
        result = self.basis_function(individual)
        possible_values.append(result)

    fitness = max(possible_values)

    if count:
        self.nevals += 1
        if self._optimum is None or self._error is None:
            self._optimum = self.global_maximum[0]
            self._error = abs(fitness - self._optimum)
        else:
            self._error = min(self._error, abs(fitness - self._optimum))
        self._offline_error += self._error

        if self.period > 0 and self.nevals % self.period == 0:
            self.change_peaks()

    return (float(fitness),)

change_peaks()

Changes the position, the height, the width and the number of peaks.

Source code in deap_er/private/benchmarks/moving_peaks.py
def change_peaks(self) -> None:
    """Changes the position, the height, the width and the number of peaks."""
    _change_peaks(self)

MPConfigs

Configuration presets for the Moving Peaks problem.

Each preset is a dict class attribute.

.. dropdown:: Table of Presets :margin: 0 5 0 0

=================== ===================== ===================== =====================
Keys / Presets      **DEFAULT**           **ALT1**              **ALT2**
=================== ===================== ===================== =====================
``pfunc``           ``MPFuncs.pf1``       ``MPFuncs.pf2``       ``MPFuncs.pf2``
``bfunc``           :obj:`None`           :obj:`None`           :obj:`lambda x: 10`
``npeaks``          5                     10                    50
``change_severity`` :obj:`None`           :obj:`None`           :obj:`None`
``min_coord``       0.0                   0.0                   0.0
``max_coord``       100.0                 100.0                 100.0
``min_height``      30.0                  30.0                  30.0
``max_height``      70.0                  70.0                  70.0
``uniform_height``  50.0                  50.0                  0.0
``min_width``       0.0001                1.0                   1.0
``max_width``       0.2                   12.0                  12.0
``uniform_width``   0.1                   0.0                   0.0
``lambda_``         0.0                   0.5                   0.5
``move_severity``   1.0                   1.5                   1.0
``height_severity`` 7.0                   7.0                   1.0
``width_severity``  0.01                  1.0                   0.5
``period``          5000                  5000                  1000
=================== ===================== ===================== =====================

MPFuncs

Peak functions for Moving Peaks custom presets.

pf1(individual, positions, height, width) staticmethod

The peak function of the :data:DEFAULT preset.

Official Moving Peaks scenario 1 is the squared form height / (1 + width * sum((x_i - p_i)^2)).

Parameters:

Name Type Description Default
individual Sequence[float]

Individual to evaluate.

required
positions Iterable[float]

Peak centre coordinates.

required
height float

Peak height.

required
width float

Peak width.

required

Returns:

Type Description
float

The fitness of the individual.

Source code in deap_er/private/benchmarks/moving_peaks_catalog.py
@staticmethod
def pf1(
    individual: Sequence[float], positions: Iterable[float], height: float, width: float
) -> float:
    """The peak function of the :data:`DEFAULT` preset.

    Official Moving Peaks scenario 1 is the squared form
    ``height / (1 + width * sum((x_i - p_i)^2))``.

    Args:
        individual: Individual to evaluate.
        positions: Peak centre coordinates.
        height: Peak height.
        width: Peak width.

    Returns:
        The fitness of the individual.
    """
    value = 0.0
    for x, p in zip(individual, positions, strict=False):
        value += (x - p) ** 2
    return float(height / (1 + width * value))

pf2(individual, positions, height, width) staticmethod

The peak function of the :data:ALT1 and :data:ALT2 presets.

Parameters:

Name Type Description Default
individual Sequence[float]

Individual to evaluate.

required
positions Iterable[float]

Peak centre coordinates.

required
height float

Peak height.

required
width float

Peak width.

required

Returns:

Type Description
float

The fitness of the individual.

Source code in deap_er/private/benchmarks/moving_peaks_catalog.py
@staticmethod
def pf2(
    individual: Sequence[float], positions: Iterable[float], height: float, width: float
) -> float:
    """The peak function of the :data:`ALT1` and :data:`ALT2` presets.

    Args:
        individual: Individual to evaluate.
        positions: Peak centre coordinates.
        height: Peak height.
        width: Peak width.

    Returns:
        The fitness of the individual.
    """
    value = 0.0
    for x, p in zip(individual, positions, strict=False):
        value += (x - p) ** 2
    return float(height - width * math.sqrt(value))

pf3(individual, positions, height, *_) staticmethod

An optional peak function.

Parameters:

Name Type Description Default
individual Sequence[float]

Individual to evaluate.

required
positions Iterable[float]

Peak centre coordinates.

required
height float

Peak height.

required

Returns:

Type Description
float

The fitness of the individual.

Source code in deap_er/private/benchmarks/moving_peaks_catalog.py
@staticmethod
def pf3(
    individual: Sequence[float], positions: Iterable[float], height: float, *_: Any
) -> float:
    """An optional peak function.

    Args:
        individual: Individual to evaluate.
        positions: Peak centre coordinates.
        height: Peak height.

    Returns:
        The fitness of the individual.
    """
    value = 0.0
    for x, p in zip(individual, positions, strict=False):
        value += (x - p) ** 2
    return float(height * value)

bm_chuang_f1(individual)

Evaluate Chuang and Hsu's first binary deceptive function.

From "Multivariate Multi-Model Approach for Globally Multimodal Problems". Two global optima at all-ones and all-zeros. The individual must have 41 dimensions.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[int]

The deceptive function value.

Source code in deap_er/private/benchmarks/binary.py
def bm_chuang_f1(individual: Individual) -> tuple[int]:
    """Evaluate Chuang and Hsu's first binary deceptive function.

    From "Multivariate Multi-Model Approach for Globally Multimodal
    Problems". Two global optima at all-ones and all-zeros. The
    individual must have 41 dimensions.

    Args:
        individual: Individual to evaluate.

    Returns:
        The deceptive function value.
    """
    total = 0
    if individual[-1] == 0:
        for i in range(0, len(individual) - 1, 4):
            total += _inv_trap(individual[i : i + 4])
    else:
        for i in range(0, len(individual) - 1, 4):
            total += _trap(individual[i : i + 4])
    return (total,)

bm_chuang_f2(individual)

Evaluate Chuang and Hsu's second binary deceptive function.

From "Multivariate Multi-Model Approach for Globally Multimodal Problems". Four global optima: half-and-half, reverse half-and-half, all-ones, and all-zeros. The individual must have 41 dimensions.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[int]

The deceptive function value.

Source code in deap_er/private/benchmarks/binary.py
def bm_chuang_f2(individual: Individual) -> tuple[int]:
    """Evaluate Chuang and Hsu's second binary deceptive function.

    From "Multivariate Multi-Model Approach for Globally Multimodal
    Problems". Four global optima: half-and-half, reverse half-and-half,
    all-ones, and all-zeros. The individual must have 41 dimensions.

    Args:
        individual: Individual to evaluate.

    Returns:
        The deceptive function value.
    """
    total = 0
    if individual[-2] == 0 and individual[-1] == 0:
        for i in range(0, len(individual) - 2, 8):
            total += _inv_trap(individual[i : i + 4]) + _inv_trap(individual[i + 4 : i + 8])
    elif individual[-2] == 0 and individual[-1] == 1:
        for i in range(0, len(individual) - 2, 8):
            total += _inv_trap(individual[i : i + 4]) + _trap(individual[i + 4 : i + 8])
    elif individual[-2] == 1 and individual[-1] == 0:
        for i in range(0, len(individual) - 2, 8):
            total += _trap(individual[i : i + 4]) + _inv_trap(individual[i + 4 : i + 8])
    else:
        for i in range(0, len(individual) - 2, 8):
            total += _trap(individual[i : i + 4]) + _trap(individual[i + 4 : i + 8])
    return (total,)

bm_chuang_f3(individual)

Evaluate Chuang and Hsu's third binary deceptive function.

From "Multivariate Multi-Model Approach for Globally Multimodal Problems". Two global optima at all-ones and all-zeros. The individual must have 41 dimensions.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[int]

The deceptive function value.

Source code in deap_er/private/benchmarks/binary.py
def bm_chuang_f3(individual: Individual) -> tuple[int]:
    """Evaluate Chuang and Hsu's third binary deceptive function.

    From "Multivariate Multi-Model Approach for Globally Multimodal
    Problems". Two global optima at all-ones and all-zeros. The
    individual must have 41 dimensions.

    Args:
        individual: Individual to evaluate.

    Returns:
        The deceptive function value.
    """
    total = 0
    if individual[-1] == 0:
        for i in range(0, len(individual) - 1, 4):
            total += _inv_trap(individual[i : i + 4])
    else:
        for i in range(2, 38, 4):
            total += _trap(individual[i : i + 4])
        total += _trap(individual[38:40] + individual[:2])
    return (total,)

bm_royal_road_1(individual, order)

Evaluate Royal Road function R1.

As presented by Melanie Mitchell in "An introduction to Genetic Algorithms".

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
order int

Order of the royal road function.

required

Returns:

Type Description
tuple[int]

The royal road function value.

Source code in deap_er/private/benchmarks/binary.py
def bm_royal_road_1(individual: Individual, order: int) -> tuple[int]:
    """Evaluate Royal Road function R1.

    As presented by Melanie Mitchell in "An introduction to Genetic
    Algorithms".

    Args:
        individual: Individual to evaluate.
        order: Order of the royal road function.

    Returns:
        The royal road function value.
    """
    nelem = len(individual) // order
    total = 0
    for i in range(nelem):
        start = i * order
        stop = i * order + order
        values = individual[start:stop]
        if all(values):
            total += order
    return (total,)

bm_royal_road_2(individual, order)

Evaluate Royal Road function R2.

As presented by Melanie Mitchell in "An introduction to Genetic Algorithms".

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
order int

Order of the royal road function.

required

Returns:

Type Description
tuple[int]

The royal road function value.

Source code in deap_er/private/benchmarks/binary.py
def bm_royal_road_2(individual: Individual, order: int) -> tuple[int]:
    """Evaluate Royal Road function R2.

    As presented by Melanie Mitchell in "An introduction to Genetic
    Algorithms".

    Args:
        individual: Individual to evaluate.
        order: Order of the royal road function.

    Returns:
        The royal road function value.
    """
    total = 0
    n_order = order
    while n_order <= len(individual):
        total += bm_royal_road_1(individual, n_order)[0]
        n_order *= 2
    return (total,)

bm_dtlz_1(individual, count)

Evaluate the DTLZ1 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations
\[ g(\mathbf{x}_m) = 100\left(|\mathbf{x}_m| + \sum_{x_i \in \mathbf{x}_m}\left((x_i - 0.5)^2 - \cos(20\pi(x_i - 0.5))\right)\right) \]

\(f_{1}(\mathbf{x}) = \frac{1}{2} (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1}x_i\)

\[ f_{2}(\mathbf{x}) = \frac{1}{2} (1 + g(\mathbf{x}_m)) (1-x_{m-1}) \prod_{i=1}^{m-2}x_i \]

\(f_{m-1}(\mathbf{x}) = \frac{1}{2} (1 + g(\mathbf{x}_m)) (1 - x_2) x_1\)

\(\ldots\)

\(f_{m}(\mathbf{x}) = \frac{1}{2} (1 - x_1)(1 + g(\mathbf{x}_m))\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_1_4.py
def bm_dtlz_1(individual: Individual, count: int) -> list[float]:
    r"""Evaluate the DTLZ1 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $$
        g(\mathbf{x}_m) = 100\left(|\mathbf{x}_m| +
        \sum_{x_i \in \mathbf{x}_m}\left((x_i - 0.5)^2 -
        \cos(20\pi(x_i - 0.5))\right)\right)
        $$

        $f_{1}(\mathbf{x}) = \frac{1}{2} (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1}x_i$

        $$
        f_{2}(\mathbf{x}) = \frac{1}{2} (1 + g(\mathbf{x}_m))
        (1-x_{m-1}) \prod_{i=1}^{m-2}x_i
        $$

        $f_{m-1}(\mathbf{x}) = \frac{1}{2} (1 + g(\mathbf{x}_m)) (1 - x_2) x_1$

        $\ldots$

        $f_{m}(\mathbf{x}) = \frac{1}{2} (1 - x_1)(1 + g(\mathbf{x}_m))$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """

    def fn_xi(xi: float) -> float:
        _cos = cos(20 * pi * (xi - 0.5))
        return float((xi - 0.5) ** 2 - _cos)

    def fn_m(m: int) -> float:
        rdc = reduce(mul, individual[:m], 1)
        return float(0.5 * rdc * (1 - individual[m]) * (1 + gval))

    _sum = sum(fn_xi(xi) for xi in individual[count - 1 :])
    gval = 100 * (len(individual[count - 1 :]) + _sum)
    fit = [0.5 * reduce(mul, individual[: count - 1], 1) * (1 + gval)]
    fit.extend(fn_m(m) for m in reversed(range(count - 1)))
    return [float(value) for value in fit]

bm_dtlz_2(individual, count)

Evaluate the DTLZ2 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}_m) = \sum_{x_i \in \mathbf{x}_m} (x_i - 0.5)^2\)

\(f_{1}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1} \cos(0.5x_i\pi)\)

\[ f_{2}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{m-1}\pi) \prod_{i=1}^{m-2} \cos(0.5x_i\pi) \]

\(\ldots\)

\(f_{m}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{1}\pi )\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_1_4.py
def bm_dtlz_2(individual: Individual, count: int) -> list[float]:
    r"""Evaluate the DTLZ2 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}_m) = \sum_{x_i \in \mathbf{x}_m} (x_i - 0.5)^2$

        $f_{1}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1} \cos(0.5x_i\pi)$

        $$
        f_{2}(\mathbf{x}) = (1 + g(\mathbf{x}_m))
        \sin(0.5x_{m-1}\pi) \prod_{i=1}^{m-2}
        \cos(0.5x_i\pi)
        $$

        $\ldots$

        $f_{m}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{1}\pi )$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """
    xm = individual[count - 1 :]
    gval = sum((xi - 0.5) ** 2 for xi in xm)
    return _dtlz_helper_1(individual, count, gval)

bm_dtlz_3(individual, count)

Evaluate the DTLZ3 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations
\[ g(\mathbf{x}_m) = 100\left(|\mathbf{x}_m| + \sum_{x_i \in \mathbf{x}_m}\left((x_i - 0.5)^2 - \cos(20\pi(x_i - 0.5))\right)\right) \]

\(f_{1}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1} \cos(0.5x_i\pi)\)

\[ f_{2}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{m-1}\pi) \prod_{i=1}^{m-2} \cos(0.5x_i\pi) \]

\(\ldots\)

\(f_{m}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{1}\pi )\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_1_4.py
def bm_dtlz_3(individual: Individual, count: int) -> list[float]:
    r"""Evaluate the DTLZ3 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $$
        g(\mathbf{x}_m) = 100\left(|\mathbf{x}_m| +
        \sum_{x_i \in \mathbf{x}_m}\left((x_i - 0.5)^2 -
        \cos(20\pi(x_i - 0.5))\right)\right)
        $$

        $f_{1}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1} \cos(0.5x_i\pi)$

        $$
        f_{2}(\mathbf{x}) = (1 + g(\mathbf{x}_m))
        \sin(0.5x_{m-1}\pi) \prod_{i=1}^{m-2}
        \cos(0.5x_i\pi)
        $$

        $\ldots$

        $f_{m}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{1}\pi )$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """

    def fn(xi: float) -> float:
        _cos = cos(20 * pi * (xi - 0.5))
        return float((xi - 0.5) ** 2 - _cos)

    xm = individual[count - 1 :]
    gval = 100 * (len(xm) + sum(fn(xi) for xi in xm))
    return _dtlz_helper_1(individual, count, gval)

bm_dtlz_4(individual, count, alpha)

Evaluate the DTLZ4 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required
alpha float

Fitness values exponentiation factor.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}_m) = \sum_{x_i \in \mathbf{x}_m} (x_i - 0.5)^2\)

\(f_{1}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1} \cos(0.5x_i^\alpha\pi)\)

\[ f_{2}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{m-1}^\alpha\pi) \prod_{i=1}^{m-2} \cos(0.5x_i^\alpha\pi) \]

\(\ldots\)

\(f_{m}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{1}^\alpha\pi )\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_1_4.py
def bm_dtlz_4(individual: Individual, count: int, alpha: float) -> list[float]:
    r"""Evaluate the DTLZ4 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.
        alpha: Fitness values exponentiation factor.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}_m) = \sum_{x_i \in \mathbf{x}_m} (x_i - 0.5)^2$

        $f_{1}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \prod_{i=1}^{m-1} \cos(0.5x_i^\alpha\pi)$

        $$
        f_{2}(\mathbf{x}) = (1 + g(\mathbf{x}_m))
        \sin(0.5x_{m-1}^\alpha\pi)
        \prod_{i=1}^{m-2} \cos(0.5x_i^\alpha\pi)
        $$

        $\ldots$

        $f_{m}(\mathbf{x}) = (1 + g(\mathbf{x}_m)) \sin(0.5x_{1}^\alpha\pi )$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """
    xm = individual[count - 1 :]
    gval = sum((xi - 0.5) ** 2 for xi in xm)
    return _dtlz_helper_1(individual, count, gval, alpha)

bm_dtlz_5(individual, count)

Evaluate the DTLZ5 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}_m) = \text{ ?}\)

\(f_{1}(\mathbf{x}) = \text{ ?}\)

\(f_{2}(\mathbf{x}) = \text{ ?}\)

\(\ldots\)

\(f_{m}(\mathbf{x}) = \text{ ?}\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_5_7.py
def bm_dtlz_5(individual: Individual, count: int) -> list[float]:
    r"""Evaluate the DTLZ5 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}_m) = \text{ ?}$

        $f_{1}(\mathbf{x}) = \text{ ?}$

        $f_{2}(\mathbf{x}) = \text{ ?}$

        $\ldots$

        $f_{m}(\mathbf{x}) = \text{ ?}$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """
    gval = sum([(a - 0.5) ** 2 for a in individual[count - 1 :]])
    return _dtlz_helper_2(individual, count, gval)

bm_dtlz_6(individual, count)

Evaluate the DTLZ6 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}_m) = \text{ ?}\)

\(f_{1}(\mathbf{x}) = \text{ ?}\)

\(f_{2}(\mathbf{x}) = \text{ ?}\)

\(\ldots\)

\(f_{m}(\mathbf{x}) = \text{ ?}\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_5_7.py
def bm_dtlz_6(individual: Individual, count: int) -> list[float]:
    r"""Evaluate the DTLZ6 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}_m) = \text{ ?}$

        $f_{1}(\mathbf{x}) = \text{ ?}$

        $f_{2}(\mathbf{x}) = \text{ ?}$

        $\ldots$

        $f_{m}(\mathbf{x}) = \text{ ?}$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """
    gval = sum([a**0.1 for a in individual[count - 1 :]])
    return _dtlz_helper_2(individual, count, gval)

bm_dtlz_7(individual, count)

Evaluate the DTLZ7 multi-objective function.

Returns a list of size count. The individual must have at least count elements.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
count int

Number of objectives.

required

Returns:

Type Description
list[float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}_m) = \text{ ?}\)

\(f_{1}(\mathbf{x}) = \text{ ?}\)

\(f_{2}(\mathbf{x}) = \text{ ?}\)

\(\ldots\)

\(f_{m}(\mathbf{x}) = \text{ ?}\)

Where \(m\) is the number of objectives and \(\mathbf{x}_m\) is a vector of the remaining attributes \([x_m~\ldots~x_n]\) of the individual in \(n > m\) dimensions.

Source code in deap_er/private/benchmarks/bm_dtlz_5_7.py
def bm_dtlz_7(individual: Individual, count: int) -> list[float]:
    r"""Evaluate the DTLZ7 multi-objective function.

    Returns a list of size ``count``. The individual must have at
    least ``count`` elements.

    Args:
        individual: Individual to evaluate.
        count: Number of objectives.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}_m) = \text{ ?}$

        $f_{1}(\mathbf{x}) = \text{ ?}$

        $f_{2}(\mathbf{x}) = \text{ ?}$

        $\ldots$

        $f_{m}(\mathbf{x}) = \text{ ?}$

        Where $m$ is the number of objectives and $\mathbf{x}_m$
        is a vector of the remaining attributes $[x_m~\ldots~x_n]$
        of the individual in $n > m$ dimensions.
    """

    def fn(a: float) -> float:
        return float(a / (1 + gval) * (1 + sin(3 * pi * a)))

    gval = sum(individual[count - 1 :])
    gval = 1 + 9 / len(individual[count - 1 :]) * gval

    fit = list(individual[: count - 1])
    vals = [fn(a) for a in individual[: count - 1]]
    res = (1 + gval) * (count - sum(vals))
    fit.append(res)
    return [float(value) for value in fit]

bm_himmelblau(individual)

The Himmelblau function has four minima in \([-6, 6]^2\).

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-6, 6]\)
Global optima see below
Function see below

\(\mathbf{x}_1 = (3.0, 2.0)\), \(f(\mathbf{x}_1) = 0\)

\(\mathbf{x}_2 = (-2.805118, 3.131312)\), \(f(\mathbf{x}_2) = 0\)

\(\mathbf{x}_3 = (-3.779310, -3.283186)\), \(f(\mathbf{x}_3) = 0\)

\(\mathbf{x}_4 = (3.584428, -1.848126)\), \(f(\mathbf{x}_4) = 0\)

\[ f(x_1, x_2) = (x_1^2 + x_2 - 11)^2 + (x_1 + x_2^2 -7)^2 \]
Source code in deap_er/private/benchmarks/bm_landscape.py
def bm_himmelblau(individual: Individual) -> tuple[float]:
    r"""The Himmelblau function has four minima in $[-6, 6]^2$.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-6, 6]$ |
        | Global optima | see below |
        | Function | see below |

        $\mathbf{x}_1 = (3.0, 2.0)$, $f(\mathbf{x}_1) = 0$

        $\mathbf{x}_2 = (-2.805118, 3.131312)$, $f(\mathbf{x}_2) = 0$

        $\mathbf{x}_3 = (-3.779310, -3.283186)$, $f(\mathbf{x}_3) = 0$

        $\mathbf{x}_4 = (3.584428, -1.848126)$, $f(\mathbf{x}_4) = 0$

        $$
        f(x_1, x_2) = (x_1^2 + x_2 - 11)^2 + (x_1 + x_2^2 -7)^2
        $$
    """
    var_1 = (individual[0] * individual[0] + individual[1] - 11) ** 2
    var_2 = (individual[0] + individual[1] * individual[1] - 7) ** 2
    result = var_1 + var_2
    return (float(result),)

bm_schaffer(individual)

Schaffer test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-100, 100]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function see below
\[ f(\mathbf{x}) = \sum_{i=1}^{N-1} (x_i^2+x_{i+1}^2)^{0.25} \cdot \left[ \sin^2(50\cdot(x_i^2+x_{i+1}^2)^{0.10}) + 1.0 \right] \]
Source code in deap_er/private/benchmarks/bm_landscape.py
def bm_schaffer(individual: Individual) -> tuple[float]:
    r"""Schaffer test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-100, 100]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = \sum_{i=1}^{N-1}
        (x_i^2+x_{i+1}^2)^{0.25} \cdot \left[
        \sin^2(50\cdot(x_i^2+x_{i+1}^2)^{0.10})
        + 1.0 \right]
        $$
    """
    results = []
    for x, x1 in zip(individual[:-1], individual[1:], strict=False):
        var_1 = (x**2 + x1**2) ** 0.25
        var_2 = sin(50 * (x**2 + x1**2) ** 0.1) ** 2 + 1.0
        results.append(var_1 * var_2)
    result = sum(results)
    return (float(result),)

bm_schwefel(individual)

Schwefel test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-500, 500]\)
Global optima see below
Function see below

\(x_i = 420.96874636\), \(\forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)

\[ f(\mathbf{x}) = 418.9828872724339\cdot N - \sum_{i=1}^N\,x_i\sin\left(\sqrt{|x_i|}\right) \]
Source code in deap_er/private/benchmarks/bm_landscape.py
def bm_schwefel(individual: Individual) -> tuple[float]:
    r"""Schwefel test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-500, 500]$ |
        | Global optima | see below |
        | Function | see below |

        $x_i = 420.96874636$, $\forall i \in \lbrace 1 \ldots N\rbrace$,
        $f(\mathbf{x}) = 0$

        $$
        f(\mathbf{x}) = 418.9828872724339\cdot N -
        \sum_{i=1}^N\,x_i\sin\left(\sqrt{|x_i|}\right)
        $$
    """
    len_ind = len(individual)
    values = sum(x * sin(sqrt(abs(x))) for x in individual)
    result = 418.9828872724339 * len_ind - values
    return (float(result),)

bm_dent(individual, dent_size=0.85)

Evaluate a two-objective problem with a dent.

The individual must have two attributes in [-1.5, 1.5].

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
dent_size float

Size of the dent.

0.85

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(f_{1}(\mathbf{x}) = \text{ ?}\)

\(f_{2}(\mathbf{x}) = \text{ ?}\)

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_mo_classic.py
def bm_dent(individual: Individual, dent_size: float = 0.85) -> tuple[float, float]:
    r"""Evaluate a two-objective problem with a dent.

    The individual must have two attributes in ``[-1.5, 1.5]``.

    Args:
        individual: Individual to evaluate.
        dent_size: Size of the dent.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $f_{1}(\mathbf{x}) = \text{ ?}$

        $f_{2}(\mathbf{x}) = \text{ ?}$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    d = dent_size * exp(-((individual[0] - individual[1]) ** 2))
    f1 = (
        0.5
        * (
            sqrt(1 + (individual[0] + individual[1]) ** 2)
            + sqrt(1 + (individual[0] - individual[1]) ** 2)
            + individual[0]
            - individual[1]
        )
        + d
    )
    f2 = (
        0.5
        * (
            sqrt(1 + (individual[0] + individual[1]) ** 2)
            + sqrt(1 + (individual[0] - individual[1]) ** 2)
            - individual[0]
            + individual[1]
        )
        + d
    )
    return float(f1), float(f2)

bm_fonseca(individual)

Fonseca and Fleming's multiobjective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(f_{1}(\mathbf{x}) = 1 - e^{-\sum_{i=1}^{3}(x_i - \frac{1}{\sqrt{3}})^2}\)

\(f_{2}(\mathbf{x}) = 1 - e^{-\sum_{i=1}^{3}(x_i + \frac{1}{\sqrt{3}})^2}\)

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_mo_classic.py
def bm_fonseca(individual: Individual) -> tuple[float, float]:
    r"""Fonseca and Fleming's multiobjective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $f_{1}(\mathbf{x}) = 1 - e^{-\sum_{i=1}^{3}(x_i - \frac{1}{\sqrt{3}})^2}$

        $f_{2}(\mathbf{x}) = 1 - e^{-\sum_{i=1}^{3}(x_i + \frac{1}{\sqrt{3}})^2}$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    f1 = 1 - exp(-sum((xi - 1 / sqrt(3)) ** 2 for xi in individual[:3]))
    f2 = 1 - exp(-sum((xi + 1 / sqrt(3)) ** 2 for xi in individual[:3]))
    return float(f1), float(f2)

bm_kursawe(individual)

Kursawe multi-objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(f_{1}(\mathbf{x}) = \sum_{i=1}^{N-1} -10 e^{-0.2 \sqrt{x_i^2 + x_{i+1}^2} }\)

\(f_{2}(\mathbf{x}) = \sum_{i=1}^{N} |x_i|^{0.8} + 5 \sin(x_i^3)\)

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_mo_classic.py
def bm_kursawe(individual: Individual) -> tuple[float, float]:
    r"""Kursawe multi-objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $f_{1}(\mathbf{x}) = \sum_{i=1}^{N-1} -10 e^{-0.2 \sqrt{x_i^2 + x_{i+1}^2} }$

        $f_{2}(\mathbf{x}) = \sum_{i=1}^{N} |x_i|^{0.8} + 5 \sin(x_i^3)$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """

    def fn(x: float, y: float) -> float:
        return -10 * exp(-0.2 * sqrt(x * x + y * y))

    f1 = sum(fn(x, y) for x, y in zip(individual[:-1], individual[1:], strict=False))
    f2 = sum(abs(x) ** 0.8 + 5 * sin(x * x * x) for x in individual)
    return float(f1), float(f2)

bm_poloni(individual)

Poloni's multiobjective function on a two-attribute individual.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(A_1 = 0.5 \sin (1) - 2 \cos (1) + \sin (2) - 1.5 \cos (2)\)

\(A_2 = 1.5 \sin (1) - \cos (1) + 2 \sin (2) - 0.5 \cos (2)\)

\(B_1 = 0.5 \sin (x_1) - 2 \cos (x_1) + \sin (x_2) - 1.5 \cos (x_2)\)

\(B_2 = 1.5 \sin (x_1) - cos(x_1) + 2 \sin (x_2) - 0.5 \cos (x_2)\)

\(f_{1}(\mathbf{x}) = 1 + (A_1 - B_1)^2 + (A_2 - B_2)^2\)

\(f_{2}(\mathbf{x}) = (x_1 + 3)^2 + (x_2 + 1)^2\)

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_mo_classic.py
def bm_poloni(individual: Individual) -> tuple[float, float]:
    r"""Poloni's multiobjective function on a two-attribute **individual**.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $A_1 = 0.5 \sin (1) - 2 \cos (1) + \sin (2) - 1.5 \cos (2)$

        $A_2 = 1.5 \sin (1) - \cos (1) + 2 \sin (2) - 0.5 \cos (2)$

        $B_1 = 0.5 \sin (x_1) - 2 \cos (x_1) + \sin (x_2) - 1.5 \cos (x_2)$

        $B_2 = 1.5 \sin (x_1) - cos(x_1) + 2 \sin (x_2) - 0.5 \cos (x_2)$

        $f_{1}(\mathbf{x}) = 1 + (A_1 - B_1)^2 + (A_2 - B_2)^2$

        $f_{2}(\mathbf{x}) = (x_1 + 3)^2 + (x_2 + 1)^2$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    x_1 = individual[0]
    x_2 = individual[1]
    a_1 = 0.5 * sin(1) - 2 * cos(1) + sin(2) - 1.5 * cos(2)
    a_2 = 1.5 * sin(1) - cos(1) + 2 * sin(2) - 0.5 * cos(2)
    b_1 = 0.5 * sin(x_1) - 2 * cos(x_1) + sin(x_2) - 1.5 * cos(x_2)
    b_2 = 1.5 * sin(x_1) - cos(x_1) + 2 * sin(x_2) - 0.5 * cos(x_2)
    f1 = 1 + (a_1 - b_1) ** 2 + (a_2 - b_2) ** 2
    f2 = (x_1 + 3) ** 2 + (x_2 + 1) ** 2
    return float(f1), float(f2)

bm_schaffer_mo(individual)

Schaffer's multi-objective function on a one-attribute individual.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(f_{1}(\mathbf{x}) = x_1^2\)

\(f_{2}(\mathbf{x}) = (x_1-2)^2\)

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_mo_classic.py
def bm_schaffer_mo(individual: Individual) -> tuple[float, float]:
    r"""Schaffer's multi-objective function on a one-attribute **individual**.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $f_{1}(\mathbf{x}) = x_1^2$

        $f_{2}(\mathbf{x}) = (x_1-2)^2$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    f1 = individual[0] ** 2
    f2 = (individual[0] - 2) ** 2
    return float(f1), float(f2)

bm_ackley(individual)

Ackley test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-15, 30]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function see below
\[ f(\mathbf{x}) = 20 - 20\exp\left(-0.2 \sqrt{\frac{1}{N} \sum_{i=1}^N x_i^2} \right) + e - \exp\left(\frac{1}{N} \sum_{i=1}^N \cos(2\pi x_i) \right) \]
Source code in deap_er/private/benchmarks/bm_multimodal.py
def bm_ackley(individual: Individual) -> tuple[float]:
    r"""Ackley test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-15, 30]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = 20 - 20\exp\left(-0.2
        \sqrt{\frac{1}{N} \sum_{i=1}^N x_i^2}
        \right) + e - \exp\left(\frac{1}{N}
        \sum_{i=1}^N \cos(2\pi x_i) \right)
        $$
    """
    len_ind = len(individual)
    exp_1 = exp(-0.2 * sqrt(1 / len_ind * sum(x**2 for x in individual)))
    exp_2 = exp(1 / len_ind * sum(cos(2 * pi * x) for x in individual))
    result = 20 - 20 * exp_1 + e - exp_2
    return (float(result),)

bm_bohachevsky(individual)

Bohachevsky test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-100, 100]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function see below
\[ f(\mathbf{x}) = \sum_{i=1}^{N-1}(x_i^2 + 2x_{i+1}^2 - 0.3\cos(3\pi x_i) - 0.4\cos(4\pi x_{i+1}) + 0.7) \]
Source code in deap_er/private/benchmarks/bm_multimodal.py
def bm_bohachevsky(individual: Individual) -> tuple[float]:
    r"""Bohachevsky test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-100, 100]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = \sum_{i=1}^{N-1}(x_i^2 +
        2x_{i+1}^2 - 0.3\cos(3\pi x_i) -
        0.4\cos(4\pi x_{i+1}) + 0.7)
        $$
    """
    results = []
    for x, x1 in zip(individual[:-1], individual[1:], strict=False):
        c1 = cos(3 * pi * x)
        c2 = cos(4 * pi * x1)
        res = x**2 + 2 * x1**2 - 0.3 * c1 - 0.4 * c2 + 0.7
        results.append(res)
    result = sum(results)
    return (float(result),)

bm_griewank(individual)

Griewank test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-600, 600]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function see below
\[ f(\mathbf{x}) = \frac{1}{4000}\sum_{i=1}^N x_i^2 - \prod_{i=1}^N\cos\left( \frac{x_i}{\sqrt{i}}\right) + 1 \]
Source code in deap_er/private/benchmarks/bm_multimodal.py
def bm_griewank(individual: Individual) -> tuple[float]:
    r"""Griewank test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-600, 600]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = \frac{1}{4000}\sum_{i=1}^N
        x_i^2 - \prod_{i=1}^N\cos\left(
        \frac{x_i}{\sqrt{i}}\right) + 1
        $$
    """
    values = [cos(x / sqrt(i + 1.0)) for i, x in enumerate(individual)]
    exp_sum = sum(x**2 for x in individual)
    result = 1 / 4000 * exp_sum - reduce(mul, values, 1) + 1
    return (float(result),)

bm_h1(individual)

Simple two-dimensional function containing several local maxima.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type maximization
Range \(x_i \in [-100, 100]\)
Global optima \(\mathbf{x} = (8.6998, 6.7665)\), \(f(\mathbf{x}) = 2\)
Function see below
\[ f(\mathbf{x}) = \frac{\sin(x_1 - \frac{x_2}{8})^2 + \sin(x_2 + \frac{x_1}{8})^2}{\sqrt{(x_1 - 8.6998)^2 + (x_2 - 6.7665)^2} + 1} \]
Source code in deap_er/private/benchmarks/bm_multimodal.py
def bm_h1(individual: Individual) -> tuple[float]:
    r"""Simple two-dimensional function containing several local maxima.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | maximization |
        | Range | $x_i \in [-100, 100]$ |
        | Global optima | $\mathbf{x} = (8.6998, 6.7665)$, $f(\mathbf{x}) = 2$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = \frac{\sin(x_1 -
        \frac{x_2}{8})^2 + \sin(x_2 +
        \frac{x_1}{8})^2}{\sqrt{(x_1 - 8.6998)^2
        + (x_2 - 6.7665)^2} + 1}
        $$
    """

    def compute_num() -> float:
        var_1 = sin(individual[0] - individual[1] / 8) ** 2
        var_2 = sin(individual[1] + individual[0] / 8) ** 2
        return float(var_1 + var_2)

    def compute_denum() -> float:
        var_1 = (individual[0] - 8.6998) ** 2
        var_2 = (individual[1] - 6.7665) ** 2
        return float((var_1 + var_2) ** 0.5 + 1)

    result = compute_num() / compute_denum()
    return (float(result),)

bm_rastrigin(individual)

Rastrigin test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-5.12, 5.12]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function \(f(\mathbf{x}) = 10N + \sum_{i=1}^N x_i^2 - 10 \cos(2\pi x_i)\)
Source code in deap_er/private/benchmarks/bm_rastrigin.py
def bm_rastrigin(individual: Individual) -> tuple[float]:
    r"""Rastrigin test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-5.12, 5.12]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | $f(\mathbf{x}) = 10N + \sum_{i=1}^N x_i^2 - 10 \cos(2\pi x_i)$ |
    """
    values = [gene * gene - 10 * cos(2 * pi * gene) for gene in individual]
    result = 10 * len(individual) + sum(values)
    return (float(result),)

bm_rastrigin_scaled(individual)

Scaled Rastrigin test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-5.12, 5.12]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function see below
\[ f(\mathbf{x}) = 10N + \sum_{i=1}^N \left(10^{\left(\frac{i-1}{N-1}\right)} x_i \right)^2 - 10\cos\left(2\pi 10^{\left(\frac{i-1}{N-1}\right)} x_i \right) \]
Source code in deap_er/private/benchmarks/bm_rastrigin.py
def bm_rastrigin_scaled(individual: Individual) -> tuple[float]:
    r"""Scaled Rastrigin test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-5.12, 5.12]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = 10N + \sum_{i=1}^N
        \left(10^{\left(\frac{i-1}{N-1}\right)}
        x_i \right)^2 - 10\cos\left(2\pi
        10^{\left(\frac{i-1}{N-1}\right)} x_i
        \right)
        $$
    """
    results = []
    len_ind = len(individual)
    for i, x in enumerate(individual):
        var_1 = (10 ** (i / (len_ind - 1)) * x) ** 2
        var_2 = 10 * cos(2 * pi * 10 ** (i / (len_ind - 1)) * x)
        results.append(var_1 - var_2)
    result = 10 * len_ind + sum(results)
    return (float(result),)

bm_rastrigin_skewed(individual)

Skewed Rastrigin test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range \(x_i \in [-5.12, 5.12]\)
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function see below

\(f(\mathbf{x}) = 10N + \sum_{i=1}^N \left(y_i^2 - 10 \cos(2\pi x_i)\right)\)

\(\text{where } y_i = 10\cdot x_i \text{ if } x_i > 0 \text{, else } x_i\)

Source code in deap_er/private/benchmarks/bm_rastrigin.py
def bm_rastrigin_skewed(individual: Individual) -> tuple[float]:
    r"""Skewed Rastrigin test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | $x_i \in [-5.12, 5.12]$ |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | see below |

        $f(\mathbf{x}) = 10N + \sum_{i=1}^N \left(y_i^2 - 10 \cos(2\pi x_i)\right)$

        $\text{where } y_i = 10\cdot x_i \text{ if } x_i > 0 \text{, else } x_i$
    """
    results = []
    len_ind = len(individual)
    for x in individual:
        var_1 = (10 * x if x > 0 else x) ** 2
        var_2 = 10 * cos(2 * pi * (10 * x if x > 0 else x))
        results.append(var_1 - var_2)
    result = 10 * len_ind + sum(results)
    return (float(result),)

bm_shekel(individual, matrix, vector)

Evaluate the Shekel multimodal function.

The number of maxima is the length of matrix and vector.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required
matrix ndarray

Matrix of size \(M\times N\), where \(M\) is the number of maxima and \(N\) is the number of dimensions.

required
vector ndarray

Vector of size \(M\times 1\), where \(M\) is the number of maxima.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type maximization
Range None
Global optima None
Function see below
\[ f(\mathbf{x}) = \sum_{i = 1}^{M} \frac{1}{c_{i} + \sum_{j = 1}^{N} (x_{j} - a_{ij})^2 } \]
Source code in deap_er/private/benchmarks/bm_rastrigin.py
def bm_shekel(individual: Individual, matrix: numpy.ndarray, vector: numpy.ndarray) -> tuple[float]:
    r"""Evaluate the Shekel multimodal function.

    The number of maxima is the length of ``matrix`` and ``vector``.

    Args:
        individual: Individual to evaluate.
        matrix: Matrix of size $M\times N$,
            where $M$ is the number of maxima and
            $N$ is the number of dimensions.
        vector: Vector of size $M\times 1$,
            where $M$ is the number of maxima.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | maximization |
        | Range | None |
        | Global optima | None |
        | Function | see below |

        $$
        f(\mathbf{x}) = \sum_{i = 1}^{M}
        \frac{1}{c_{i} + \sum_{j = 1}^{N}
        (x_{j} - a_{ij})^2 }
        $$
    """
    results = []
    for i in range(len(vector)):
        values = []
        for j, g in enumerate(matrix[i]):
            val = (individual[j] - g) ** 2
            values.append(val)
        result = 1 / (vector[i] + sum(values))
        results.append(result)
    result = sum(results)
    return (float(result),)

bm_cigar(individual)

Cigar test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range none
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function \(f(\mathbf{x}) = x_0^2 + 10^6\sum_{i=1}^N\,x_i^2\)
Source code in deap_er/private/benchmarks/bm_unimodal.py
def bm_cigar(individual: Individual) -> tuple[float]:
    r"""Cigar test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | none |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | $f(\mathbf{x}) = x_0^2 + 10^6\sum_{i=1}^N\,x_i^2$ |
    """
    _sum = sum(gene * gene for gene in individual[1:])
    result = individual[0] ** 2 + 1e6 * _sum
    return (float(result),)

bm_plane(individual)

Plane test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

The first attribute of the individual.

Equations
Type minimization
Range none
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function \(f(\mathbf{x}) = x_0\)
Source code in deap_er/private/benchmarks/bm_unimodal.py
def bm_plane(individual: Individual) -> tuple[float]:
    r"""Plane test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The first attribute of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | none |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | $f(\mathbf{x}) = x_0$ |
    """
    result = individual[0]
    return (float(result),)

bm_rand(*_)

Random test objective function. Unused extra arguments are ignored.

Returns:

Type Description
tuple[float]

A uniformly random number in [0, 1).

Equations
Type minimization or maximization
Range none
Global optima none
Function \(f(\mathbf{x}) = \text{random}(0,1)\)
Source code in deap_er/private/benchmarks/bm_unimodal.py
def bm_rand(*_) -> tuple[float]:
    r"""Random test objective function. Unused extra arguments are ignored.

    Returns:
        A uniformly random number in ``[0, 1)``.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization or maximization |
        | Range | none |
        | Global optima | none |
        | Function | $f(\mathbf{x}) = \text{random}(0,1)$ |
    """
    result = rng.random()
    return (float(result),)

bm_rosenbrock(individual)

Rosenbrock test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range none
Global optima \(x_i = 1, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function \(f(\mathbf{x}) = \sum_{i=1}^{N-1} (1-x_i)^2 + 100 (x_{i+1} - x_i^2 )^2\)
Source code in deap_er/private/benchmarks/bm_unimodal.py
def bm_rosenbrock(individual: Individual) -> tuple[float]:
    r"""Rosenbrock test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | none |
        | Global optima | $x_i = 1, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | $f(\mathbf{x}) = \sum_{i=1}^{N-1} (1-x_i)^2 + 100 (x_{i+1} - x_i^2 )^2$ |
    """
    results = []
    for x, y in zip(individual[:-1], individual[1:], strict=False):
        results.append(100 * (x * x - y) ** 2 + (1 - x) ** 2)
    result = sum(results)
    return (float(result),)

bm_sphere(individual)

Sphere test objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float]

Fitness value of the individual.

Equations
Type minimization
Range none
Global optima \(x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace\), \(f(\mathbf{x}) = 0\)
Function \(f(\mathbf{x}) = \sum_{i=1}^Nx_i^2\)
Source code in deap_er/private/benchmarks/bm_unimodal.py
def bm_sphere(individual: Individual) -> tuple[float]:
    r"""Sphere test objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness value of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Type | minimization |
        | Range | none |
        | Global optima | $x_i = 0, \forall i \in \lbrace 1 \ldots N\rbrace$, $f(\mathbf{x}) = 0$ |
        | Function | $f(\mathbf{x}) = \sum_{i=1}^Nx_i^2$ |
    """
    result = sum(gene * gene for gene in individual)
    return (float(result),)

bm_zdt_1(individual)

ZDT1 multi-objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}) = 1 + \frac{9}{n-1}\sum_{i=2}^n x_i\)

\(f_{1}(\mathbf{x}) = x_1\)

\(f_{2}(\mathbf{x}) = g(\mathbf{x})\left[1 - \sqrt{\frac{x_1}{g(\mathbf{x})}}\right]\)

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_zdt.py
def bm_zdt_1(individual: Individual) -> tuple[float, float]:
    r"""ZDT1 multi-objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}) = 1 + \frac{9}{n-1}\sum_{i=2}^n x_i$

        $f_{1}(\mathbf{x}) = x_1$

        $f_{2}(\mathbf{x}) = g(\mathbf{x})\left[1 - \sqrt{\frac{x_1}{g(\mathbf{x})}}\right]$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    g = _zdt_g(individual)
    f1 = individual[0]
    f2 = g * (1 - sqrt(f1 / g))
    return float(f1), float(f2)

bm_zdt_2(individual)

ZDT2 multi-objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}) = 1 + \frac{9}{n-1}\sum_{i=2}^n x_i\)

\(f_{1}(\mathbf{x}) = x_1\)

\[ f_{2}(\mathbf{x}) = g(\mathbf{x})\left[1 - \left(\frac{x_1}{g(\mathbf{x})}\right)^2\right] \]

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_zdt.py
def bm_zdt_2(individual: Individual) -> tuple[float, float]:
    r"""ZDT2 multi-objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}) = 1 + \frac{9}{n-1}\sum_{i=2}^n x_i$

        $f_{1}(\mathbf{x}) = x_1$

        $$
        f_{2}(\mathbf{x}) = g(\mathbf{x})\left[1 -
        \left(\frac{x_1}{g(\mathbf{x})}\right)^2\right]
        $$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    g = _zdt_g(individual)
    f1 = individual[0]
    f2 = g * (1 - (f1 / g) ** 2)
    return float(f1), float(f2)

bm_zdt_3(individual)

ZDT3 multi-objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}) = 1 + \frac{9}{n-1}\sum_{i=2}^n x_i\)

\(f_{1}(\mathbf{x}) = x_1\)

\[ f_{2}(\mathbf{x}) = g(\mathbf{x})\left[1 - \sqrt{\frac{x_1}{g(\mathbf{x})}} - \frac{x_1}{g(\mathbf{x})} \sin(10\pi x_1)\right] \]

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_zdt.py
def bm_zdt_3(individual: Individual) -> tuple[float, float]:
    r"""ZDT3 multi-objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}) = 1 + \frac{9}{n-1}\sum_{i=2}^n x_i$

        $f_{1}(\mathbf{x}) = x_1$

        $$
        f_{2}(\mathbf{x}) = g(\mathbf{x})\left[1 -
        \sqrt{\frac{x_1}{g(\mathbf{x})}} -
        \frac{x_1}{g(\mathbf{x})} \sin(10\pi x_1)\right]
        $$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    g = _zdt_g(individual)
    f1 = individual[0]
    f2 = g * (1 - sqrt(f1 / g) - f1 / g * sin(10 * pi * f1))
    return float(f1), float(f2)

bm_zdt_4(individual)

ZDT4 multi-objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}) = 1 + 10(n-1) + \sum_{i=2}^n \left[ x_i^2 - 10\cos(4\pi x_i) \right]\)

\(f_{1}(\mathbf{x}) = x_1\)

\[ f_{2}(\mathbf{x}) = g(\mathbf{x}) \left[ 1 - \sqrt{ \frac{x_1}{g(\mathbf{x})}} \right] \]

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_zdt.py
def bm_zdt_4(individual: Individual) -> tuple[float, float]:
    r"""ZDT4 multi-objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}) = 1 + 10(n-1) + \sum_{i=2}^n \left[ x_i^2 - 10\cos(4\pi x_i) \right]$

        $f_{1}(\mathbf{x}) = x_1$

        $$
        f_{2}(\mathbf{x}) = g(\mathbf{x}) \left[ 1 -
        \sqrt{ \frac{x_1}{g(\mathbf{x})}} \right]
        $$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    var = sum(xi**2 - 10 * cos(4 * pi * xi) for xi in individual[1:])
    g = 1 + 10 * (len(individual) - 1) + var
    f1 = individual[0]
    f2 = g * (1 - sqrt(f1 / g))
    return float(f1), float(f2)

bm_zdt_6(individual)

ZDT6 multi-objective function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
tuple[float, float]

Fitness values of the individual.

Equations

\(g(\mathbf{x}) = 1 + 9 \left[ \left(\sum_{i=2}^n x_i\right)/(n-1) \right]^{0.25}\)

\(f_{1}(\mathbf{x}) = 1 - \exp(-4x_1)\sin^6(6\pi x_1)\)

\[ f_{2}(\mathbf{x}) = g(\mathbf{x}) \left[1 - \left(\frac{f_{1}(\mathbf{x})}{g(\mathbf{x})} \right)^2 \right] \]

Returns \(f_{1}(\mathbf{x})\) and \(f_{2}(\mathbf{x})\).

Source code in deap_er/private/benchmarks/bm_zdt.py
def bm_zdt_6(individual: Individual) -> tuple[float, float]:
    r"""ZDT6 multi-objective function.

    Args:
        individual: Individual to evaluate.

    Returns:
        Fitness values of the individual.

    ??? note "Equations"

        $g(\mathbf{x}) = 1 + 9 \left[ \left(\sum_{i=2}^n x_i\right)/(n-1) \right]^{0.25}$

        $f_{1}(\mathbf{x}) = 1 - \exp(-4x_1)\sin^6(6\pi x_1)$

        $$
        f_{2}(\mathbf{x}) = g(\mathbf{x}) \left[1 -
        \left(\frac{f_{1}(\mathbf{x})}{g(\mathbf{x})}
        \right)^2 \right]
        $$

        Returns $f_{1}(\mathbf{x})$ and $f_{2}(\mathbf{x})$.
    """
    g = 1 + 9 * (sum(individual[1:]) / (len(individual) - 1)) ** 0.25
    f1 = 1 - exp(-4 * individual[0]) * sin(6 * pi * individual[0]) ** 6
    f2 = g * (1 - (f1 / g) ** 2)
    return float(f1), float(f2)

bm_kotanchek(individual)

Kotanchek benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [-1, 7]^2\)
Function \(f(\mathbf{x}) = \frac{e^{-(x_1 - 1)^2}}{1.2 + (x_2 - 2.5)^2}\)
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_kotanchek(individual: Individual) -> float:
    r"""Kotanchek benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [-1, 7]^2$ |
        | Function | $f(\mathbf{x}) = \frac{e^{-(x_1 - 1)^2}}{1.2 + (x_2 - 2.5)^2}$ |
    """
    i = individual[0]
    j = individual[1]
    numer = exp(-((i - 1) ** 2))
    de_nom = 1.2 + (j - 2.5) ** 2
    return float(numer / de_nom)

bm_rational_polynomial_1(individual)

Rational polynomial ball benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [0, 2]^3\)
Function \(f(\mathbf{x}) = \frac{30 * (x_1 - 1) (x_3 - 1)}{x_2^2 (x_1 - 10)}\)
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_rational_polynomial_1(individual: Individual) -> float:
    r"""Rational polynomial ball benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [0, 2]^3$ |
        | Function | $f(\mathbf{x}) = \frac{30 * (x_1 - 1) (x_3 - 1)}{x_2^2 (x_1 - 10)}$ |
    """
    i = individual[0]
    j = individual[1]
    k = individual[2]
    numer = 30 * (i - 1) * (k - 1)
    de_nom = j**2 * (i - 10)
    return float(numer / de_nom)

bm_rational_polynomial_2(individual)

Rational polynomial benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [0, 6]^2\)
Function see below
\[ f(\mathbf{x}) = \frac{(x_1 - 3)^4 + (x_2 - 3)^3 - (x_2 - 3)}{(x_2 - 2)^4 + 10} \]
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_rational_polynomial_2(individual: Individual) -> float:
    r"""Rational polynomial benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [0, 6]^2$ |
        | Function | see below |

        $$
        f(\mathbf{x}) = \frac{(x_1 - 3)^4 + (x_2 - 3)^3
        - (x_2 - 3)}{(x_2 - 2)^4 + 10}
        $$
    """
    i = individual[0]
    j = individual[1]
    numer = (i - 3) ** 4 + (j - 3) ** 3 - (j - 3)
    de_nom = (j - 2) ** 4 + 10
    return float(numer / de_nom)

bm_ripple(individual)

Ripple benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [-5, 5]^2\)
Function \(f(\mathbf{x}) = (x_1 - 3) (x_2 - 3) + 2 \sin((x_1 - 4) (x_2 -4))\)
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_ripple(individual: Individual) -> float:
    r"""Ripple benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [-5, 5]^2$ |
        | Function | $f(\mathbf{x}) = (x_1 - 3) (x_2 - 3) + 2 \sin((x_1 - 4) (x_2 -4))$ |
    """
    i = individual[0]
    j = individual[1]
    a = (i - 3) * (j - 3)
    b = 2 * sin((i - 4) * (j - 4))
    return float(a + b)

bm_salustowicz_1d(individual)

Salustowicz benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(x \in [0, 10]\)
Function \(f(x) = e^{-x} x^3 \cos(x) \sin(x) (\cos(x) \sin^2(x) - 1)\)
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_salustowicz_1d(individual: Individual) -> float:
    r"""Salustowicz benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $x \in [0, 10]$ |
        | Function | $f(x) = e^{-x} x^3 \cos(x) \sin(x) (\cos(x) \sin^2(x) - 1)$ |
    """
    i = individual[0]
    a = exp(-i) * i**3 * cos(i)
    b = sin(i) * (cos(i) * sin(i) ** 2 - 1)
    return float(a * b)

bm_salustowicz_2d(individual)

Salustowicz benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [0, 7]^2\)
Function see below
\[ f(\mathbf{x})=e^{-x_1} x_1^3\cos(x_1)\sin(x_1) (\cos(x_1)\sin^2(x_1)-1)(x_2-5) \]
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_salustowicz_2d(individual: Individual) -> float:
    r"""Salustowicz benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [0, 7]^2$ |
        | Function | see below |

        $$
        f(\mathbf{x})=e^{-x_1} x_1^3\cos(x_1)\sin(x_1)
        (\cos(x_1)\sin^2(x_1)-1)(x_2-5)
        $$
    """
    i = individual[0]
    j = individual[1]
    a = exp(-i) * i**3 * cos(i) * sin(i)
    b = (cos(i) * sin(i) ** 2 - 1) * (j - 5)
    return float(a * b)

bm_sin_cos(individual)

Sine cosine benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [0, 6]^2\)
Function \(f(\mathbf{x}) = 6\sin(x_1)\cos(x_2)\)
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_sin_cos(individual: Individual) -> float:
    r"""Sine cosine benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [0, 6]^2$ |
        | Function | $f(\mathbf{x}) = 6\sin(x_1)\cos(x_2)$ |
    """
    i = individual[0]
    j = individual[1]
    return 6 * sin(i) * cos(j)

bm_unwrapped_ball(individual)

Unwrapped ball benchmark function.

Parameters:

Name Type Description Default
individual Individual

Individual to evaluate.

required

Returns:

Type Description
float

The fitness of the individual.

Equations
Range \(\mathbf{x} \in [-2, 8]^n\)
Function \(f(\mathbf{x}) = \frac{10}{5 + \sum_{i=1}^n (x_i - 3)^2}\)
Source code in deap_er/private/benchmarks/symb_regr.py
def bm_unwrapped_ball(individual: Individual) -> float:
    r"""Unwrapped ball benchmark function.

    Args:
        individual: Individual to evaluate.

    Returns:
        The fitness of the individual.

    ??? note "Equations"

        | | |
        |---|---|
        | Range | $\mathbf{x} \in [-2, 8]^n$ |
        | Function | $f(\mathbf{x}) = \frac{10}{5 + \sum_{i=1}^n (x_i - 3)^2}$ |
    """
    s = sum((d - 3) ** 2 for d in individual)
    return float(10 / (5 + s))