Skip to content

Restart criteria list updates #50

Description

@Dvermetten

For the new restart criteria, the object which stores this list is not intuitive to manipulate, as replacing an item or appending do not work. Example:

import modcma.c_maes as modcma
import ioh

class MyCriterion(modcma.restart.Criterion):
    def __init__(self):
        super().__init__("MyCriterionName")
   
    def on_reset(self, par: modcma.Parameters):
        """Called when a restart happens (also at the start)"""
   
    def update(self, par: modcma.Parameters):
        """Called after each iteration, needs to modify self.met"""
        self.met = True

if __name__ == "__main__":
    modcma.utils.set_seed(1)
    mods = modcma.parameters.Modules()
    mods.restart_strategy = modcma.options.RestartStrategy.RESTART
    mods.matrix_adaptation = modcma.options.MatrixAdaptationType.COVARIANCE
   
    problem = ioh.get_problem(1, 1, 2)
    settings = modcma.Settings(
        dim=problem.meta_data.n_variables,
        modules=mods,
        lb=problem.bounds.lb,
        ub=problem.bounds.ub,
        budget=1000,
        verbose=True
    )
    cma = modcma.ModularCMAES(settings)
   
   
    cma.p.criteria.items = cma.p.criteria.items[1:2] # Works
    cma.p.criteria.items[1] = MyCriterion() # Doesn't work
    cma.p.criteria.items.append(MyCriterion()) #Doesn't work

    print(cma.p.criteria.items)

    while not cma.break_conditions():
        cma.mutate(problem)
        cma.select()
        cma.recombine()
        cma.adapt()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions