From 5d4bb1e568145b974126f0e6672ded95e3f3d160 Mon Sep 17 00:00:00 2001 From: Nihat Engin Toklu Date: Tue, 17 Jan 2023 15:08:29 +0100 Subject: [PATCH] fix: Update cmaes.py (#55) Make the `center_init` argument of CMAES accept `Solution` instances --- src/evotorch/algorithms/cmaes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/evotorch/algorithms/cmaes.py b/src/evotorch/algorithms/cmaes.py index dbef4a16..ccce5994 100644 --- a/src/evotorch/algorithms/cmaes.py +++ b/src/evotorch/algorithms/cmaes.py @@ -23,7 +23,7 @@ import numpy as np import torch -from ..core import Problem, SolutionBatch +from ..core import Problem, Solution, SolutionBatch from ..tools.misc import Real, Vector from .searchalgorithm import SearchAlgorithm, SinglePopulationAlgorithmMixin @@ -231,10 +231,14 @@ def __init__( # If `center_init` is not given, generate an initial solution # with the help of the problem object. + # If it is given as a Solution, then clone the solution's values + # as a PyTorch tensor. # Otherwise, use the given initial solution as the starting # point in the search space. if center_init is None: center_init = self._problem.generate_values(1) + elif isinstance(center_init, Solution): + center_init = center_init.values.clone() # Store the center self.m = self._problem.make_tensor(center_init)