Utilities¶
jmetal.util provides the archives, distance metrics, comparators, density estimators, and other
supporting utilities used throughout the framework. Evaluators, observers, and termination
criteria have their own tutorials with usage examples — see
Evaluators, Observers.
Archives¶
Archives are data structures for storing and managing collections of solutions during the optimization process. jMetalPy provides several implementations for different use cases:
- Archive: Base abstract class for all archives
- BoundedArchive: Archive with size limits
- NonDominatedSolutionsArchive: Maintains only non-dominated solutions
- CrowdingDistanceArchive: Uses crowding distance for diversity
- DistanceBasedArchive: Adaptive distance-based selection
DistanceBasedArchive¶
DistanceBasedArchive provides adaptive selection strategies based on the number of objectives:
- 2 objectives: Uses crowding distance selection for optimal diversity along Pareto fronts
- >2 objectives: Uses distance-based subset selection with normalization
Key features:
- Automatic strategy adaptation based on problem dimensionality
- Robust normalization handling constant objectives
- Support for custom distance measures
- Non-dominated solution filtering using Pareto dominance
- Memory-efficient in-place list modifications
Algorithm for many-objective problems:
- Normalize objectives to [0,1] range using min-max normalization
- Select random objective for initial sorting
- Choose extreme solutions (best and worst in random objective)
- Select remaining solutions using maximum minimum distance criterion
Example usage:
from jmetal.util.archive import DistanceBasedArchive
from jmetal.util.distance import DistanceMetric
# Create archive with a custom distance metric
archive = DistanceBasedArchive(
maximum_size=10,
metric=DistanceMetric.L2_SQUARED,
)
# Add solutions - automatically adapts strategy
for solution in solutions:
archive.add(solution)
DistanceBasedArchive(maximum_size, metric=DistanceMetric.L2_SQUARED, weights=None, random_seed=None, dominance_comparator=None, use_vectorized=True)
¶
Bases: BoundedArchive[S]
Archive that maintains solutions using adaptive distance-based subset selection.
This archive extends BoundedArchive to use a sophisticated selection mechanism: - For 2 objectives: Uses crowding distance selection - For >2 objectives: Uses robust distance-based subset selection with normalization
The implementation follows the Java jMetal SafeBestSolutionsArchive algorithm.
Initialize the distance-based archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maximum_size
|
int
|
Maximum number of solutions to maintain |
required |
metric
|
DistanceMetric
|
Distance metric to use (default: L2_SQUARED) |
L2_SQUARED
|
weights
|
ndarray | None
|
Optional weights for TCHEBY_WEIGHTED metric |
None
|
random_seed
|
int | None
|
Optional seed for reproducible results |
None
|
dominance_comparator
|
Comparator | None
|
Comparator for dominance (default: DominanceComparator) |
None
|
use_vectorized
|
bool
|
Whether to use vectorized implementation (default: True) |
True
|
Source code in src/jmetal/util/archive.py
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
add(solution)
¶
Add a solution to the archive using non-dominated sorting and distance-based selection. Thread-safe implementation for concurrent use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
S
|
Solution to add |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if solution was added or archive was modified, False otherwise |
Source code in src/jmetal/util/archive.py
compute_density_estimator()
¶
Override parent method since we use distance-based selection instead. This method is called by parent class but we don't need density estimation.
Source code in src/jmetal/util/archive.py
Distance-based subset selection¶
Standalone function for distance-based subset selection that can be used independently of the archive.
- Selection strategy: for 2 objectives, delegates to crowding distance selection; for more than 2, uses the distance-based algorithm with normalization.
from jmetal.util.archive import distance_based_subset_selection
# Select 5 best solutions from a larger set
selected = distance_based_subset_selection(
solution_list=all_solutions,
subset_size=5,
)
distance_based_subset_selection(solution_list, subset_size, distance_measure=None, metric=DistanceMetric.L2_SQUARED, weights=None, random_seed=None)
¶
Backward compatibility wrapper for distance_based_subset_selection_robust.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution_list
|
list[S]
|
List of solutions to select from |
required |
subset_size
|
int
|
Number of solutions to select |
required |
distance_measure
|
object | None
|
Deprecated parameter (ignored) |
None
|
metric
|
DistanceMetric
|
Distance metric to use |
L2_SQUARED
|
weights
|
ndarray | None
|
Optional weights for TCHEBY_WEIGHTED metric |
None
|
random_seed
|
int | None
|
Optional seed for reproducible results |
None
|
Returns:
| Type | Description |
|---|---|
list[S]
|
List of selected solutions |
Source code in src/jmetal/util/archive.py
Other archive classes¶
Archive()
¶
Bases: Generic[S], ABC
add_batch(solutions)
¶
Add many solutions at once.
The default implementation just calls add() once per solution; it exists
so callers that have a whole batch on hand (e.g. an Evaluation component
adding a generation's worth of evaluated solutions) have one method to call
regardless of archive type. Subclasses where checking the whole batch at
once is meaningfully faster than one insertion at a time (see
NonDominatedSolutionsArchive) should override it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solutions
|
list[S]
|
The solutions to add. |
required |
Source code in src/jmetal/util/archive.py
BoundedArchive(maximum_size, comparator=None, density_estimator=None, dominance_comparator=DominanceComparator())
¶
Bases: Archive[S]
Source code in src/jmetal/util/archive.py
NonDominatedSolutionsArchive(dominance_comparator=DominanceComparator(), objective_tolerance=1e-10)
¶
Bases: Archive[S]
Archive that maintains only non-dominated solutions using Pareto dominance.
This implementation efficiently manages a collection of solutions by: - Adding new non-dominated solutions - Removing solutions dominated by new ones - Preventing duplicate solutions based on objectives
Time Complexity: O(n) per insertion, where n is archive size Space Complexity: O(n) for storing solutions
Initialize the non-dominated solutions archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dominance_comparator
|
Comparator
|
Comparator to determine dominance relationships |
DominanceComparator()
|
objective_tolerance
|
float
|
Tolerance for comparing floating-point objectives |
1e-10
|
Source code in src/jmetal/util/archive.py
add(solution)
¶
Add a solution to the archive if it's non-dominated and not duplicate.
This method efficiently handles the archive by: 1. Checking if the new solution is dominated by existing ones 2. Removing existing solutions dominated by the new one 3. Preventing addition of duplicate solutions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solution
|
S
|
Solution to add to the archive |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if solution was added, False if rejected (dominated or duplicate) |
Time Complexity: O(n) where n is the number of solutions in archive
Source code in src/jmetal/util/archive.py
add_batch(solutions)
¶
Add many solutions at once, filtering the combined set in a single pass.
add() is O(n) per call (checks the new solution against every existing
one), so adding a batch of k solutions one at a time costs O(k * n) --
the pattern SequentialEvaluationWithArchive used to follow, calling
add() once per evaluated solution even though a whole generation's worth
was available at once. This instead combines the archive's current
contents with the batch and filters the result with
moocore.is_nondominated in one C-backed call, which is much faster than
even a single Python-level add() call once the archive has more than a
handful of solutions. Only meaningful when using the default
DominanceComparator, matching add()'s own accelerated path elsewhere in
this module; a custom comparator falls back to the base class's
one-at-a-time loop, since moocore.is_nondominated only knows Pareto
dominance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solutions
|
list[S]
|
The solutions to add. |
required |
Source code in src/jmetal/util/archive.py
CrowdingDistanceArchive(maximum_size, dominance_comparator=DominanceComparator())
¶
Bases: BoundedArchive[S]
Source code in src/jmetal/util/archive.py
ArchiveWithReferencePoint(maximum_size, reference_point, comparator, density_estimator, rng=None)
¶
Bases: BoundedArchive[S]
Source code in src/jmetal/util/archive.py
Performance considerations¶
Time complexity:
DistanceBasedArchive.add(): O(n²) for >2 objectives, O(n log n) for 2 objectivesdistance_based_subset_selection(): O(n²) worst case
Space complexity: O(n) for all archive implementations.
Scalability: Efficient for typical archive sizes (< 1000 solutions).
Recommendations:
- Use
CrowdingDistanceArchivefor 2-objective problems requiring only crowding distance - Use
DistanceBasedArchivefor mixed or many-objective problems - Use
NonDominatedSolutionsArchivewhen size limits are not needed
Distance metrics¶
The distance module provides various distance metrics and calculation utilities optimized for different use cases in multi-objective optimization:
- DistanceMetric: Enumeration of available distance metrics — L2_SQUARED (squared Euclidean distance, fastest, avoids sqrt computation), LINF (L-infinity/Chebyshev distance, efficient for high dimensions), TCHEBY_WEIGHTED (weighted Chebyshev distance, supports preferences)
- DistanceCalculator: High-performance static utility class for distance calculations
- EuclideanDistance: Enhanced Euclidean distance with input validation for lists and arrays
- CosineDistance: Cosine distance with reference point translation
Usage example:
import numpy as np
from jmetal.util.distance import DistanceCalculator, DistanceMetric
point1 = np.array([0.1, 0.5, 0.8])
point2 = np.array([0.3, 0.2, 0.9])
# L2 squared distance (fastest)
dist_l2 = DistanceCalculator.calculate_distance(
point1, point2, DistanceMetric.L2_SQUARED
)
# Chebyshev distance
dist_linf = DistanceCalculator.calculate_distance(
point1, point2, DistanceMetric.LINF
)
# Weighted Chebyshev distance
weights = np.array([0.5, 0.3, 0.2])
dist_weighted = DistanceCalculator.calculate_distance(
point1, point2, DistanceMetric.TCHEBY_WEIGHTED, weights
)
distance
¶
DistanceMetric
¶
Bases: Enum
Enumeration of available distance metrics for optimized distance calculations.
Each metric is optimized for specific use cases: - L2_SQUARED: Fastest, avoids sqrt computation for relative distance comparisons - LINF: Efficient for high-dimensional spaces, emphasizes maximum difference - TCHEBY_WEIGHTED: Flexible weighted distance allowing preference specification
DistanceCalculator
¶
High-performance distance calculator supporting multiple metrics.
This utility class provides optimized implementations for different distance metrics commonly used in multi-objective optimization. All methods are static for efficiency and support numpy array operations for vectorized performance.
calculate_distance(point1, point2, metric, weights=None)
staticmethod
¶
Calculate distance between two points using the specified metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point1
|
ndarray
|
First point as numpy array |
required |
point2
|
ndarray
|
Second point as numpy array |
required |
metric
|
DistanceMetric
|
Distance metric to use |
required |
weights
|
ndarray | None
|
Optional weights for TCHEBY_WEIGHTED metric |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Distance between points according to specified metric |
Raises:
| Type | Description |
|---|---|
ValueError
|
If metric is invalid or weights are required but not provided |
Source code in src/jmetal/util/distance.py
calculate_distance_matrix(points, metric, weights=None)
staticmethod
¶
Calculate pairwise distance matrix between all points using vectorized operations.
This is significantly faster than calculating distances individually, especially for large numbers of points. Uses optimized NumPy operations for maximum performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
2D array where each row is a point (n_points, n_dimensions) |
required |
metric
|
DistanceMetric
|
Distance metric to use |
required |
weights
|
ndarray | None
|
Optional weights for TCHEBY_WEIGHTED metric |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Symmetric distance matrix (n_points, n_points) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If metric is invalid or weights are required but not provided |
Source code in src/jmetal/util/distance.py
calculate_min_distances_vectorized(points, selected_indices, metric, weights=None)
staticmethod
¶
Calculate minimum distances from each point to the selected points using vectorized operations.
This is optimized for the subset selection process where we need to find the minimum distance from each candidate point to any already selected point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
2D array of all points (n_points, n_dimensions) |
required |
selected_indices
|
list[int]
|
List of indices of already selected points |
required |
metric
|
DistanceMetric
|
Distance metric to use |
required |
weights
|
ndarray | None
|
Optional weights for TCHEBY_WEIGHTED metric |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Array of minimum distances for each point |
Source code in src/jmetal/util/distance.py
EuclideanDistance
¶
Bases: Distance
Euclidean distance implementation with enhanced type safety and validation.
Supports both Python lists and numpy arrays as input. Provides comprehensive input validation for robust operation.
get_distance(list1, list2)
¶
Calculate the Euclidean distance between two points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
list[float] | ndarray
|
First point as list or numpy array |
required |
list2
|
list[float] | ndarray
|
Second point as list or numpy array |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Euclidean distance between the points |
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs have different dimensions or are empty |
TypeError
|
If inputs cannot be converted to numeric arrays |
Source code in src/jmetal/util/distance.py
CosineDistance(reference_point)
¶
Bases: Distance
Cosine distance implementation with reference point translation.
This class computes the cosine distance between two points after translating them relative to a reference point. The cosine distance is defined as: distance = 1 - cosine_similarity
Where cosine_similarity = (a·b) / (||a|| * ||b||)
The distance ranges from 0 (identical direction) to 2 (opposite directions).
Performance optimizations: - Cached reference point norm for efficiency - Vectorized numpy operations - Robust input validation and error handling
Initialize the cosine distance calculator with a reference point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_point
|
list[float] | ndarray
|
Point used to translate input vectors before computing distance |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If reference point is empty |
TypeError
|
If reference point is not numeric or is None |
Source code in src/jmetal/util/distance.py
get_distance(list1, list2)
¶
Calculate the cosine distance between two points relative to the reference point.
The computation follows these steps: 1. Translate both points by subtracting the reference point 2. Compute cosine similarity of the translated vectors 3. Return cosine distance = 1 - cosine_similarity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
list[float] | ndarray
|
First point as list or numpy array |
required |
list2
|
list[float] | ndarray
|
Second point as list or numpy array |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Cosine distance in range [0, 2] 0 = vectors point in same direction 1 = vectors are orthogonal 2 = vectors point in opposite directions |
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs have different dimensions than reference point or are empty |
TypeError
|
If inputs cannot be converted to numeric arrays |
Source code in src/jmetal/util/distance.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | |
get_similarity(list1, list2)
¶
Calculate the cosine similarity between two points relative to the reference point.
This is a convenience method that returns the similarity instead of distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list1
|
list[float] | ndarray
|
First point as list or numpy array |
required |
list2
|
list[float] | ndarray
|
Second point as list or numpy array |
required |
Returns:
| Type | Description |
|---|---|
float
|
Cosine similarity in range [-1, 1]: 1 means the vectors point in the same direction, |
float
|
0 means they are orthogonal, and -1 means they point in opposite directions. |
Source code in src/jmetal/util/distance.py
Comparators, rankings, and density estimators¶
comparator
¶
MultiComparator(comparator_list)
¶
Bases: Comparator
This comparator takes a list of comparators and check all of them iteratively until a value != 0 is obtained or the list becomes empty
Source code in src/jmetal/util/comparator.py
ranking
¶
FastNonDominatedRanking(comparator=DominanceComparator())
¶
Bases: Ranking[list[S]]
Class implementing the non-dominated ranking of NSGA-II proposed by Deb et al., see [Deb2002]_
Source code in src/jmetal/util/ranking.py
compute_ranking(solutions, k=None)
¶
Compute ranking of solutions.
Optimized implementation with improved performance: - Early termination when k solutions found - Efficient front construction - Minimal object allocations
:param solutions: Solution list. :param k: Number of individuals.
Source code in src/jmetal/util/ranking.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
StrengthRanking(comparator=DominanceComparator())
¶
Bases: Ranking[list[S]]
Class implementing a ranking scheme based on the strength ranking used in SPEA2.
Source code in src/jmetal/util/ranking.py
compute_ranking(solutions, k=None)
¶
Compute ranking of solutions using the provided dominance comparator.
:param solutions: Solution list. :param k: Number of individuals.
Source code in src/jmetal/util/ranking.py
density_estimator
¶
S = TypeVar('S')
module-attribute
¶
.. module:: density_estimator :platform: Unix, Windows :synopsis: Module including the implementation of density estimators.
.. moduleauthor:: Antonio J. Nebro ajnebro@uma.es
CrowdingDistanceDensityEstimator
¶
Bases: DensityEstimator[list[S]]
This class implements a DensityEstimator based on the crowding distance of algorithm NSGA-II.
compute_density_estimator(front)
¶
This function performs the computation of the crowding density estimation over the solution list.
.. note:: This method assign the distance in the inner elements of the solution list.
:param front: The list of solutions.
Source code in src/jmetal/util/density_estimator.py
KNearestNeighborDensityEstimator(k=1)
¶
Bases: DensityEstimator[list[S]]
This class implements a density estimator based on the distance to the k-th nearest solution.
Source code in src/jmetal/util/density_estimator.py
sort(solutions)
¶
Sort solutions by knn_density (highest first).
HypervolumeContributionDensityEstimator(reference_point=None)
¶
Bases: DensityEstimator[list[S]]
Density estimator based on the hypervolume contribution of each solution.
Source code in src/jmetal/util/density_estimator.py
compute_density_estimator(solutions)
¶
Computes the hypervolume contribution for each solution in the list. Stores the value in solution.attributes["hv_contribution"].
Source code in src/jmetal/util/density_estimator.py
sort(solutions)
¶
Sorts solutions by their hypervolume contribution (highest first).
get_comparator()
classmethod
¶
Returns a comparator for the "hv_contribution" attribute.
Solutions, generators, and constraint handling¶
solution
¶
logger = logging.getLogger(__name__)
module-attribute
¶
.. module:: solutions :platform: Unix, Windows :synopsis: Utils to print solutions.
.. moduleauthor:: Antonio J. Nebro ajnebro@uma.es, Antonio BenÃtez-Hidalgo antonio.b@uma.es
get_non_dominated_solutions(solutions)
¶
Filter a list of solutions down to its non-dominated subset.
Delegates to moocore.is_nondominated for efficiency: the previous
implementation added solutions one at a time to a NonDominatedSolutionsArchive,
which is O(n) per insertion (O(n^2) overall) -- noticeably slow for the
thousands of solutions an unbounded external archive can accumulate.
moocore.is_nondominated filters the whole batch at once and already treats
solutions with identical objectives as duplicates, keeping only the first
occurrence -- the same behavior NonDominatedSolutionsArchive had.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solutions
|
list[Solution]
|
The solutions to filter. |
required |
Returns:
| Type | Description |
|---|---|
list[Solution]
|
The non-dominated subset, in their original relative order. |
Source code in src/jmetal/util/solution.py
read_solutions(filename)
¶
Reads a reference front from a file.
:param filename: File path where the front is located.
Source code in src/jmetal/util/solution.py
generator
¶
R = TypeVar('R')
module-attribute
¶
.. module:: generator :platform: Unix, Windows :synopsis: Population generators implementation.
.. moduleauthor:: Antonio BenÃtez-Hidalgo antonio.b@uma.es
constraint_handling
¶
is_feasible(solution)
¶
Returns a boolean value concerning the feasibility of a solution :param solution: :return: true if the solution is feasible; false otherwise
Source code in src/jmetal/util/constraint_handling.py
number_of_violated_constraints(solution)
¶
Returns the number of violated constraints of a solution :param solution: :return:
overall_constraint_violation_degree(solution)
¶
Returns the constraint violation degree of a solution, which is the sum of the constraint values that are not zero :param solution: :return:
Source code in src/jmetal/util/constraint_handling.py
feasibility_ratio(solutions)
¶
Returns the percentage of feasible solutions in a solution list :param solutions: :return:
Source code in src/jmetal/util/constraint_handling.py
Aggregation and neighborhoods (MOEA/D)¶
aggregation_function
¶
neighborhood
¶
WeightVectorNeighborhood(number_of_weight_vectors, neighborhood_size, weight_vector_size=2, weights_path=None)
¶
Bases: WeightNeighborhood
Source code in src/jmetal/util/neighborhood.py
TwoDimensionalMesh(rows, columns, neighborhood)
¶
Bases: Neighborhood
Class defining a bi-mensional mesh.
Source code in src/jmetal/util/neighborhood.py
C9(rows, columns)
¶
Bases: TwoDimensionalMesh
Class defining an C9 neighborhood of a solution belonging to a list of solutions which is structured as a bi-dimensional mesh. The neighbors are those solutions that are in 1-hop distance
Shape
- o *
Topology
north = {-1, 0} south = { 1 , 0} east = { 0 , 1} west = { 0 ,-1} north_east = {-1, 1} north_west = {-1, -1} south_east = { 1 , 1} south_west = { 1 ,-1}
Source code in src/jmetal/util/neighborhood.py
L5(rows, columns)
¶
Bases: TwoDimensionalMesh
L5 neighborhood. Shape: * * o * *
Topology
north = -1, 0 south = 1, 0 east = 0, 1 west = 0, -1
Source code in src/jmetal/util/neighborhood.py
Normalization, points, and checks¶
normalization
¶
Normalization utilities for Pareto fronts.
This module provides functions to normalize Pareto fronts before applying quality indicators. Normalization is essential to avoid bias from objectives with different scales.
normalize_fronts(front, reference_front, method='reference_only')
¶
Normalize both solution front and reference front to the same scale.
This ensures that quality indicators are not biased by objectives with different scales. Typically normalizes to [0,1] for each objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
front
|
ndarray
|
Solution front matrix (each row is a solution, each column an objective). |
required |
reference_front
|
ndarray
|
Reference front matrix (each row is a solution, each column an objective). |
required |
method
|
NormalizationMethod
|
Normalization method. Options: - "minmax": Normalize to [0,1] using global min/max across both fronts - "zscore": Standardize using global mean and standard deviation - "reference_only": Normalize using only reference front bounds (recommended, default) |
'reference_only'
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
Tuple of (normalized_front, normalized_reference_front) where both matrices are normalized. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fronts have different number of objectives or invalid method. |
Examples:
>>> front = np.array([[1.0, 100.0], [2.0, 200.0], [3.0, 150.0]])
>>> reference_front = np.array([[0.5, 80.0], [1.5, 120.0], [2.5, 180.0]])
>>> norm_front, norm_ref = normalize_fronts(front, reference_front)
>>> # Uses reference_only by default
>>> # Using different methods
>>> norm_front, norm_ref = normalize_fronts(front, reference_front, method="minmax")
Note
For quality indicators, "reference_only" is typically recommended as it uses the reference front to define the normalization bounds, which is more appropriate for performance assessment.
Source code in src/jmetal/util/normalization.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
normalize_front(front, bounds_min, bounds_max)
¶
Normalize a front using predefined bounds for each objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
front
|
ndarray
|
Front matrix to normalize (each row is a solution, each column an objective). |
required |
bounds_min
|
ndarray
|
Minimum values for each objective. |
required |
bounds_max
|
ndarray
|
Maximum values for each objective. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized front matrix. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If dimensions don't match. |
Examples:
>>> front = np.array([[1.0, 100.0], [2.0, 200.0]])
>>> min_bounds = np.array([0.0, 50.0])
>>> max_bounds = np.array([5.0, 250.0])
>>> normalized = normalize_front(front, min_bounds, max_bounds)
Source code in src/jmetal/util/normalization.py
solutions_to_matrix(solutions)
¶
Convert a list of jMetal Solution objects to a numpy matrix of objectives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solutions
|
list[Solution]
|
List of Solution objects. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Matrix where each row is a solution and each column is an objective. |
Examples:
>>> # Assuming solutions is a list of Solution objects
>>> matrix = solutions_to_matrix(solutions)
>>> normalized_matrix, _ = normalize_fronts(matrix, reference_matrix)
Source code in src/jmetal/util/normalization.py
normalize_solution_fronts(solutions, reference_solutions, method='reference_only')
¶
Normalize fronts from jMetal Solution objects.
Convenience function that converts Solution objects to matrices and normalizes them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solutions
|
list[Solution]
|
List of solution objects. |
required |
reference_solutions
|
list[Solution]
|
List of reference solution objects. |
required |
method
|
NormalizationMethod
|
Normalization method. |
'reference_only'
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
Tuple of (normalized_front, normalized_reference_front) as numpy arrays. |
Examples:
>>> # Assuming solutions and reference_solutions are lists of Solution objects
>>> norm_front, norm_ref = normalize_solution_fronts(solutions, reference_solutions)
>>> # Can now be used with quality indicators
Source code in src/jmetal/util/normalization.py
get_ideal_and_nadir_points(front)
¶
Get ideal and nadir points from a front.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
front
|
ndarray
|
Front matrix (each row is a solution, each column an objective). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of (ideal_point, nadir_point) where: |
ndarray
|
|
tuple[ndarray, ndarray]
|
|
Examples:
>>> front = np.array([[1.0, 3.0], [2.0, 2.0], [3.0, 1.0]])
>>> ideal, nadir = get_ideal_and_nadir_points(front)
>>> # ideal = [1.0, 1.0], nadir = [3.0, 3.0]
Source code in src/jmetal/util/normalization.py
normalize_to_unit_hypercube(front, ideal_point=None, nadir_point=None)
¶
Normalize a front to the unit hypercube [0,1]^m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
front
|
ndarray
|
Front matrix to normalize. |
required |
ideal_point
|
ndarray
|
Ideal point (minimum values). If None, computed from front. |
None
|
nadir_point
|
ndarray
|
Nadir point (maximum values). If None, computed from front. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized front in [0,1]^m. |
Examples:
>>> front = np.array([[1.0, 3.0], [2.0, 2.0], [3.0, 1.0]])
>>> normalized = normalize_to_unit_hypercube(front)
>>> # All values will be in [0,1]
Source code in src/jmetal/util/normalization.py
point
¶
ckecking
¶
Observable¶
observable
¶
LOGGER = logging.getLogger('jmetal')
module-attribute
¶
.. module:: observable :platform: Unix, Windows :synopsis: Implementation of observable entities (using delegation) .. moduleauthor:: Antonio J. Nebro antonio@lcc.uma.es
Standalone plotting¶
A separate, CLI/benchmark-oriented plotting utility from jmetal.lab.visualization (see
Front visualization): reads a CSV of objective values and writes
a static PNG plus an optional interactive Plotly HTML file.
plotting
¶
save_plt_to_file(solutions, filename, out_dir='results', html_plotly=False)
¶
Save a visualization of a solution front to a PNG file.
Parameters
- solutions: iterable of solutions (objects with .objectives) or an array-like numeric front
- filename: base filename (no extension) used to build output names
- out_dir: directory where PNG/HTML will be written
- html_plotly: if True and Plotly is available, write an interactive HTML parallel-coordinates page for multi-objective fronts
Returns the path to the generated PNG file.
Source code in src/jmetal/util/plotting.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |