iwopy 0.1.5__py3-none-any.whl → 0.1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of iwopy might be problematic. Click here for more details.
- iwopy/VERSION +1 -1
- iwopy/benchmarks/branin.py +1 -1
- iwopy/core/optimizer.py +9 -3
- iwopy/core/problem.py +66 -6
- iwopy/interfaces/__init__.py +1 -0
- iwopy/interfaces/pygmo/algos.py +24 -24
- iwopy/interfaces/pygmo/imports.py +21 -20
- iwopy/interfaces/pygmo/optimizer.py +5 -5
- iwopy/interfaces/pymoo/__init__.py +1 -1
- iwopy/interfaces/pymoo/factory.py +19 -35
- iwopy/interfaces/pymoo/imports.py +75 -22
- iwopy/interfaces/pymoo/optimizer.py +41 -34
- iwopy/interfaces/pymoo/problem.py +336 -285
- iwopy/interfaces/scipy/__init__.py +1 -0
- iwopy/interfaces/scipy/optimizer.py +232 -0
- iwopy/utils/__init__.py +1 -0
- iwopy/utils/load.py +31 -0
- iwopy/wrappers/discretize_reg_grid.py +66 -18
- {iwopy-0.1.5.dist-info → iwopy-0.1.8.dist-info}/METADATA +6 -3
- {iwopy-0.1.5.dist-info → iwopy-0.1.8.dist-info}/RECORD +24 -21
- {iwopy-0.1.5.dist-info → iwopy-0.1.8.dist-info}/WHEEL +1 -1
- {iwopy-0.1.5.dist-info → iwopy-0.1.8.dist-info}/LICENSE +0 -0
- {iwopy-0.1.5.dist-info → iwopy-0.1.8.dist-info}/top_level.txt +0 -0
- {iwopy-0.1.5.dist-info → iwopy-0.1.8.dist-info}/zip-safe +0 -0
|
@@ -2,36 +2,39 @@ import numpy as np
|
|
|
2
2
|
import matplotlib.pyplot as plt
|
|
3
3
|
|
|
4
4
|
from iwopy.core import Optimizer
|
|
5
|
-
from .problem import
|
|
6
|
-
from .imports import IMPORT_OK, check_import, Callback
|
|
5
|
+
from .problem import get_single_obj_class, get_multi_obj_class
|
|
7
6
|
from .factory import Factory
|
|
7
|
+
from . import imports
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
self.data["f_best"]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
self.data["f_best"]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
self.data["cv_best"]
|
|
34
|
-
|
|
9
|
+
|
|
10
|
+
def get_default_callback_class(verbosity=1):
|
|
11
|
+
|
|
12
|
+
imports.load(verbosity)
|
|
13
|
+
|
|
14
|
+
class DefaultCallback(imports.Callback):
|
|
15
|
+
def __init__(self):
|
|
16
|
+
super().__init__()
|
|
17
|
+
self.data["f_best"] = None
|
|
18
|
+
self.data["cv_best"] = None
|
|
19
|
+
|
|
20
|
+
def notify(self, algorithm):
|
|
21
|
+
fvals = algorithm.pop.get("F")
|
|
22
|
+
cvals = algorithm.pop.get("CV")
|
|
23
|
+
n_obj = fvals.shape[1]
|
|
24
|
+
n_con = cvals.shape[1]
|
|
25
|
+
i = np.argmin(fvals, axis=0)
|
|
26
|
+
if self.data["f_best"] is None:
|
|
27
|
+
self.data["f_best"] = fvals[None, i, range(n_obj)]
|
|
28
|
+
self.data["cv_best"] = cvals[None, i, range(n_con)]
|
|
29
|
+
else:
|
|
30
|
+
self.data["f_best"] = np.append(
|
|
31
|
+
self.data["f_best"], fvals[None, i, range(n_obj)], axis=0
|
|
32
|
+
)
|
|
33
|
+
self.data["cv_best"] = np.append(
|
|
34
|
+
self.data["cv_best"], cvals[None, i, range(n_con)], axis=0
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return DefaultCallback
|
|
35
38
|
|
|
36
39
|
|
|
37
40
|
class Optimizer_pymoo(Optimizer):
|
|
@@ -69,8 +72,6 @@ class Optimizer_pymoo(Optimizer):
|
|
|
69
72
|
def __init__(self, problem, problem_pars, algo_pars, setup_pars={}, term_pars={}):
|
|
70
73
|
super().__init__(problem)
|
|
71
74
|
|
|
72
|
-
check_import()
|
|
73
|
-
|
|
74
75
|
self.problem_pars = problem_pars
|
|
75
76
|
self.algo_pars = algo_pars
|
|
76
77
|
self.setup_pars = setup_pars
|
|
@@ -128,9 +129,13 @@ class Optimizer_pymoo(Optimizer):
|
|
|
128
129
|
|
|
129
130
|
"""
|
|
130
131
|
if self.problem.n_objectives <= 1:
|
|
131
|
-
self.pymoo_problem =
|
|
132
|
+
self.pymoo_problem = get_single_obj_class(verbosity)(
|
|
133
|
+
self.problem, **self.problem_pars
|
|
134
|
+
)
|
|
132
135
|
else:
|
|
133
|
-
self.pymoo_problem =
|
|
136
|
+
self.pymoo_problem = get_multi_obj_class(verbosity)(
|
|
137
|
+
self.problem, **self.problem_pars
|
|
138
|
+
)
|
|
134
139
|
|
|
135
140
|
if verbosity:
|
|
136
141
|
print("Initializing", type(self).__name__)
|
|
@@ -141,7 +146,7 @@ class Optimizer_pymoo(Optimizer):
|
|
|
141
146
|
|
|
142
147
|
super().initialize(verbosity)
|
|
143
148
|
|
|
144
|
-
def solve(self, callback=
|
|
149
|
+
def solve(self, callback="default", verbosity=1):
|
|
145
150
|
"""
|
|
146
151
|
Run the optimization solver.
|
|
147
152
|
|
|
@@ -158,13 +163,15 @@ class Optimizer_pymoo(Optimizer):
|
|
|
158
163
|
The optimization results object
|
|
159
164
|
|
|
160
165
|
"""
|
|
166
|
+
if callback == "default":
|
|
167
|
+
callback = get_default_callback_class(verbosity)()
|
|
161
168
|
|
|
162
169
|
# check problem initialization:
|
|
163
170
|
super().solve()
|
|
164
171
|
|
|
165
172
|
# run pymoo solver:
|
|
166
173
|
self.callback = callback
|
|
167
|
-
self.results = minimize(
|
|
174
|
+
self.results = imports.minimize(
|
|
168
175
|
self.pymoo_problem,
|
|
169
176
|
algorithm=self.algo,
|
|
170
177
|
termination=self.term,
|