Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/algorithms/agemoea.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Evaluations: 400
| Polynomial mutation | Numeric probability `1/12`, eta 20. |
| `constraint_mode("feasibility")` | Enables feasibility-based selection if constraints exist; DTLZ2 here is unconstrained. |
| `constraint_handling(name, ...)` | **VAMOS 1.2.0:** ranks a constrained population with another of jMetal's techniques; its fronts take the place of the non-dominated ones in the survival and the tournament. See [choose a constraint-handling technique](../reference/constraints.md#choose-a-constraint-handling-technique). |
| `variant("agemoea_ii")` | **Development after 1.4.0:** runs AGE-MOEA-II [2], whose survival estimates the front's geometry by Newton-Raphson and measures diversity with geodesic distances; the default `"agemoea"` is the algorithm of this page. See [AGE-MOEA-II](../reference/algorithms.md#age-moea-ii). |

## Interpret the result and its limits

Expand All @@ -186,3 +187,5 @@ Increase the budget to 800 while holding the problem and population fixed. Exami
## References

[1] Panichella, A. (2019). [An Adaptive Evolutionary Algorithm based on Non-Euclidean Geometry for Many-objective Optimization](https://apanichella.github.io/publication/gecco2019/). *GECCO 2019*.

[2] Panichella, A. (2022). [An Improved Pareto Front Modeling Algorithm for Large-scale Many-Objective Optimization](https://doi.org/10.1145/3512290.3528732). *GECCO 2022*, 565-573.
30 changes: 30 additions & 0 deletions docs/reference/algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,36 @@ on ZDT1, from 0.7426 to 0.7443 on DTLZ2 and from 0.1880 to 0.1892 on DTLZ1,
within seed variation of jMetal 7.9's AGE-MOEA (0.8545, 0.7446 and 0.1890).
AGE-MOEA results from VAMOS 1.1.0 and earlier differ with the same seed.

### AGE-MOEA-II

**Development after 1.4.0:** `AGEMOEAConfig.builder().variant("agemoea_ii")` runs
AGE-MOEA-II (Panichella, GECCO 2022). Its survival differs from AGE-MOEA's in two
steps of the first-front score, which are those that jMetal's
`AGEMOEA2EnvironmentalSelection`, written by the author, overrides:

- the exponent `p` of the front is the one whose Minkowski norm of the
non-extreme point nearest to the ideal point is 1, found by Newton-Raphson
from `p = 1` (precision 0.001, at most 100 steps), instead of a closed form
from the point nearest to the diagonal;
- the diversity uses geodesic distances on the estimated `L_p` manifold: both
points and their midpoint are projected on it, and the distance is the
length of the path through the projected midpoint.

Everything else, the extreme points, the normalization, the scores of later
fronts and the mating tournament, is AGE-MOEA's above, with that `p`. The
exponents and distances agree with jMetal's on every case of
`tests/engine/data/agemoea2_jmetal_values.json`, and so do the survival scores
on the fronts where AGE-MOEA's shared steps agree with jMetal's. They do not
agree where AGE-MOEA's extreme points or its tie-breaking (on exactly linear
fronts) depart from jMetal, as described above for AGE-MOEA. As in AGE-MOEA,
`p` is capped at 20, which pymoo's AGE-MOEA-II also does and jMetal does not; a
point at the ideal point is not projected. pymoo takes the straight Euclidean
distance when `0.95 < p < 1.05`; VAMOS, like jMetal, always goes through the
midpoint, and both coincide when `p = 1`.

The tuning spaces of AGE-MOEA choose it with `replacement: agemoea_ii`, the
name of Evolver's parameter (`agemoeaII` in Evolver).

### Where the variants depart from their references

These are declared VAMOS choices, not defects; report them when comparing with
Expand Down
12 changes: 11 additions & 1 deletion docs/topics/tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ The paragraphs above use the earlier names.
| `normalization_epsilon` | `normalization_epsilon` | `epsilonParameterForNormalization` |
| `ipbi_theta` | `ipbi_theta` | `ipbiTheta` |
| `de_scheme` | `de_scheme` | `differentialEvolutionCrossover` |
| `replacement` | `replacement` | `replacement` |

Values that change: mutation `pm` becomes `polynomial` (the name the other
spaces already used) and crossover `undx` becomes `undc` (Evolver's `UNDC`).
Expand All @@ -546,7 +547,9 @@ differently, and the exchange functions translate them: `SBX`, `blxAlpha`,
`linkedPolynomial`, `nonUniform`, `levyFlight` and `powerLaw`;
`tschebyscheff`, `weightedSum`, `penaltyBoundaryIntersection` and
`modifiedTschebyscheff`; `default` (random; **VAMOS 1.4.0:** `auto`), `latinHypercubeSampling`,
`scatterSearch` and `oppositionBased`; `stochasticUniversalSampling`.
`scatterSearch` and `oppositionBased`; `stochasticUniversalSampling`;
**Development after 1.4.0:** AGE-MOEA's `replacement` `agemoeaII`
(`agemoea_ii`).

**VAMOS 1.4.0:** Evolver's `modifiedTschebyscheff` is jMetal's
`ModifiedTschebyscheff`, `max |f - z*| / w`, which VAMOS calls
Expand Down Expand Up @@ -703,6 +706,13 @@ spaces of VAMOS 1.3.0, with `pop_size`, `use_external_archive` or an absolute
`mutation_prob`, or with the names of VAMOS 1.2.1, builds the configuration it
built.

**Development after 1.4.0:** every AGE-MOEA space (`agemoea`, `agemoea_constrained`,
`agemoea_binary`, `agemoea_integer`, `agemoea_permutation` and `agemoea_mixed`)
offers `replacement`, Evolver's choice between AGE-MOEA's survival (`agemoea`,
the default) and AGE-MOEA-II's (`agemoea_ii`, Evolver's `agemoeaII`); see
[AGE-MOEA-II](../reference/algorithms.md#age-moea-ii). The default still builds
the configuration of VAMOS 1.4.0.

### Constrained spaces

**VAMOS 1.2.0:** `nsgaii_constrained`, `nsgaiii_constrained`,
Expand Down
24 changes: 17 additions & 7 deletions src/vamos/engine/algorithm/agemoea/agemoea.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
validate_initial_budget,
)
from vamos.engine.algorithm.config.base import normalize_constraint_mode
from vamos.engine.algorithm.config.types import resolve_agemoea_variant
from vamos.engine.archive.factory import resolve_external_archive, setup_archive
from vamos.engine.config.variation import (
ensure_operator_tuple,
Expand Down Expand Up @@ -116,6 +117,11 @@ class AGEMOEA:
zero coefficient also falls back to the front maximum, and the default
variation is SBX(0.9, 15) with polynomial mutation.

The configuration's ``variant="agemoea_ii"`` runs AGE-MOEA-II (Panichella,
GECCO 2022), whose survival estimates ``p`` by Newton-Raphson and measures
diversity with geodesic distances on the estimated manifold; everything
else is the same.

Parameters
----------
config : dict
Expand Down Expand Up @@ -149,9 +155,9 @@ def __init__(self, config: dict[str, Any], kernel: KernelBackend | None = None)

def _refresh_selection_metrics(self, st: AGEMOEAState) -> None:
if st.constraint_handling is not None and st.G is not None:
ranks, scores = technique_selection_metrics(self.kernel, st.F, st.G, st.constraint_handling, st.rng)
ranks, scores = technique_selection_metrics(self.kernel, st.F, st.G, st.constraint_handling, st.rng, variant=st.variant)
else:
ranks, scores = population_selection_metrics(self.kernel, st.F, st.G, st.constraint_mode)
ranks, scores = population_selection_metrics(self.kernel, st.F, st.G, st.constraint_mode, st.variant)
st.selection_ranks = ranks
st.selection_crowding = scores

Expand Down Expand Up @@ -214,6 +220,7 @@ def initialize(
pop_size = int(self.cfg.get("pop_size", 100))
constraint_mode = normalize_constraint_mode(self.cfg.get("constraint_mode", "feasibility"))
constraint_handling = run_technique(self.cfg.get("constraint_handling"), constraint_mode)
variant = resolve_agemoea_variant(self.cfg.get("variant", "agemoea"))
n_constraints = int(getattr(problem, "n_constraints", 0) or 0)
max_evals, hv_config = parse_termination(termination, "AGE-MOEA", pop_size)
validate_initial_budget(max_evals, pop_size, "AGE-MOEA")
Expand Down Expand Up @@ -249,9 +256,9 @@ def initialize(
G,
)
if constraint_handling is not None and G is not None:
selection_ranks, selection_crowding = technique_selection_metrics(self.kernel, F, G, constraint_handling, rng)
selection_ranks, selection_crowding = technique_selection_metrics(self.kernel, F, G, constraint_handling, rng, variant=variant)
else:
selection_ranks, selection_crowding = population_selection_metrics(self.kernel, F, G, constraint_mode)
selection_ranks, selection_crowding = population_selection_metrics(self.kernel, F, G, constraint_mode, variant)

result_mode = str(self.cfg.get("result_mode", "non_dominated")).strip().lower()
if result_mode not in {"non_dominated", "population"}:
Expand All @@ -270,6 +277,7 @@ def initialize(
variation=variation,
constraint_mode=constraint_mode,
constraint_handling=constraint_handling,
variant=variant,
archive_size=ext_cfg.capacity if ext_cfg is not None else None,
archive_X=archive_X,
archive_F=archive_F,
Expand Down Expand Up @@ -380,17 +388,19 @@ def tell(self, eval_result: Any, problem: ProblemProtocol | None = None) -> bool
# The technique follows the evaluations before the offspring's.
progress = run_progress(st.n_eval, st.max_evals)
survivors, survival_scores = technique_age_survival(
F_combined, G_combined, st.pop_size, self.kernel, technique, st.rng, progress
F_combined, G_combined, st.pop_size, self.kernel, technique, st.rng, progress, st.variant
)
else:
survivors, survival_scores = constraint_aware_age_survival(F_combined, G_combined, st.pop_size, self.kernel, st.constraint_mode)
survivors, survival_scores = constraint_aware_age_survival(
F_combined, G_combined, st.pop_size, self.kernel, st.constraint_mode, st.variant
)
st.X = X_combined[survivors]
st.F = F_combined[survivors]
st.G = G_combined[survivors] if G_combined is not None else None
st.n_eval += X_off.shape[0]
if technique is not None and st.G is not None:
st.selection_ranks, st.selection_crowding = technique_selection_metrics(
self.kernel, st.F, st.G, technique, st.rng, survival_scores
self.kernel, st.F, st.G, technique, st.rng, survival_scores, st.variant
)
else:
st.selection_ranks, st.selection_crowding = selection_metrics(self.kernel, st.F, st.G, st.constraint_mode, survival_scores)
Expand Down
92 changes: 87 additions & 5 deletions src/vamos/engine/algorithm/agemoea/geometry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"""Geometry helpers for AGE-MOEA survival selection."""
"""Geometry helpers for AGE-MOEA survival selection.

Both variants of Panichella's algorithm share the survival below: AGE-MOEA (GECCO 2019) and
AGE-MOEA-II (GECCO 2022), which estimates the exponent ``p`` of the front by Newton-Raphson and
measures diversity with geodesic distances on the estimated manifold.
"""

from __future__ import annotations

from typing import Any

import numpy as np

from vamos.engine.algorithm.config.types import AGEMOEAVariant
from vamos.foundation.kernel.backend import KernelBackend, SelectionKernels


Expand Down Expand Up @@ -82,10 +88,79 @@ def _compute_geometry(front: np.ndarray[Any, Any], extreme: np.ndarray[Any, Any]
return float(p)


def _newton_exponent(point: np.ndarray[Any, Any], precision: float = 1e-3, iterations: int = 100) -> float:
"""The exponent ``p`` whose Minkowski norm of ``point`` is 1: the zero of ``log(sum_i |a_i|^p)``.

Newton-Raphson from ``p = 1``, as in jMetal's ``AGEMOEA2EnvironmentalSelection.findZero`` (the
author's port): at most ``iterations`` steps, stopping when a step moves less than ``precision``.
The function sums every coordinate and its derivative only the positive ones. A failed search
returns a non-finite value, which :func:`_compute_geometry_ii` replaces.
"""
raw = np.asarray(point, dtype=float)
a = np.abs(raw)
positive = raw[raw > 0.0]
log_positive = np.log(positive)
x = np.float64(1.0)
past = x
with np.errstate(all="ignore"):
for _ in range(iterations):
f = np.log(np.sum(a**x))
powers = positive**x
denominator = np.sum(powers)
derivative = np.sum(powers * log_positive) / denominator if denominator != 0.0 else np.float64(1.0)
x = x - f / derivative
if abs(x - past) <= precision:
break
past = x
return float(x)


def _compute_geometry_ii(front: np.ndarray[Any, Any], extreme: np.ndarray[Any, Any]) -> float:
"""AGE-MOEA-II's exponent of the normalized front.

The reference point is the non-extreme point nearest to the origin (the ideal point), not the
one nearest to the diagonal as in AGE-MOEA, and ``p`` makes its Minkowski norm 1
(:func:`_newton_exponent`). As in jMetal, a non-finite ``p`` or one below 0.1 means a flat front,
``p = 1``; as in AGE-MOEA and pymoo's AGE-MOEA-II, ``p`` is capped at 20.
"""
d = np.sqrt(np.sum(front * front, axis=1))
d[extreme] = np.inf
index = int(np.argmin(d))
p = _newton_exponent(front[index])
if not np.isfinite(p) or p < 0.1:
return 1.0
return float(min(p, 20.0))


def _project_on_manifold(points: np.ndarray[Any, Any], p: float) -> np.ndarray[Any, Any]:
"""``points`` scaled to Minkowski norm 1 of order ``p``; a point of norm 0 stays as it is."""
norms = np.sum(np.abs(points) ** p, axis=-1) ** (1.0 / p)
scale = np.where(norms > 0.0, 1.0 / np.where(norms > 0.0, norms, 1.0), 1.0)
return np.asarray(points * scale[..., None], dtype=float)


def _geodesic_distances(front: np.ndarray[Any, Any], p: float) -> np.ndarray[Any, Any]:
"""AGE-MOEA-II's pairwise distances: the geodesic distances on the ``L_p`` manifold, approximated.

Both points are projected on the manifold, and so is their midpoint; the distance is the
Euclidean length of the path through the projected midpoint, as in jMetal's
``AGEMOEA2EnvironmentalSelection.pairwiseDistances``. pymoo takes the straight Euclidean distance
when ``0.95 < p < 1.05``; on the simplex (``p = 1``) both coincide.
"""
projected = _project_on_manifold(front, p)
midpoints = _project_on_manifold(0.5 * projected[:, None, :] + 0.5 * projected[None, :, :], p)
to_mid = np.sqrt(np.sum((projected[:, None, :] - midpoints) ** 2, axis=2))
from_mid = np.sqrt(np.sum((midpoints - projected[None, :, :]) ** 2, axis=2))
distances = to_mid + from_mid
np.fill_diagonal(distances, 0.0)
return np.asarray(distances, dtype=float)


def _survival_score(
front: np.ndarray[Any, Any],
ideal_point: np.ndarray[Any, Any],
selection_kernels: SelectionKernels | None = None,
variant: AGEMOEAVariant = "agemoea",
) -> tuple[np.ndarray[Any, Any], float, np.ndarray[Any, Any]]:
m, n = front.shape
crowd_dist = np.zeros(m, dtype=float)
Expand All @@ -108,11 +183,12 @@ def _survival_score(
selected = np.full(m, False)
selected[extreme] = True

p = _compute_geometry(front, extreme, n)
ii = variant == "agemoea_ii"
p = _compute_geometry_ii(front, extreme) if ii else _compute_geometry(front, extreme, n)
nn = np.linalg.norm(front, ord=p, axis=1)
nn[nn < 1e-8] = 1.0

distances = _pairwise_distances(front, p)
distances = _geodesic_distances(front, p) if ii else _pairwise_distances(front, p)
distances[distances < 1e-8] = 1e-8
distances = distances / nn[:, None]

Expand Down Expand Up @@ -177,8 +253,9 @@ def age_survival(
n_survive: int,
kernel: KernelBackend,
ranks: np.ndarray[Any, Any] | None = None,
variant: AGEMOEAVariant = "agemoea",
) -> tuple[np.ndarray[Any, Any], np.ndarray[Any, Any]]:
"""Select AGE-MOEA survivors from a combined parent-offspring front.
"""Select AGE-MOEA or AGE-MOEA-II survivors from a combined parent-offspring front.

Returns the survivor indices in ascending order and their survival scores,
as PlatEMO's ``EnvironmentalSelection`` (Panichella's own code) defines
Expand All @@ -198,6 +275,11 @@ def age_survival(

The fronts are the non-dominated ones unless ``ranks`` gives them, as a
constraint-handling technique does in Evolver's AGE-MOEA.

``variant="agemoea_ii"`` scores the first front as AGE-MOEA-II does (Panichella, GECCO 2022):
the exponent ``p`` by :func:`_compute_geometry_ii` and the diversity by
:func:`_geodesic_distances`. The rest, later fronts included, is AGE-MOEA's, with that ``p``, as
in jMetal, whose AGE-MOEA-II overrides only those two steps.
"""
n_survive = min(int(n_survive), F.shape[0])
if ranks is None:
Expand All @@ -222,7 +304,7 @@ def age_survival(

front0 = F[ranks == 0, :]
ideal_point = np.min(front0, axis=0)
crowd_dist[ranks == 0], p, normalization = _survival_score(front0, ideal_point, kernel.selection_kernels())
crowd_dist[ranks == 0], p, normalization = _survival_score(front0, ideal_point, kernel.selection_kernels(), variant)

for r in range(1, last_rank + 1):
front_idx = fronts[r]
Expand Down
3 changes: 3 additions & 0 deletions src/vamos/engine/algorithm/agemoea/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
with_constraints,
)
from vamos.engine.algorithm.components.state import AlgorithmState
from vamos.engine.algorithm.config.types import AGEMOEAVariant

if TYPE_CHECKING:
from vamos.engine.variation.pipeline import VariationPipeline
Expand All @@ -36,6 +37,8 @@ class AGEMOEAState(AlgorithmState):
variation: VariationPipeline | None = None
selection_ranks: Any = field(default=None, repr=False, compare=False)
selection_crowding: Any = field(default=None, repr=False, compare=False)
# The survival's variant: AGE-MOEA or AGE-MOEA-II.
variant: AGEMOEAVariant = "agemoea"


def build_agemoea_result(
Expand Down
Loading
Loading