11from enum import Enum
2+ from dataclasses import dataclass
23
34from .cmaescpp import (
45 constants ,
2021
2122from .cmaescpp .parameters import Settings , Modules # pyright: ignore[reportMissingModuleSource]
2223
24+ from ConfigSpace import ConfigurationSpace , Categorical , Integer , Float , NormalIntegerHyperparameter , NormalFloatHyperparameter
25+
2326
2427def get_module_options (name : str ) -> tuple :
2528 if not hasattr (Modules , name ):
@@ -29,13 +32,13 @@ def get_module_options(name: str) -> tuple:
2932 if isinstance (default_value , bool ):
3033 return (default_value , not default_value )
3134
32- if issubclass (default_value .__class__ , Enum ):
35+ module_class = default_value .__class__
36+ if issubclass (module_class , Enum ):
3337 other_values = [
34- x for x in default_value .__members__ .items ()
38+ x for x in module_class .__members__ .values ()
3539 if x is not default_value
3640 ]
3741 return tuple ([default_value ] + other_values )
38- breakpoint ()
3942 raise TypeError (f"{ name } has a unparsable type { type (default_value )} " )
4043
4144def get_all_module_options () -> dict :
@@ -44,3 +47,41 @@ def get_all_module_options() -> dict:
4447 for name in dir (Modules )
4548 if not name .startswith ("_" )
4649 }
50+
51+ def make_numeric_parameter (name : str , dim : int , lb : float = 0 , ub : float = float ("inf" )) -> NormalIntegerHyperparameter | NormalFloatHyperparameter :
52+ settings = Parameters (Settings (dim ))
53+ default = getattr (settings .weights , name , None )
54+ print (name , default )
55+
56+
57+
58+
59+ def get_all_numeric_options (dim : int ) -> dict [str , NormalIntegerHyperparameter | NormalFloatHyperparameter ]:
60+ return {
61+ "sigma0" : make_numeric_parameter ("sigma0" , dim ),
62+ "lambda0" : make_numeric_parameter ("lambda0" , dim , 4 ),
63+ "mu0" : make_numeric_parameter ("mu0" , dim , 4 ),
64+ "cs" : make_numeric_parameter ("cs" , dim , 0 , 1.0 ),
65+ "cc" : make_numeric_parameter ("cc" , dim , 0 , 1.0 ),
66+ "cmu" : make_numeric_parameter ("cmu" , dim , 0 , 1.0 ),
67+ "c1" : make_numeric_parameter ("c1" , dim , 0 , 1.0 ),
68+ "damps" : make_numeric_parameter ("damps" , dim , 0 , 10.0 ),
69+ "acov" : make_numeric_parameter ("acov" , dim , 0 , 10.0 ),
70+ }
71+
72+ def get_configspace (dim : int = None , only_modules : bool = False ) -> ConfigurationSpace :
73+ cspace = ConfigurationSpace ()
74+ for name , options in get_all_module_options ().items ():
75+ cspace .add (Categorical (name , options , default = options [0 ]))
76+
77+ if only_modules :
78+ return cspace
79+
80+ if dim is None :
81+ print ("warning" )
82+ dim = 1
83+
84+ for name , options in get_all_numeric_options (dim ).items ():
85+ cspace .add ()
86+
87+ return cspace
0 commit comments