pyMachDM 0.1.0__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.
- pymachdm/ANN_weights/1.Weld_Beam_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/10.DTLZ7_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/11.DTLZ7_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/12.MW8_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/13.MW8_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/14.WAVY_3Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/15.FLOW_3Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/16.DPF4_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/17.DPF4_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/18.River_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/19.River_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/2.OSY_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/20.C2DTLZ2_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/21.C2DTLZ2_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/22.Knee_5Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/23.WATER_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/24.WATER_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/25.Clutch_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/26.Clutch_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/27.NIMBUS_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/28.NIMBUS_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/29.DTLZ2_8Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/3.ZDT2_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/30.GAA_10Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/4.Crash_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/4.ZDT3_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/4a.ZDT3_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/5.WAVY_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/6.WAVY_2Obj_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/7.Carside_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/8.Carside_MachineDM.joblib +0 -0
- pymachdm/ANN_weights/9.FLOWER_3Obj_MachineDM.joblib +0 -0
- pymachdm/__init__.py +71 -0
- pymachdm/ann/__init__.py +16 -0
- pymachdm/ann/multioutput_class.py +115 -0
- pymachdm/ann/multioutput_reg.py +110 -0
- pymachdm/imcdm_methods/__init__.py +25 -0
- pymachdm/imcdm_methods/guess_start.py +46 -0
- pymachdm/imcdm_methods/guess_sub.py +49 -0
- pymachdm/imcdm_methods/mod_guess_start.py +47 -0
- pymachdm/imcdm_methods/mod_guess_sub.py +47 -0
- pymachdm/imcdm_methods/nimbus_inter.py +64 -0
- pymachdm/imcdm_methods/nimbus_start.py +48 -0
- pymachdm/imcdm_methods/nimbus_sub.py +56 -0
- pymachdm/imcdm_methods/stem_start.py +47 -0
- pymachdm/imcdm_methods/stem_sub.py +51 -0
- pymachdm/imcdm_methods/stom_start.py +46 -0
- pymachdm/imcdm_methods/stom_sub.py +47 -0
- pymachdm/machdm_imcdm/__init__.py +4 -0
- pymachdm/machdm_imcdm/machdm_all.py +771 -0
- pymachdm/machdm_imcdm/machine_dm.py +124 -0
- pymachdm/pareto/__init__.py +3 -0
- pymachdm/pareto/pareto_analyser.py +162 -0
- pymachdm/plots/__init__.py +7 -0
- pymachdm/plots/plot_2d_scatter.py +57 -0
- pymachdm/plots/plot_3d_scatter.py +91 -0
- pymachdm/plots/plot_pcp.py +93 -0
- pymachdm/plots/plot_radviz.py +496 -0
- pymachdm/plots/plot_tsne.py +369 -0
- pymachdm/problems/__init__.py +4 -0
- pymachdm/problems/problem_factory.py +879 -0
- pymachdm/problems/symbolic_problem_factory.py +696 -0
- pymachdm/run_machdm.py +232 -0
- pymachdm/soo_aasf/__init__.py +7 -0
- pymachdm/soo_aasf/guess_asf.py +99 -0
- pymachdm/soo_aasf/mod_guess_asf.py +112 -0
- pymachdm/soo_aasf/nimbus_asf.py +104 -0
- pymachdm/soo_aasf/stem_asf.py +99 -0
- pymachdm/soo_aasf/stom_asf.py +81 -0
- pymachdm/utils/__init__.py +21 -0
- pymachdm/utils/auto_tradeoff_stom.py +34 -0
- pymachdm/utils/compute_lambda.py +71 -0
- pymachdm/utils/compute_lambda_with_g.py +85 -0
- pymachdm/utils/cos_sim.py +8 -0
- pymachdm/utils/generate_ref_dirs.py +6 -0
- pymachdm/utils/predict_best.py +45 -0
- pymachdm/utils/predict_best2.py +62 -0
- pymachdm/utils/predict_prob.py +67 -0
- pymachdm/utils/predict_rank.py +47 -0
- pymachdm-0.1.0.dist-info/LICENSE +21 -0
- pymachdm-0.1.0.dist-info/METADATA +223 -0
- pymachdm-0.1.0.dist-info/RECORD +84 -0
- pymachdm-0.1.0.dist-info/WHEEL +5 -0
- pymachdm-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
|
|
2
|
+
from sklearn.manifold import TSNE
|
|
3
|
+
import numpy as np
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def make_tsne_iter(
|
|
8
|
+
pf,
|
|
9
|
+
idx,
|
|
10
|
+
STEM_Start_F,
|
|
11
|
+
STEM_iter_F,
|
|
12
|
+
NIM_F=None,
|
|
13
|
+
figsize=(9, 9),
|
|
14
|
+
STEM_inter_F=None,
|
|
15
|
+
perplexity=30,
|
|
16
|
+
random_state=42,
|
|
17
|
+
learning_rate="auto",
|
|
18
|
+
n_iter=1000
|
|
19
|
+
):
|
|
20
|
+
"""
|
|
21
|
+
t-SNE visualization for interactive MCDM iterations.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
pf : ndarray
|
|
26
|
+
Pareto front (n_solutions, n_objectives).
|
|
27
|
+
|
|
28
|
+
idx : int
|
|
29
|
+
Index of final preferred solution in pf.
|
|
30
|
+
|
|
31
|
+
STEM_Start_F : ndarray
|
|
32
|
+
Starting solution (n_objectives,).
|
|
33
|
+
|
|
34
|
+
STEM_iter_F : ndarray
|
|
35
|
+
Alternate solutions (n_iterations, n_objectives).
|
|
36
|
+
|
|
37
|
+
NIM_F : ndarray, optional
|
|
38
|
+
Retained for compatibility.
|
|
39
|
+
|
|
40
|
+
figsize : tuple
|
|
41
|
+
Figure size.
|
|
42
|
+
|
|
43
|
+
STEM_inter_F : ndarray, optional
|
|
44
|
+
Intermediate solutions.
|
|
45
|
+
|
|
46
|
+
perplexity : float
|
|
47
|
+
t-SNE perplexity. Automatically reduced if necessary
|
|
48
|
+
to ensure perplexity < number of samples.
|
|
49
|
+
|
|
50
|
+
random_state : int
|
|
51
|
+
Random seed for reproducibility.
|
|
52
|
+
|
|
53
|
+
learning_rate : float or "auto"
|
|
54
|
+
t-SNE learning rate.
|
|
55
|
+
|
|
56
|
+
n_iter : int
|
|
57
|
+
Number of optimization iterations.
|
|
58
|
+
|
|
59
|
+
Returns
|
|
60
|
+
-------
|
|
61
|
+
fig, ax
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
# ========================================================
|
|
65
|
+
# 1. Convert inputs
|
|
66
|
+
# ========================================================
|
|
67
|
+
|
|
68
|
+
pf = np.asarray(pf, dtype=float)
|
|
69
|
+
|
|
70
|
+
STEM_Start_F = np.asarray(
|
|
71
|
+
STEM_Start_F, dtype=float
|
|
72
|
+
).reshape(1, -1)
|
|
73
|
+
|
|
74
|
+
STEM_iter_F = np.asarray(
|
|
75
|
+
STEM_iter_F, dtype=float
|
|
76
|
+
).reshape(-1, pf.shape[1])
|
|
77
|
+
|
|
78
|
+
if STEM_inter_F is not None:
|
|
79
|
+
STEM_inter_F = np.asarray(
|
|
80
|
+
STEM_inter_F, dtype=float
|
|
81
|
+
).reshape(-1, pf.shape[1])
|
|
82
|
+
|
|
83
|
+
n_obj = pf.shape[1]
|
|
84
|
+
|
|
85
|
+
if not 0 <= idx < len(pf):
|
|
86
|
+
raise IndexError("idx must be a valid index of pf.")
|
|
87
|
+
|
|
88
|
+
if STEM_Start_F.shape[1] != n_obj:
|
|
89
|
+
raise ValueError("Starting solution has incorrect objective dimension.")
|
|
90
|
+
|
|
91
|
+
if STEM_iter_F.shape[1] != n_obj:
|
|
92
|
+
raise ValueError("Alternate solutions have incorrect objective dimension.")
|
|
93
|
+
|
|
94
|
+
if STEM_inter_F is not None and STEM_inter_F.shape[1] != n_obj:
|
|
95
|
+
raise ValueError("Intermediate solutions have incorrect objective dimension.")
|
|
96
|
+
|
|
97
|
+
# ========================================================
|
|
98
|
+
# 2. Common normalization
|
|
99
|
+
# ========================================================
|
|
100
|
+
|
|
101
|
+
datasets = [
|
|
102
|
+
pf,
|
|
103
|
+
STEM_Start_F,
|
|
104
|
+
STEM_iter_F
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
if STEM_inter_F is not None:
|
|
108
|
+
datasets.append(STEM_inter_F)
|
|
109
|
+
|
|
110
|
+
data = np.vstack(datasets)
|
|
111
|
+
|
|
112
|
+
ideal_point = data.min(axis=0)
|
|
113
|
+
nadir_point = data.max(axis=0)
|
|
114
|
+
|
|
115
|
+
data_range = nadir_point - ideal_point
|
|
116
|
+
|
|
117
|
+
safe_range = data_range.copy()
|
|
118
|
+
safe_range[safe_range == 0] = 1.0
|
|
119
|
+
|
|
120
|
+
def normalize(X):
|
|
121
|
+
return (
|
|
122
|
+
np.asarray(X, dtype=float) - ideal_point
|
|
123
|
+
) / safe_range
|
|
124
|
+
|
|
125
|
+
pf_norm = normalize(pf)
|
|
126
|
+
start_norm = normalize(STEM_Start_F)
|
|
127
|
+
iter_norm = normalize(STEM_iter_F)
|
|
128
|
+
|
|
129
|
+
if STEM_inter_F is not None:
|
|
130
|
+
inter_norm = normalize(STEM_inter_F)
|
|
131
|
+
|
|
132
|
+
target_norm = pf_norm[idx].reshape(1, -1)
|
|
133
|
+
|
|
134
|
+
# ========================================================
|
|
135
|
+
# 3. Construct complete dataset
|
|
136
|
+
# ========================================================
|
|
137
|
+
|
|
138
|
+
all_data = [
|
|
139
|
+
pf_norm,
|
|
140
|
+
start_norm,
|
|
141
|
+
iter_norm
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
if STEM_inter_F is not None:
|
|
145
|
+
all_data.append(inter_norm)
|
|
146
|
+
|
|
147
|
+
all_data.append(target_norm)
|
|
148
|
+
|
|
149
|
+
X = np.vstack(all_data)
|
|
150
|
+
|
|
151
|
+
n_samples = X.shape[0]
|
|
152
|
+
|
|
153
|
+
if n_samples < 3:
|
|
154
|
+
raise ValueError(
|
|
155
|
+
"At least three samples are required for t-SNE."
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
if not np.all(np.isfinite(X)):
|
|
159
|
+
raise ValueError("Input data contains NaN or infinite values.")
|
|
160
|
+
|
|
161
|
+
# ========================================================
|
|
162
|
+
# 4. t-SNE projection
|
|
163
|
+
# ========================================================
|
|
164
|
+
|
|
165
|
+
effective_perplexity = min(
|
|
166
|
+
float(perplexity),
|
|
167
|
+
float(n_samples - 1)
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
if effective_perplexity <= 0:
|
|
171
|
+
raise ValueError("perplexity must be positive.")
|
|
172
|
+
|
|
173
|
+
tsne = TSNE(
|
|
174
|
+
n_components=2,
|
|
175
|
+
perplexity=effective_perplexity,
|
|
176
|
+
init="pca",
|
|
177
|
+
learning_rate=learning_rate,
|
|
178
|
+
max_iter=n_iter,
|
|
179
|
+
random_state=random_state
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
X_2d = tsne.fit_transform(X)
|
|
183
|
+
|
|
184
|
+
# ========================================================
|
|
185
|
+
# 5. Extract projected solutions
|
|
186
|
+
# ========================================================
|
|
187
|
+
|
|
188
|
+
i = 0
|
|
189
|
+
|
|
190
|
+
pf_2d = X_2d[i:i + len(pf_norm)]
|
|
191
|
+
i += len(pf_norm)
|
|
192
|
+
|
|
193
|
+
start_2d = X_2d[i:i + 1]
|
|
194
|
+
i += 1
|
|
195
|
+
|
|
196
|
+
iter_2d = X_2d[i:i + len(iter_norm)]
|
|
197
|
+
i += len(iter_norm)
|
|
198
|
+
|
|
199
|
+
if STEM_inter_F is not None:
|
|
200
|
+
inter_2d = X_2d[i:i + len(inter_norm)]
|
|
201
|
+
i += len(inter_norm)
|
|
202
|
+
|
|
203
|
+
target_2d = X_2d[i:i + 1]
|
|
204
|
+
|
|
205
|
+
# ========================================================
|
|
206
|
+
# 6. Construct solution sequence
|
|
207
|
+
# ========================================================
|
|
208
|
+
|
|
209
|
+
all_points_2d = [
|
|
210
|
+
start_2d[0],
|
|
211
|
+
*list(iter_2d)
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
if STEM_inter_F is not None:
|
|
215
|
+
all_points_2d.extend(list(inter_2d))
|
|
216
|
+
|
|
217
|
+
all_points_2d.append(target_2d[0])
|
|
218
|
+
|
|
219
|
+
all_labels = get_labels(len(all_points_2d))
|
|
220
|
+
|
|
221
|
+
# ========================================================
|
|
222
|
+
# 7. Create figure
|
|
223
|
+
# ========================================================
|
|
224
|
+
|
|
225
|
+
fig, ax = plt.subplots(figsize=figsize)
|
|
226
|
+
|
|
227
|
+
# ========================================================
|
|
228
|
+
# 8. Pareto front
|
|
229
|
+
# ========================================================
|
|
230
|
+
|
|
231
|
+
ax.scatter(
|
|
232
|
+
pf_2d[:, 0],
|
|
233
|
+
pf_2d[:, 1],
|
|
234
|
+
color="gray",
|
|
235
|
+
alpha=0.20,
|
|
236
|
+
s=12,
|
|
237
|
+
linewidths=0,
|
|
238
|
+
label="Pareto Front",
|
|
239
|
+
zorder=2
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
# ========================================================
|
|
243
|
+
# 9. Starting solution
|
|
244
|
+
# ========================================================
|
|
245
|
+
|
|
246
|
+
ax.scatter(
|
|
247
|
+
start_2d[:, 0],
|
|
248
|
+
start_2d[:, 1],
|
|
249
|
+
color="black",
|
|
250
|
+
marker="s",
|
|
251
|
+
s=90,
|
|
252
|
+
edgecolors="black",
|
|
253
|
+
linewidths=1.0,
|
|
254
|
+
label="Start Point",
|
|
255
|
+
zorder=7
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# ========================================================
|
|
259
|
+
# 10. Alternate solutions
|
|
260
|
+
# ========================================================
|
|
261
|
+
|
|
262
|
+
ax.scatter(
|
|
263
|
+
iter_2d[:, 0],
|
|
264
|
+
iter_2d[:, 1],
|
|
265
|
+
color="green",
|
|
266
|
+
marker="o",
|
|
267
|
+
s=65,
|
|
268
|
+
edgecolors="black",
|
|
269
|
+
linewidths=0.5,
|
|
270
|
+
label="Alter. Solns.",
|
|
271
|
+
zorder=6
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
# ========================================================
|
|
275
|
+
# 11. Intermediate solutions
|
|
276
|
+
# ========================================================
|
|
277
|
+
|
|
278
|
+
if STEM_inter_F is not None:
|
|
279
|
+
|
|
280
|
+
ax.scatter(
|
|
281
|
+
inter_2d[:, 0],
|
|
282
|
+
inter_2d[:, 1],
|
|
283
|
+
color="magenta",
|
|
284
|
+
marker="D",
|
|
285
|
+
s=75,
|
|
286
|
+
edgecolors="black",
|
|
287
|
+
linewidths=0.5,
|
|
288
|
+
label="Inter. Solns.",
|
|
289
|
+
zorder=8
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
# ========================================================
|
|
293
|
+
# 12. Final preferred solution
|
|
294
|
+
# ========================================================
|
|
295
|
+
|
|
296
|
+
ax.scatter(
|
|
297
|
+
target_2d[:, 0],
|
|
298
|
+
target_2d[:, 1],
|
|
299
|
+
color="red",
|
|
300
|
+
marker="*",
|
|
301
|
+
s=150,
|
|
302
|
+
edgecolors="black",
|
|
303
|
+
linewidths=0.8,
|
|
304
|
+
label="Pref. Soln.",
|
|
305
|
+
zorder=10
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
# ========================================================
|
|
309
|
+
# 13. Alphabetical annotations
|
|
310
|
+
# ========================================================
|
|
311
|
+
|
|
312
|
+
for point, label in zip(all_points_2d, all_labels):
|
|
313
|
+
|
|
314
|
+
ax.annotate(
|
|
315
|
+
label,
|
|
316
|
+
xy=point,
|
|
317
|
+
xytext=(5, 5),
|
|
318
|
+
textcoords="offset points",
|
|
319
|
+
fontsize=10,
|
|
320
|
+
fontweight="normal",
|
|
321
|
+
color="blue",
|
|
322
|
+
ha="left",
|
|
323
|
+
va="bottom",
|
|
324
|
+
zorder=11
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
# ========================================================
|
|
328
|
+
# 14. Serial arrows (exclude final target)
|
|
329
|
+
# ========================================================
|
|
330
|
+
|
|
331
|
+
for i in range(len(all_points_2d) - 2):
|
|
332
|
+
|
|
333
|
+
x1, y1 = all_points_2d[i]
|
|
334
|
+
x2, y2 = all_points_2d[i + 1]
|
|
335
|
+
|
|
336
|
+
ax.annotate(
|
|
337
|
+
"",
|
|
338
|
+
xy=(x2, y2),
|
|
339
|
+
xytext=(x1, y1),
|
|
340
|
+
arrowprops=dict(
|
|
341
|
+
arrowstyle="->",
|
|
342
|
+
color="black",
|
|
343
|
+
linewidth=0.6,
|
|
344
|
+
mutation_scale=12,
|
|
345
|
+
shrinkA=3,
|
|
346
|
+
shrinkB=3
|
|
347
|
+
),
|
|
348
|
+
zorder=9
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
# ========================================================
|
|
352
|
+
# 15. Formatting
|
|
353
|
+
# ========================================================
|
|
354
|
+
|
|
355
|
+
ax.set_xlabel("t-SNE 1", fontsize=11)
|
|
356
|
+
ax.set_ylabel("t-SNE 2", fontsize=11)
|
|
357
|
+
|
|
358
|
+
ax.grid(alpha=0.2)
|
|
359
|
+
|
|
360
|
+
ax.legend(
|
|
361
|
+
loc="best",
|
|
362
|
+
frameon=True,
|
|
363
|
+
fontsize=10
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
plt.tight_layout()
|
|
367
|
+
plt.show()
|
|
368
|
+
|
|
369
|
+
return fig, ax
|