Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
light-weaver committed Sep 25, 2023
1 parent 51b698d commit 7fc311f
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 146 deletions.
3 changes: 2 additions & 1 deletion desdeo_tools/interaction/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ def response(self, value: pd.DataFrame):


class PreferredSolutionPreference(BaseRequest):
"""Methods can use this class to ask the Decision maker to provide their preferences in form of preferred solution(s).
"""Methods can use this class to ask the Decision maker to provide their preferences

Check failure on line 388 in desdeo_tools/interaction/request.py

View workflow job for this annotation

GitHub Actions / Flake8

desdeo_tools/interaction/request.py#L388

Trailing whitespace (W291)
in form of preferred solution(s).
"""

def __init__(
Expand Down
3 changes: 2 additions & 1 deletion desdeo_tools/scalarization/MOEADSF.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class PBI(MOEADSFBase):
theta (float): A penalty parameter used by the function
.. Q. Zhang and H. Li, "MOEA/D: A Multiobjective Evolutionary Algorithm Based on Decomposition,"
in IEEE Transactions on Evolutionary Computation, vol. 11, no. 6, pp. 712-731, Dec. 2007, doi: 10.1109/TEVC.2007.892759.
in IEEE Transactions on Evolutionary Computation, vol. 11, no. 6, pp. 712-731, Dec. 2007,
doi: 10.1109/TEVC.2007.892759.
"""

def __init__(self, theta: float = 5):
Expand Down
17 changes: 5 additions & 12 deletions desdeo_tools/solver/ScalarSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class ScalarSolverException(Exception):


class ScalarMethod:
"""A class the define and implement methods for minimizing scalar valued functions.
"""
"""A class the define and implement methods for minimizing scalar valued functions."""

def __init__(
self, method: Callable, method_args=None, use_scipy: Optional[bool] = False
Expand Down Expand Up @@ -93,16 +92,15 @@ def __call__(
class MixedIntegerMinimizer:

"""Implements methods for solving scalar valued functions.
Args:
scalarized_objective (Callable): The objective function that has been scalarized
scalarized_objective (Callable): The objective function that has been scalarized
and ready for minimization.
problem (MOProblem): A MOProblem instance required to get variable types.
minlp_solver_path (str): The path to the bonmin solver.
"""

def __init__(self, scalarized_objective: Callable, problem, minlp_solver_path: str):

# Try importing rbfopt
try:
global rbfopt
Expand Down Expand Up @@ -271,9 +269,7 @@ def __init__(
self._bounds[:, 1] -= 1e-6

def get_presets(self):
"""Return the list of preset minimizers available.
"""
"""Return the list of preset minimizers available."""
return self.get_presets

def minimize(self, x0: np.ndarray) -> Dict:
Expand Down Expand Up @@ -314,8 +310,7 @@ def minimize(self, x0: np.ndarray) -> Dict:


class DiscreteMinimizer:
"""Implements a class for finding the minimum value of a discrete of scalarized vectors.
"""
"""Implements a class for finding the minimum value of a discrete of scalarized vectors."""

def __init__(
self,
Expand Down Expand Up @@ -374,8 +369,6 @@ def minimize(self, vectors: np.ndarray) -> dict:


if __name__ == "__main__":
from desdeo_tools.scalarization.ASF import PointMethodASF

ideal = np.array([0, 0, 0, 0])
nadir = np.array([1, 1, 1, 1])

Expand Down
18 changes: 9 additions & 9 deletions desdeo_tools/utilities/quality_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@njit()
def epsilon_indicator(s1: np.ndarray, s2: np.ndarray) -> float:
""" Computes the additive epsilon-indicator between two solutions.
"""Computes the additive epsilon-indicator between two solutions.
Args:
s1 (np.ndarray): Solution 1. Should be an one-dimensional array.
Expand All @@ -27,7 +27,7 @@ def epsilon_indicator(s1: np.ndarray, s2: np.ndarray) -> float:

@njit()
def epsilon_indicator_ndims(front: np.ndarray, reference_point: np.ndarray) -> list:
""" Computes the additive epsilon-indicator between reference point and current one-dimensional vector of front.
"""Computes the additive epsilon-indicator between reference point and current one-dimensional vector of front.
Args:
front (np.ndarray): The front that the current reference point is being compared to.
Expand All @@ -53,19 +53,19 @@ def preference_indicator(
ref_point: np.ndarray,
delta: float,
) -> float:
""" Computes the preference-based quality indicator.
"""Computes the preference-based quality indicator.
Args:
s1 (np.ndarray): Solution 1. Should be an one-dimensional array.
s2 (np.ndarray): Solution 2. Should be an one-dimensional array.
ref_point (np.ndarray): The reference point should be same shape as front.
min_asf_value (float): Minimum value of achievement scalarization of the reference_front. Used in normalization.
delta (float): The spesifity delta allows to set the amplification of the indicator to be closer or farther
delta (float): The spesifity delta allows to set the amplification of the indicator to be closer or farther
from the reference point. Smaller delta means that all solutions are in smaller range around the reference
point.
Returns:
float: The maximum distance between the values in s1 and s2 taking into account
float: The maximum distance between the values in s1 and s2 taking into account
the reference point and spesifity.
"""
s2_asf = SimpleASF(np.ones_like(s2))
Expand All @@ -74,12 +74,13 @@ def preference_indicator(


def hypervolume_indicator(front: np.ndarray, reference_point: np.ndarray) -> float:
""" Computes the hypervolume-indicator between reference front and current approximating point.
"""Computes the hypervolume-indicator between reference front and current approximating point.
Args:
front (np.ndarray): The front that is compared. Should be set of arrays, where the rows are the solutions and
front (np.ndarray): The front that is compared. Should be set of arrays, where the rows are the solutions and
the columns are the objective dimensions.
reference_point (np.ndarray): The reference point that the current front is being compared to. Should be 1D array.
reference_point (np.ndarray): The reference point that the current front is being compared to.
Should be 1D array.
Returns:
float: Measures the volume of the objective space dominated by an approximation set.
Expand All @@ -92,7 +93,6 @@ def hypervolume_indicator(front: np.ndarray, reference_point: np.ndarray) -> flo


if __name__ == "__main__":

po_front = np.asarray([[1.0, 0], [0.5, 0.5], [0, 1.0], [2, -1], [0, 0]])
sol1 = [4, 4] # cant be better than po front, min is zero
sol = np.asarray(sol1)
Expand Down
5 changes: 4 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7fc311f

Please sign in to comment.