pymoo icon indicating copy to clipboard operation
pymoo copied to clipboard

超参数优化HyperparameterProblem

Open niurencheng opened this issue 2 years ago • 1 comments

from pymoo.algorithms.hyperparameters import SingleObjectiveSingleRun, HyperparameterProblem from pymoo.algorithms.soo.nonconvex.g3pcx import G3PCX from pymoo.algorithms.soo.nonconvex.optuna import Optuna from pymoo.core.mixed import MixedVariableGA from pymoo.core.parameters import set_params, hierarchical from pymoo.optimize import minimize from pymoo.problems.single import Sphere

algorithm = G3PCX()

problem = get_problem("g1") n_evals = 500

performance = SingleObjectiveSingleRun(problem, termination=("n_evals", n_evals), seed=1)

res = minimize(HyperparameterProblem(algorithm, performance), MixedVariableGA(pop_size=5), termination=('n_evals', 50), seed=1, verbose=False)

hyperparams = res.X print(hyperparams) set_params(algorithm, hierarchical(hyperparams))

res = minimize(Sphere(), algorithm, termination=("n_evals", n_evals), seed=1) print("Best solution found: \nX = %s\nF = %s" % (res.X, res.F))

Why does an error occur when dealing with a problem with constraints during hyperparameter optimization?

Exception: ('Problem Error: G can not be set, expected shape (5, 0) but provided (5, 9)', ValueError('cannot reshape array of size 45 into shape (5,0)'))

niurencheng avatar Feb 29 '24 10:02 niurencheng

the problem you are trying to optimize is not a mixed variable problem. (I admit the error message is misleading)

blankjul avatar Mar 16 '24 18:03 blankjul