moospread 0.1.4__py3-none-any.whl → 0.1.5__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.
- moospread/core.py +709 -218
- moospread/tasks/bo_torch.py +24 -9
- moospread/utils/mobo_utils/learning/model_init.py +0 -4
- moospread/utils/mobo_utils/learning/utils.py +41 -17
- {moospread-0.1.4.dist-info → moospread-0.1.5.dist-info}/METADATA +2 -2
- {moospread-0.1.4.dist-info → moospread-0.1.5.dist-info}/RECORD +9 -9
- {moospread-0.1.4.dist-info → moospread-0.1.5.dist-info}/WHEEL +0 -0
- {moospread-0.1.4.dist-info → moospread-0.1.5.dist-info}/licenses/LICENSE +0 -0
- {moospread-0.1.4.dist-info → moospread-0.1.5.dist-info}/top_level.txt +0 -0
moospread/tasks/bo_torch.py
CHANGED
|
@@ -35,13 +35,17 @@ class BraninCurrin(PymooProblemTorch):
|
|
|
35
35
|
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
|
-
def __init__(self, path = None, ref_point=None, negate=
|
|
38
|
+
def __init__(self, path = None, ref_point=None, negate=False, **kwargs):
|
|
39
39
|
super().__init__(n_var=2, n_obj=2,
|
|
40
40
|
xl=torch.zeros(2, dtype=torch.float) + 1e-6,
|
|
41
41
|
xu=torch.ones(2, dtype=torch.float) - 1e-6,
|
|
42
42
|
vtype=float, **kwargs)
|
|
43
|
+
|
|
44
|
+
self.negate = negate
|
|
43
45
|
if ref_point is None:
|
|
44
46
|
self.ref_point = [18.0, 6.0]
|
|
47
|
+
if self.negate:
|
|
48
|
+
self.ref_point = [-val for val in self.ref_point]
|
|
45
49
|
else:
|
|
46
50
|
self.ref_point = ref_point
|
|
47
51
|
|
|
@@ -50,7 +54,7 @@ class BraninCurrin(PymooProblemTorch):
|
|
|
50
54
|
|
|
51
55
|
def _calc_pareto_front(self, n_pareto_points: int = 100) -> torch.Tensor:
|
|
52
56
|
if self.path is not None:
|
|
53
|
-
front = np.
|
|
57
|
+
front = np.load(self.path)
|
|
54
58
|
return torch.from_numpy(front).to(self.device)
|
|
55
59
|
else:
|
|
56
60
|
return None
|
|
@@ -85,6 +89,8 @@ class BraninCurrin(PymooProblemTorch):
|
|
|
85
89
|
branin = self._rescaled_branin(X=X)
|
|
86
90
|
currin = self._currin(X=X)
|
|
87
91
|
out["F"] = torch.stack([branin, currin], dim=-1)
|
|
92
|
+
if self.negate:
|
|
93
|
+
out["F"] = -out["F"]
|
|
88
94
|
|
|
89
95
|
class Penicillin(PymooProblemTorch):
|
|
90
96
|
r"""A penicillin production simulator from [Liang2021]_.
|
|
@@ -125,13 +131,16 @@ class Penicillin(PymooProblemTorch):
|
|
|
125
131
|
R = 1.9872 # CAL/(MOL K)
|
|
126
132
|
V_max = 180.0
|
|
127
133
|
|
|
128
|
-
def __init__(self, path = None, ref_point=None, negate=
|
|
134
|
+
def __init__(self, path = None, ref_point=None, negate=False, **kwargs):
|
|
129
135
|
super().__init__(n_var=7, n_obj=3,
|
|
130
136
|
xl=torch.tensor([60.0, 0.05, 293.0, 0.05, 0.01, 500.0, 5.0], dtype=torch.float) + 1e-6,
|
|
131
137
|
xu=torch.tensor([120.0, 18.0, 303.0, 18.0, 0.5, 700.0, 6.5], dtype=torch.float) - 1e-6,
|
|
132
138
|
vtype=float, **kwargs)
|
|
139
|
+
self.negate = negate
|
|
133
140
|
if ref_point is None:
|
|
134
141
|
self.ref_point = [25.935, 57.612, 935.5]
|
|
142
|
+
if self.negate:
|
|
143
|
+
self.ref_point = [-val for val in self.ref_point]
|
|
135
144
|
else:
|
|
136
145
|
self.ref_point = ref_point
|
|
137
146
|
|
|
@@ -140,7 +149,7 @@ class Penicillin(PymooProblemTorch):
|
|
|
140
149
|
|
|
141
150
|
def _calc_pareto_front(self, n_pareto_points: int = 100) -> torch.Tensor:
|
|
142
151
|
if self.path is not None:
|
|
143
|
-
front = np.
|
|
152
|
+
front = np.load(self.path)
|
|
144
153
|
return torch.from_numpy(front).to(self.device)
|
|
145
154
|
else:
|
|
146
155
|
return None
|
|
@@ -222,10 +231,11 @@ class Penicillin(PymooProblemTorch):
|
|
|
222
231
|
def _evaluate(self, X: torch.Tensor, out: dict, *args, **kwargs) -> None:
|
|
223
232
|
# This uses in-place operations. Hence, the clone is to avoid modifying
|
|
224
233
|
# the original X in-place.
|
|
225
|
-
out["F"] = self.penicillin_vectorized(X.view(-1, self.
|
|
226
|
-
*X.shape[:-1], self.
|
|
234
|
+
out["F"] = self.penicillin_vectorized(X.view(-1, self.n_var).clone()).view(
|
|
235
|
+
*X.shape[:-1], self.n_obj
|
|
227
236
|
)
|
|
228
|
-
|
|
237
|
+
if self.negate:
|
|
238
|
+
out["F"] = -out["F"]
|
|
229
239
|
|
|
230
240
|
class VehicleSafety(PymooProblemTorch):
|
|
231
241
|
r"""Optimize Vehicle crash-worthiness.
|
|
@@ -239,13 +249,16 @@ class VehicleSafety(PymooProblemTorch):
|
|
|
239
249
|
pareto front from [Tanabe2020]_.
|
|
240
250
|
"""
|
|
241
251
|
|
|
242
|
-
def __init__(self, path = None, ref_point=None, negate=
|
|
252
|
+
def __init__(self, path = None, ref_point=None, negate=False, **kwargs):
|
|
243
253
|
super().__init__(n_var=5, n_obj=3,
|
|
244
254
|
xl=torch.ones(5, dtype=torch.float) + 1e-6,
|
|
245
255
|
xu=3*torch.ones(5, dtype=torch.float) - 1e-6,
|
|
246
256
|
vtype=float, **kwargs)
|
|
257
|
+
self.negate = negate
|
|
247
258
|
if ref_point is None:
|
|
248
259
|
self.ref_point = [1864.72022, 11.81993945, 0.2903999384]
|
|
260
|
+
if self.negate:
|
|
261
|
+
self.ref_point = [-val for val in self.ref_point]
|
|
249
262
|
else:
|
|
250
263
|
self.ref_point = ref_point
|
|
251
264
|
|
|
@@ -254,7 +267,7 @@ class VehicleSafety(PymooProblemTorch):
|
|
|
254
267
|
|
|
255
268
|
def _calc_pareto_front(self, n_pareto_points: int = 100) -> torch.Tensor:
|
|
256
269
|
if self.path is not None:
|
|
257
|
-
front = np.
|
|
270
|
+
front = np.load(self.path)
|
|
258
271
|
return torch.from_numpy(front).to(self.device)
|
|
259
272
|
else:
|
|
260
273
|
return None
|
|
@@ -298,3 +311,5 @@ class VehicleSafety(PymooProblemTorch):
|
|
|
298
311
|
)
|
|
299
312
|
f_X = torch.cat([f1, f2, f3], dim=-1)
|
|
300
313
|
out["F"] = f_X
|
|
314
|
+
if self.negate:
|
|
315
|
+
out["F"] = -out["F"]
|
|
@@ -4,7 +4,6 @@ from moospread.utils.mobo_utils.learning.model import NeuralNet
|
|
|
4
4
|
import torch.nn as nn
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
def init_dom_nn_classifier(x, y, rel_map, dom, n_var, batch_size=32,
|
|
9
8
|
activation='relu', lr=0.001, weight_decay=0.00001):
|
|
10
9
|
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
@@ -13,10 +12,7 @@ def init_dom_nn_classifier(x, y, rel_map, dom, n_var, batch_size=32,
|
|
|
13
12
|
num_hidden_layers = 3
|
|
14
13
|
epochs = 20
|
|
15
14
|
data = prepare_dom_data(x, y, rel_map, dom, data_kind='tensor', device=device)
|
|
16
|
-
# print(f"Data shape: {data.shape}")
|
|
17
|
-
# print("data[:, -1]", data[:, -1])
|
|
18
15
|
weight = compute_class_weight(data[:, -1])
|
|
19
|
-
# print(f"Class weights: {weight}")
|
|
20
16
|
if weight is None:
|
|
21
17
|
return None
|
|
22
18
|
|
|
@@ -4,8 +4,6 @@ import numpy as np
|
|
|
4
4
|
import torch.nn as nn
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
# This file implements some Utility Functions about training
|
|
8
|
-
|
|
9
7
|
def prepare_dom_data(x, y, rel_map, dom, start=0, data_kind='tensor', device='cpu'):
|
|
10
8
|
n = len(x)
|
|
11
9
|
data = []
|
|
@@ -65,22 +63,48 @@ def load_batched_dom_data(data, batch_size):
|
|
|
65
63
|
|
|
66
64
|
|
|
67
65
|
def compute_class_weight(class_labels):
|
|
66
|
+
#################################### Original implementation (can return None too eagerly):
|
|
67
|
+
# n_examples = len(class_labels)
|
|
68
|
+
|
|
69
|
+
# class_labels = class_labels.cpu().numpy()
|
|
70
|
+
# n_zero = np.sum(class_labels == 0)
|
|
71
|
+
# n_one = np.sum(class_labels == 1)
|
|
72
|
+
# n_two = n_examples - n_zero - n_one
|
|
73
|
+
|
|
74
|
+
# if n_zero == 0 or n_one == 0 or n_two == 0:
|
|
75
|
+
# return None
|
|
76
|
+
|
|
77
|
+
# w_zero = n_examples / (3. * n_zero)
|
|
78
|
+
# w_one = n_examples / (3. * n_one)
|
|
79
|
+
# w_two = n_examples / (3. * n_two)
|
|
80
|
+
|
|
81
|
+
# return w_zero, w_one, w_two
|
|
82
|
+
|
|
83
|
+
# return w_zero, w_one, w_two
|
|
84
|
+
################################### Revised implementation:
|
|
85
|
+
eps = 1e-6
|
|
68
86
|
n_examples = len(class_labels)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
labels = class_labels.detach().cpu().numpy().astype(int)
|
|
88
|
+
n_zero = np.sum(labels == 0)
|
|
89
|
+
n_one = np.sum(labels == 1)
|
|
90
|
+
n_two = np.sum(labels == 2)
|
|
91
|
+
counts = np.array([n_zero, n_one, n_two], dtype=float)
|
|
92
|
+
weights = np.zeros(3, dtype=float)
|
|
93
|
+
# indices of present classes
|
|
94
|
+
present = counts > 0
|
|
95
|
+
missing = counts == 0
|
|
96
|
+
if missing.any():
|
|
97
|
+
# set missing class(es) to eps
|
|
98
|
+
weights[missing] = eps
|
|
99
|
+
# compute raw weights for present classes using your formula
|
|
100
|
+
raw = n_examples / (3.0 * counts[present])
|
|
101
|
+
# normalize them to sum to (1 - eps * num_missing)
|
|
102
|
+
remaining = 1.0 - eps * missing.sum()
|
|
103
|
+
weights[present] = raw / raw.sum() * remaining
|
|
104
|
+
else:
|
|
105
|
+
# standard case: all classes present
|
|
106
|
+
weights = n_examples / (3.0 * counts)
|
|
107
|
+
return tuple(weights)
|
|
84
108
|
|
|
85
109
|
def train_nn(data, data_loader, net, criterion, optimizer, batch_size, epochs):
|
|
86
110
|
#10000 12
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: moospread
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Sampling-based Pareto front Refinement via Efficient Adaptive Diffusion
|
|
5
5
|
Author-email: Sedjro Salomon Hotegni <salomon.hotegni@aims.ac.rw>
|
|
6
6
|
Maintainer-email: Sedjro Salomon Hotegni <salomon.hotegni@tu-dortmund.de>
|
|
@@ -73,7 +73,7 @@ Dynamic: license-file
|
|
|
73
73
|
<h3>
|
|
74
74
|
<a href="https://pypi.org/project/moospread/">Installation</a> |
|
|
75
75
|
<a href="https://moospread.readthedocs.io/en/latest/">Documentation</a> |
|
|
76
|
-
<a href="https://
|
|
76
|
+
<a href="https://openreview.net/forum?id=4731mIqv89">Paper</a>
|
|
77
77
|
</h3>
|
|
78
78
|
</div>
|
|
79
79
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
moospread/__init__.py,sha256=v9TLUZq0-q0j_23NB7S4ugJqogOMutUuL9MMCi4zu4I,124
|
|
2
|
-
moospread/core.py,sha256=
|
|
2
|
+
moospread/core.py,sha256=U29SSbF6RLkncfZVlgrKGOlI3aXiSjPpN-bvu9Mb5T4,117510
|
|
3
3
|
moospread/problem.py,sha256=YjT4k_K7qTZDhWzIYkaBQlsZRVnpP6iV3F8ShFhGAck,6042
|
|
4
4
|
moospread/tasks/__init__.py,sha256=RrtuZs1TyL35fDzGjlm1PnFqxXd75Qdl-q3Sdld7dsw,309
|
|
5
|
-
moospread/tasks/bo_torch.py,sha256=
|
|
5
|
+
moospread/tasks/bo_torch.py,sha256=a5g47Mckkj4Ci-VbchAl2PsNXZ6pWAiEvxMqETm8rbs,10898
|
|
6
6
|
moospread/tasks/dtlz_torch.py,sha256=dhmzUj-dbhF3zXIOgx2Z-PpuIqvxAttnEoBM0C9nUt0,5134
|
|
7
7
|
moospread/tasks/mw_torch.py,sha256=hvYGxcaCr-AFgZd_-rLcIul_a5cZrOV3dRVB5sl9Wuo,9585
|
|
8
8
|
moospread/tasks/re_torch.py,sha256=TK7i-9i7qlDZC2H4vdhcVgHybarKwJ-M27yAibAg3LI,14062
|
|
@@ -26,10 +26,10 @@ moospread/utils/mobo_utils/evolution/norm.py,sha256=V94LKVTF3ymVdEsI9rMc-4lwXh1Z
|
|
|
26
26
|
moospread/utils/mobo_utils/evolution/utils.py,sha256=bfrUxmFAnjTr6UwY-8AifLZvt2KMj_NR85neQHhwhlU,2314
|
|
27
27
|
moospread/utils/mobo_utils/learning/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
28
|
moospread/utils/mobo_utils/learning/model.py,sha256=9PS2BdBr70jOllm6snYbP2iUAbGcJWRAmX_EiQEwnYg,1372
|
|
29
|
-
moospread/utils/mobo_utils/learning/model_init.py,sha256=
|
|
29
|
+
moospread/utils/mobo_utils/learning/model_init.py,sha256=oUSljcQYhPKJMd9YT9pqDd9dLAJ31GM8GAOPjGLr73A,1156
|
|
30
30
|
moospread/utils/mobo_utils/learning/model_update.py,sha256=csx2k-7kaYbGaiNlFe_kwdaTWuErxcqjTo224ONiq_Q,1447
|
|
31
31
|
moospread/utils/mobo_utils/learning/prediction.py,sha256=eQec9R3omJNC5oKecQWxdJ2Y7fbHeK3YfodkHwrtOZ0,3173
|
|
32
|
-
moospread/utils/mobo_utils/learning/utils.py,sha256=
|
|
32
|
+
moospread/utils/mobo_utils/learning/utils.py,sha256=jCigiQVA41jsMmDek5WMCcxYTkprxIL7TSezHZPWAJ4,5041
|
|
33
33
|
moospread/utils/mobo_utils/mobo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
34
|
moospread/utils/mobo_utils/mobo/acquisition.py,sha256=83CP4TMG0A29KEgPiiR588e3FZfsPx2hVZCBqaW6c1U,7293
|
|
35
35
|
moospread/utils/mobo_utils/mobo/algorithms.py,sha256=MX1-jhYivoRHi4BAtUJsmTd5gK5nLLkQv7hpJJzWHlw,1518
|
|
@@ -57,8 +57,8 @@ moospread/utils/mobo_utils/mobo/surrogate_model/thompson_sampling.py,sha256=Nmp6
|
|
|
57
57
|
moospread/utils/offline_utils/__init__.py,sha256=MJC-fqvQnbQ0T_wjCw_QK8nKo_xpQxh0buq91fxYjFY,742
|
|
58
58
|
moospread/utils/offline_utils/handle_task.py,sha256=kgHpWotCIrmDBjs08KXyp1BuwXe5APkw3q7cu-xWlz4,8365
|
|
59
59
|
moospread/utils/offline_utils/proxies.py,sha256=DPBykB8l1XJmT5QQCAQrgMZz-8FiGEiNwN0bBdYJIaY,11218
|
|
60
|
-
moospread-0.1.
|
|
61
|
-
moospread-0.1.
|
|
62
|
-
moospread-0.1.
|
|
63
|
-
moospread-0.1.
|
|
64
|
-
moospread-0.1.
|
|
60
|
+
moospread-0.1.5.dist-info/licenses/LICENSE,sha256=YwtV5PRo6WMw5CWQMD728fSF8cWEKKfwOhek37Yi1so,1079
|
|
61
|
+
moospread-0.1.5.dist-info/METADATA,sha256=WPouMOqtqRjr7RUggiJrzqDd-uN4my3EFJq8NtoxThk,6189
|
|
62
|
+
moospread-0.1.5.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
63
|
+
moospread-0.1.5.dist-info/top_level.txt,sha256=LWi5kIahDQRNXNkx55T-gefn09Bgcq8SoCxp72S-7x0,10
|
|
64
|
+
moospread-0.1.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|