@@ -19,25 +19,25 @@ class MetaCluster:
19
19
20
20
Parameters
21
21
----------
22
- list_optimizer: list, default = None
22
+ list_optimizer: list, tuple, default = None
23
23
List of strings that represent class optimizer or list of instance of Optimizer class from Mealpy library.
24
24
Current supported optimizers, please check it here: https://github.com/thieu1995/mealpy
25
25
If a custom optimizer is passed, make sure it is an instance of `Optimizer` class.
26
26
Please use this to get supported optimizers: MetaCluster.get_support(name="optimizer")
27
27
28
- list_paras: list, default=None
28
+ list_paras: list, tuple, default=None
29
29
List of dictionaries that present the parameters of each Optimizer class.
30
30
You can set it to None to use all of default parameters in Mealpy library.
31
31
32
- list_obj : list, default=None
32
+ list_obj: list, tuple , default=None
33
33
List of strings that represent objective name.
34
34
Current supported objectives, please check it here: https://github.com/thieu1995/permetrics
35
35
Please use this to get supported objectives: MetaCluster.get_support(name="obj")
36
36
37
- n_trials : int, default=5
37
+ n_trials: int, default=5
38
38
The number of runs for each optimizer for each objective
39
39
40
- seed : int, default=20
40
+ seed: int, default=20
41
41
Determines random number generation for the whole program. Use an int to make the randomness deterministic.
42
42
43
43
Examples
@@ -76,7 +76,7 @@ class MetaCluster:
76
76
"all_mean" : "get_clusters_all_mean" , "all_majority" : "get_clusters_all_majority" },
77
77
"obj" : cluster .get_all_clustering_metrics (),
78
78
"metrics" : cluster .get_all_clustering_metrics (),
79
- "optimizer" : list (mu .get_all_optimizers ().keys ())
79
+ "optimizer" : list (mu .get_all_optimizers (verbose = False ).keys ())
80
80
}
81
81
82
82
FILENAME_LABELS = "result_labels"
@@ -87,8 +87,9 @@ class MetaCluster:
87
87
HYPHEN_SYMBOL = "="
88
88
89
89
def __init__ (self , list_optimizer = None , list_paras = None , list_obj = None , n_trials = 5 , seed = 20 ):
90
- self .list_optimizer , self .list_paras = self ._set_list_optimizer (list_optimizer , list_paras )
91
- self .list_obj = self ._set_list_function (list_obj , name = "objectives" )
90
+ self .list_optimizer = list_optimizer
91
+ self .list_paras = list_paras
92
+ self .list_obj = list_obj
92
93
self .n_trials = n_trials
93
94
self .seed = seed
94
95
@@ -118,7 +119,7 @@ def _set_list_function(self, list_obj=None, name="objectives"):
118
119
list_obj0 .append (obj )
119
120
if len (list_obj0 ) > 0 :
120
121
print (f"MetaCluster doesn't support { name } : { list_obj0 } " )
121
- return list_obj1
122
+ self . list_obj = list_obj1
122
123
123
124
def _set_list_optimizer (self , list_optimizer = None , list_paras = None ):
124
125
if type (list_optimizer ) not in (list , tuple ):
@@ -131,18 +132,21 @@ def _set_list_optimizer(self, list_optimizer=None, list_paras=None):
131
132
list_opts = []
132
133
for idx , opt in enumerate (list_optimizer ):
133
134
if type (opt ) is str :
134
- opt_class = mu .get_optimizer_by_name (opt )
135
+ opt_class = mu .get_optimizer_by_class (opt )
135
136
if type (list_paras [idx ]) is dict :
136
137
list_opts .append (opt_class (** list_paras [idx ]))
137
138
else :
138
- list_opts .append (opt_class (epoch = 100 , pop_size = 30 ))
139
+ list_opts .append (opt_class (epoch = 250 , pop_size = 20 ))
139
140
elif isinstance (opt , mu .Optimizer ):
140
141
if type (list_paras [idx ]) is dict :
142
+ if "name" in list_paras [idx ]: # Check if key exists and remove it
143
+ opt .name = list_paras [idx ].pop ("name" )
141
144
opt .set_parameters (list_paras [idx ])
142
145
list_opts .append (opt )
143
146
else :
144
147
raise TypeError (f"optimizer needs to set as a string and supported by Mealpy library." )
145
- return list_opts , list_paras
148
+ self .list_optimizer = list_opts
149
+ self .list_paras = list_paras
146
150
147
151
def __run__ (self , optimizer , problem , mode = "single" , n_workers = 2 , termination = None ):
148
152
optimizer .solve (problem , mode = mode , n_workers = n_workers , termination = termination , seed = self .seed )
@@ -194,6 +198,10 @@ def execute(self, data=None, cluster_finder="elbow", list_metric=None, save_path
194
198
termination : dict or None, default = None
195
199
The termination dictionary or an instance of Termination class. It is for Optimizer belongs to Mealpy library.
196
200
"""
201
+ ## Set up optimizer and objectives
202
+ self ._set_list_optimizer (self .list_optimizer , self .list_paras )
203
+ self ._set_list_function (self .list_obj , name = "objectives" )
204
+
197
205
if data .y is not None :
198
206
n_clusters = len (np .unique (data .y ))
199
207
else :
0 commit comments