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.
Files changed (84) hide show
  1. pymachdm/ANN_weights/1.Weld_Beam_MachineDM.joblib +0 -0
  2. pymachdm/ANN_weights/10.DTLZ7_MachineDM.joblib +0 -0
  3. pymachdm/ANN_weights/11.DTLZ7_MachineDM.joblib +0 -0
  4. pymachdm/ANN_weights/12.MW8_MachineDM.joblib +0 -0
  5. pymachdm/ANN_weights/13.MW8_MachineDM.joblib +0 -0
  6. pymachdm/ANN_weights/14.WAVY_3Obj_MachineDM.joblib +0 -0
  7. pymachdm/ANN_weights/15.FLOW_3Obj_MachineDM.joblib +0 -0
  8. pymachdm/ANN_weights/16.DPF4_MachineDM.joblib +0 -0
  9. pymachdm/ANN_weights/17.DPF4_MachineDM.joblib +0 -0
  10. pymachdm/ANN_weights/18.River_MachineDM.joblib +0 -0
  11. pymachdm/ANN_weights/19.River_MachineDM.joblib +0 -0
  12. pymachdm/ANN_weights/2.OSY_2Obj_MachineDM.joblib +0 -0
  13. pymachdm/ANN_weights/20.C2DTLZ2_MachineDM.joblib +0 -0
  14. pymachdm/ANN_weights/21.C2DTLZ2_MachineDM.joblib +0 -0
  15. pymachdm/ANN_weights/22.Knee_5Obj_MachineDM.joblib +0 -0
  16. pymachdm/ANN_weights/23.WATER_MachineDM.joblib +0 -0
  17. pymachdm/ANN_weights/24.WATER_MachineDM.joblib +0 -0
  18. pymachdm/ANN_weights/25.Clutch_MachineDM.joblib +0 -0
  19. pymachdm/ANN_weights/26.Clutch_MachineDM.joblib +0 -0
  20. pymachdm/ANN_weights/27.NIMBUS_MachineDM.joblib +0 -0
  21. pymachdm/ANN_weights/28.NIMBUS_MachineDM.joblib +0 -0
  22. pymachdm/ANN_weights/29.DTLZ2_8Obj_MachineDM.joblib +0 -0
  23. pymachdm/ANN_weights/3.ZDT2_2Obj_MachineDM.joblib +0 -0
  24. pymachdm/ANN_weights/30.GAA_10Obj_MachineDM.joblib +0 -0
  25. pymachdm/ANN_weights/4.Crash_MachineDM.joblib +0 -0
  26. pymachdm/ANN_weights/4.ZDT3_2Obj_MachineDM.joblib +0 -0
  27. pymachdm/ANN_weights/4a.ZDT3_2Obj_MachineDM.joblib +0 -0
  28. pymachdm/ANN_weights/5.WAVY_2Obj_MachineDM.joblib +0 -0
  29. pymachdm/ANN_weights/6.WAVY_2Obj_MachineDM.joblib +0 -0
  30. pymachdm/ANN_weights/7.Carside_MachineDM.joblib +0 -0
  31. pymachdm/ANN_weights/8.Carside_MachineDM.joblib +0 -0
  32. pymachdm/ANN_weights/9.FLOWER_3Obj_MachineDM.joblib +0 -0
  33. pymachdm/__init__.py +71 -0
  34. pymachdm/ann/__init__.py +16 -0
  35. pymachdm/ann/multioutput_class.py +115 -0
  36. pymachdm/ann/multioutput_reg.py +110 -0
  37. pymachdm/imcdm_methods/__init__.py +25 -0
  38. pymachdm/imcdm_methods/guess_start.py +46 -0
  39. pymachdm/imcdm_methods/guess_sub.py +49 -0
  40. pymachdm/imcdm_methods/mod_guess_start.py +47 -0
  41. pymachdm/imcdm_methods/mod_guess_sub.py +47 -0
  42. pymachdm/imcdm_methods/nimbus_inter.py +64 -0
  43. pymachdm/imcdm_methods/nimbus_start.py +48 -0
  44. pymachdm/imcdm_methods/nimbus_sub.py +56 -0
  45. pymachdm/imcdm_methods/stem_start.py +47 -0
  46. pymachdm/imcdm_methods/stem_sub.py +51 -0
  47. pymachdm/imcdm_methods/stom_start.py +46 -0
  48. pymachdm/imcdm_methods/stom_sub.py +47 -0
  49. pymachdm/machdm_imcdm/__init__.py +4 -0
  50. pymachdm/machdm_imcdm/machdm_all.py +771 -0
  51. pymachdm/machdm_imcdm/machine_dm.py +124 -0
  52. pymachdm/pareto/__init__.py +3 -0
  53. pymachdm/pareto/pareto_analyser.py +162 -0
  54. pymachdm/plots/__init__.py +7 -0
  55. pymachdm/plots/plot_2d_scatter.py +57 -0
  56. pymachdm/plots/plot_3d_scatter.py +91 -0
  57. pymachdm/plots/plot_pcp.py +93 -0
  58. pymachdm/plots/plot_radviz.py +496 -0
  59. pymachdm/plots/plot_tsne.py +369 -0
  60. pymachdm/problems/__init__.py +4 -0
  61. pymachdm/problems/problem_factory.py +879 -0
  62. pymachdm/problems/symbolic_problem_factory.py +696 -0
  63. pymachdm/run_machdm.py +232 -0
  64. pymachdm/soo_aasf/__init__.py +7 -0
  65. pymachdm/soo_aasf/guess_asf.py +99 -0
  66. pymachdm/soo_aasf/mod_guess_asf.py +112 -0
  67. pymachdm/soo_aasf/nimbus_asf.py +104 -0
  68. pymachdm/soo_aasf/stem_asf.py +99 -0
  69. pymachdm/soo_aasf/stom_asf.py +81 -0
  70. pymachdm/utils/__init__.py +21 -0
  71. pymachdm/utils/auto_tradeoff_stom.py +34 -0
  72. pymachdm/utils/compute_lambda.py +71 -0
  73. pymachdm/utils/compute_lambda_with_g.py +85 -0
  74. pymachdm/utils/cos_sim.py +8 -0
  75. pymachdm/utils/generate_ref_dirs.py +6 -0
  76. pymachdm/utils/predict_best.py +45 -0
  77. pymachdm/utils/predict_best2.py +62 -0
  78. pymachdm/utils/predict_prob.py +67 -0
  79. pymachdm/utils/predict_rank.py +47 -0
  80. pymachdm-0.1.0.dist-info/LICENSE +21 -0
  81. pymachdm-0.1.0.dist-info/METADATA +223 -0
  82. pymachdm-0.1.0.dist-info/RECORD +84 -0
  83. pymachdm-0.1.0.dist-info/WHEEL +5 -0
  84. pymachdm-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,496 @@
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import string
4
+
5
+
6
+ # ============================================================
7
+ # 1. Generate alphabetical labels
8
+ # ============================================================
9
+
10
+ def get_labels(n):
11
+ """
12
+ Generate labels:
13
+ A, B, C, ..., Z, AA, AB, ...
14
+ """
15
+ labels = []
16
+
17
+ for i in range(n):
18
+ label = ""
19
+ num = i
20
+
21
+ while True:
22
+ label = string.ascii_uppercase[num % 26] + label
23
+ num = num // 26 - 1
24
+
25
+ if num < 0:
26
+ break
27
+
28
+ labels.append(label)
29
+
30
+ return labels
31
+
32
+
33
+ # ============================================================
34
+ # 2. Main RadViz function
35
+ # ============================================================
36
+
37
+ def make_radviz_iter(
38
+ pf,
39
+ idx,
40
+ STEM_Start_F,
41
+ STEM_iter_F,
42
+ NIM_F=None,
43
+ figsize=(9, 9),
44
+ STEM_inter_F=None,
45
+ c=None
46
+ ):
47
+ """
48
+ RadViz visualization for interactive MCDM iterations.
49
+
50
+ Parameters
51
+ ----------
52
+ pf : ndarray
53
+ Pareto front (n_solutions, n_objectives).
54
+
55
+ idx : int
56
+ Index of final preferred solution in pf.
57
+
58
+ STEM_Start_F : ndarray
59
+ Starting solution (n_objectives,).
60
+
61
+ STEM_iter_F : ndarray
62
+ Alternate solutions (n_iterations, n_objectives).
63
+
64
+ NIM_F : ndarray, optional
65
+ Retained for compatibility.
66
+
67
+ figsize : tuple
68
+ Figure size.
69
+
70
+ STEM_inter_F : ndarray, optional
71
+ Intermediate solutions.
72
+
73
+ c : float or ndarray, optional
74
+ Controls annotation positions.
75
+
76
+ Scalar:
77
+ Same coefficient for every label.
78
+
79
+ 1D array:
80
+ One coefficient per label.
81
+
82
+ 2D array:
83
+ One coefficient per label and objective.
84
+
85
+ Annotation offset in objective space:
86
+ offset_i = c_i * (nadir_point - ideal_point)
87
+
88
+ Returns
89
+ -------
90
+ fig, ax
91
+ """
92
+
93
+ # ========================================================
94
+ # 3. Convert inputs
95
+ # ========================================================
96
+
97
+ pf = np.asarray(pf, dtype=float)
98
+
99
+ STEM_Start_F = np.asarray(
100
+ STEM_Start_F, dtype=float
101
+ ).reshape(1, -1)
102
+
103
+ STEM_iter_F = np.asarray(
104
+ STEM_iter_F, dtype=float
105
+ ).reshape(-1, pf.shape[1])
106
+
107
+ if STEM_inter_F is not None:
108
+ STEM_inter_F = np.asarray(
109
+ STEM_inter_F, dtype=float
110
+ ).reshape(-1, pf.shape[1])
111
+
112
+ n_obj = pf.shape[1]
113
+
114
+ if not 0 <= idx < len(pf):
115
+ raise IndexError("idx must be a valid index of pf.")
116
+
117
+ if STEM_Start_F.shape[1] != n_obj:
118
+ raise ValueError("Starting solution has incorrect objective dimension.")
119
+
120
+ if STEM_iter_F.shape[1] != n_obj:
121
+ raise ValueError("Alternate solutions have incorrect objective dimension.")
122
+
123
+ if STEM_inter_F is not None and STEM_inter_F.shape[1] != n_obj:
124
+ raise ValueError("Intermediate solutions have incorrect objective dimension.")
125
+
126
+ # ========================================================
127
+ # 4. Common normalization
128
+ # ========================================================
129
+
130
+ datasets = [
131
+ pf,
132
+ STEM_Start_F,
133
+ STEM_iter_F
134
+ ]
135
+
136
+ if STEM_inter_F is not None:
137
+ datasets.append(STEM_inter_F)
138
+
139
+ data = np.vstack(datasets)
140
+
141
+ ideal_point = data.min(axis=0)
142
+ nadir_point = data.max(axis=0)
143
+
144
+ data_range = nadir_point - ideal_point
145
+
146
+ safe_range = data_range.copy()
147
+ safe_range[safe_range == 0] = 1.0
148
+
149
+ def normalize(X):
150
+ return (
151
+ np.asarray(X, dtype=float) - ideal_point
152
+ ) / safe_range
153
+
154
+ pf_norm = normalize(pf)
155
+ start_norm = normalize(STEM_Start_F)
156
+ iter_norm = normalize(STEM_iter_F)
157
+
158
+ if STEM_inter_F is not None:
159
+ inter_norm = normalize(STEM_inter_F)
160
+
161
+ target_norm = pf_norm[idx]
162
+
163
+ # ========================================================
164
+ # 5. RadViz projection
165
+ # ========================================================
166
+
167
+ angles = np.linspace(
168
+ 0, 2 * np.pi, n_obj, endpoint=False
169
+ )
170
+
171
+ anchors = np.column_stack([
172
+ np.cos(angles),
173
+ np.sin(angles)
174
+ ])
175
+
176
+ def radviz_transform(X):
177
+ """
178
+ Standard RadViz projection.
179
+ """
180
+
181
+ X = np.asarray(X, dtype=float)
182
+
183
+ denominator = X.sum(axis=1, keepdims=True)
184
+
185
+ denominator[denominator == 0] = 1e-12
186
+
187
+ return (X @ anchors) / denominator
188
+
189
+ pf_2d = radviz_transform(pf_norm)
190
+
191
+ start_2d = radviz_transform(start_norm)
192
+
193
+ iter_2d = radviz_transform(iter_norm)
194
+
195
+ target_2d = radviz_transform(
196
+ target_norm.reshape(1, -1)
197
+ )
198
+
199
+ if STEM_inter_F is not None:
200
+ inter_2d = radviz_transform(inter_norm)
201
+
202
+ # ========================================================
203
+ # 6. Construct solution sequence
204
+ # ========================================================
205
+
206
+ # Sequence:
207
+ # A = Start
208
+ # B, C, D, ... = Alternate solutions
209
+ # Next labels = Intermediate solutions
210
+ # Last label = Final preferred solution
211
+
212
+ all_points_2d = [
213
+ start_2d[0],
214
+ *list(iter_2d)
215
+ ]
216
+
217
+ annotation_points_norm = [
218
+ start_norm[0],
219
+ *list(iter_norm)
220
+ ]
221
+
222
+ if STEM_inter_F is not None:
223
+
224
+ all_points_2d.extend(list(inter_2d))
225
+
226
+ annotation_points_norm.extend(list(inter_norm))
227
+
228
+ # Final preferred solution
229
+ all_points_2d.append(target_2d[0])
230
+
231
+ annotation_points_norm.append(target_norm)
232
+
233
+ n_labels = len(all_points_2d)
234
+
235
+ all_labels = get_labels(n_labels)
236
+
237
+ # ========================================================
238
+ # 7. Annotation position coefficients
239
+ # ========================================================
240
+
241
+ if c is None:
242
+
243
+ c = np.full(n_labels, 0.05)
244
+
245
+ c = np.asarray(c, dtype=float)
246
+
247
+ if c.ndim == 0:
248
+
249
+ c = np.full(n_labels, float(c))
250
+
251
+ if c.shape == (n_labels,):
252
+
253
+ offsets = c[:, None] * data_range[None, :]
254
+
255
+ elif c.shape == (n_labels, n_obj):
256
+
257
+ offsets = c * data_range[None, :]
258
+
259
+ else:
260
+
261
+ raise ValueError(
262
+ f"c must be scalar, ({n_labels},), "
263
+ f"or ({n_labels}, {n_obj})."
264
+ )
265
+
266
+ def annotation_position(point_norm, offset):
267
+
268
+ shifted_objectives = (
269
+ point_norm + offset / safe_range
270
+ )
271
+
272
+ return radviz_transform(
273
+ shifted_objectives.reshape(1, -1)
274
+ )[0]
275
+
276
+ # ========================================================
277
+ # 8. Create figure
278
+ # ========================================================
279
+
280
+ fig, ax = plt.subplots(figsize=figsize)
281
+
282
+ # ========================================================
283
+ # 9. RadViz unit circle
284
+ # ========================================================
285
+
286
+ circle = plt.Circle(
287
+ (0, 0),
288
+ 1,
289
+ fill=False,
290
+ color="black",
291
+ linewidth=1.0,
292
+ alpha=0.5
293
+ )
294
+
295
+ ax.add_patch(circle)
296
+
297
+ # ========================================================
298
+ # 10. Objective anchors
299
+ # ========================================================
300
+
301
+ for j in range(n_obj):
302
+
303
+ ax.plot(
304
+ [0, anchors[j, 0]],
305
+ [0, anchors[j, 1]],
306
+ color="gray",
307
+ linewidth=0.7,
308
+ alpha=0.4
309
+ )
310
+
311
+ ax.scatter(
312
+ anchors[j, 0],
313
+ anchors[j, 1],
314
+ color="black",
315
+ s=30,
316
+ zorder=5
317
+ )
318
+
319
+ ax.text(
320
+ 1.10 * anchors[j, 0],
321
+ 1.10 * anchors[j, 1],
322
+ fr"$f_{{{j+1}}}$",
323
+ fontsize=11,
324
+ ha="center",
325
+ va="center"
326
+ )
327
+
328
+ # ========================================================
329
+ # 11. Pareto front
330
+ # ========================================================
331
+
332
+ ax.scatter(
333
+ pf_2d[:, 0],
334
+ pf_2d[:, 1],
335
+ color="gray",
336
+ alpha=0.15,
337
+ s=12,
338
+ linewidths=0,
339
+ label="Pareto Front",
340
+ zorder=2
341
+ )
342
+
343
+ # ========================================================
344
+ # 12. Starting solution
345
+ # ========================================================
346
+
347
+ ax.scatter(
348
+ start_2d[:, 0],
349
+ start_2d[:, 1],
350
+ color="black",
351
+ marker="s",
352
+ s=90,
353
+ edgecolors="black",
354
+ linewidths=1.0,
355
+ label="Start Point",
356
+ zorder=7
357
+ )
358
+
359
+ # ========================================================
360
+ # 13. Alternate solutions
361
+ # ========================================================
362
+
363
+ ax.scatter(
364
+ iter_2d[:, 0],
365
+ iter_2d[:, 1],
366
+ color="green",
367
+ marker="o",
368
+ s=65,
369
+ edgecolors="black",
370
+ linewidths=0.5,
371
+ label="Alter. Solns.",
372
+ zorder=6
373
+ )
374
+
375
+ # ========================================================
376
+ # 14. Intermediate solutions
377
+ # ========================================================
378
+
379
+ if STEM_inter_F is not None:
380
+
381
+ ax.scatter(
382
+ inter_2d[:, 0],
383
+ inter_2d[:, 1],
384
+ color="magenta",
385
+ marker="D",
386
+ s=75,
387
+ edgecolors="black",
388
+ linewidths=0.5,
389
+ label="Inter. Solns.",
390
+ zorder=8
391
+ )
392
+
393
+ # ========================================================
394
+ # 15. Final preferred solution
395
+ # ========================================================
396
+
397
+ ax.scatter(
398
+ target_2d[:, 0],
399
+ target_2d[:, 1],
400
+ color="red",
401
+ marker="*",
402
+ s=100,
403
+ edgecolors="black",
404
+ linewidths=0.8,
405
+ label="Pref. Soln.",
406
+ zorder=10
407
+ )
408
+
409
+ # ========================================================
410
+ # 16. Alphabetical annotations: A, B, C, ...
411
+ # ========================================================
412
+
413
+ for i, (point_norm, label) in enumerate(
414
+ zip(annotation_points_norm, all_labels)
415
+ ):
416
+
417
+ annotation_xy = annotation_position(
418
+ point_norm,
419
+ offsets[i]
420
+ )
421
+
422
+ ax.annotate(
423
+ label,
424
+ xy=all_points_2d[i],
425
+ xytext=annotation_xy,
426
+ textcoords="data",
427
+ fontsize=10,
428
+ fontweight="normal",
429
+ color="blue",
430
+ ha="center",
431
+ va="center",
432
+ zorder=11
433
+ )
434
+
435
+
436
+ # ========================================================
437
+ # 17. Serial arrows (exclude final target)
438
+ # ========================================================
439
+
440
+ # Exclude the last point (red preferred solution) as an arrow destination.
441
+ for i in range(len(all_points_2d) - 2):
442
+
443
+ x1, y1 = all_points_2d[i]
444
+ x2, y2 = all_points_2d[i + 1]
445
+
446
+ ax.annotate(
447
+ "",
448
+ xy=(x2, y2),
449
+ xytext=(x1, y1),
450
+ arrowprops=dict(
451
+ arrowstyle="->",
452
+ color="black",
453
+ linewidth=0.5,
454
+ mutation_scale=12,
455
+ shrinkA=0,
456
+ shrinkB=0
457
+ ),
458
+ zorder=9
459
+ )
460
+
461
+ # ========================================================
462
+ # 18. Formatting
463
+ # ========================================================
464
+
465
+ ax.set_aspect("equal", adjustable="box")
466
+
467
+ ax.set_xlim(-1.25, 1.25)
468
+ ax.set_ylim(-1.25, 1.25)
469
+
470
+ ax.set_xlabel(
471
+ "$d_1$",
472
+ fontsize=11
473
+ )
474
+
475
+ ax.set_ylabel(
476
+ "$d_2$",
477
+ fontsize=11
478
+ )
479
+
480
+ # ax.set_title(
481
+ # "RadViz: Interactive MCDM Iterations",
482
+ # fontsize=13
483
+ # )
484
+
485
+ ax.grid(alpha=0.2)
486
+
487
+ ax.legend(
488
+ loc="upper right",
489
+ frameon=True,
490
+ fontsize=10
491
+ )
492
+
493
+ plt.tight_layout()
494
+ plt.show()
495
+
496
+ return fig, ax