Skip to content

Commit

Permalink
Add docs for indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 11, 2024
1 parent 3e1e54e commit af25eb7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/api/platypus.indicators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ platypus.indicators module

.. automodule:: platypus.indicators
:members:
:undoc-members:
6 changes: 4 additions & 2 deletions platypus/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,13 @@ def __call__(self, value):
class Solution:
"""Class representing a solution to a problem.
Attributes
Parameters
----------
problem: Problem
The problem.
Attributes
----------
variables: FixedLengthArray of objects
The values of the variables.
objectives: FixedLengthArray of float
Expand All @@ -566,7 +569,6 @@ class Solution:
"""

def __init__(self, problem):
"""Creates a new solution for the given problem."""
super().__init__()
self.problem = problem
self.variables = FixedLengthArray(problem.nvars)
Expand Down
37 changes: 37 additions & 0 deletions platypus/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@


class GenerationalDistance(Indicator):
"""Generational distance (GD) performance indicator.
Parameters
----------
reference_set : iterable of Solution
The reference set used for normalization.
d : float, default=2.0
The power used when computing the distance.
"""

def __init__(self, reference_set, d=2.0):
super().__init__()
Expand All @@ -41,6 +50,15 @@ def calculate(self, set):
return math.pow(sum([math.pow(distance_to_nearest(s, self.reference_set), self.d) for s in feasible]), 1.0 / self.d) / len(feasible)

class InvertedGenerationalDistance(Indicator):
"""Inverged generational distance (IGD) performance indicator.
Parameters
----------
reference_set : iterable of Solution
The reference set used for normalization.
d : float, default=1.0
The power used when computing the distance.
"""

def __init__(self, reference_set, d=1.0):
super().__init__()
Expand All @@ -54,6 +72,13 @@ def calculate(self, set):
return math.pow(sum([math.pow(distance_to_nearest(s, feasible), self.d) for s in self.reference_set]), 1.0 / self.d) / len(self.reference_set)

class EpsilonIndicator(Indicator):
"""Additive epsilon-indicator (AEI) performance indicator.
Parameters
----------
reference_set : iterable of Solution
The reference set used for normalization.
"""

def __init__(self, reference_set):
super().__init__()
Expand All @@ -70,6 +95,7 @@ def calculate(self, set):
return max([min([max([s2.normalized_objectives[k] - s1.normalized_objectives[k] for k in range(s2.problem.nobjs)]) for s2 in feasible]) for s1 in self.reference_set])

class Spacing(Indicator):
"""Spacing performance indicator."""

def __init__(self):
super().__init__()
Expand All @@ -88,6 +114,17 @@ def calculate(self, set):
return math.sqrt(sum([math.pow(d - avg_distance, 2.0) for d in distances]) / (len(feasible)-1))

class Hypervolume(Indicator):
"""Hypervolume performance indicator.
Parameters
----------
reference_set : iterable of Solution, optional
The reference set used for normalization.
minimum : list of float, optional
The minimum bounds for normalization.
maximum : list of float, optional
The maximum bounds for normalization.
"""

def __init__(self, reference_set=None, minimum=None, maximum=None):
if reference_set is not None:
Expand Down

0 comments on commit af25eb7

Please sign in to comment.