Skip to content

Commit 5d4bb1e

Browse files
authored
fix: Update cmaes.py (#55)
Make the `center_init` argument of CMAES accept `Solution` instances
1 parent 1212be3 commit 5d4bb1e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/evotorch/algorithms/cmaes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import numpy as np
2424
import torch
2525

26-
from ..core import Problem, SolutionBatch
26+
from ..core import Problem, Solution, SolutionBatch
2727
from ..tools.misc import Real, Vector
2828
from .searchalgorithm import SearchAlgorithm, SinglePopulationAlgorithmMixin
2929

@@ -231,10 +231,14 @@ def __init__(
231231

232232
# If `center_init` is not given, generate an initial solution
233233
# with the help of the problem object.
234+
# If it is given as a Solution, then clone the solution's values
235+
# as a PyTorch tensor.
234236
# Otherwise, use the given initial solution as the starting
235237
# point in the search space.
236238
if center_init is None:
237239
center_init = self._problem.generate_values(1)
240+
elif isinstance(center_init, Solution):
241+
center_init = center_init.values.clone()
238242

239243
# Store the center
240244
self.m = self._problem.make_tensor(center_init)

0 commit comments

Comments
 (0)