Skip to content

Commit

Permalink
fix: Update cmaes.py (#55)
Browse files Browse the repository at this point in the history
Make the `center_init` argument of CMAES accept `Solution` instances
  • Loading branch information
engintoklu committed Jan 17, 2023
1 parent 1212be3 commit 5d4bb1e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/evotorch/algorithms/cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5d4bb1e

Please sign in to comment.