You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(This should be under the feature-request/help labels, I'm just not sure how to add them)
I have written code that changes a problem using a decorator, but I'd also like to change the problem in an instantiated population. Is there currently a way to do this? For example, given some population with an associated problem at initialisation, is there a way to update the problem to the new decorated one without creating a new population? I know this is potentially very un-pygmonic (against the way PyGMO is designed), but I think it could be useful for some upcoming projects.
E.g.
import pygmo as pg
# Define a dummy decorated problem
def f_decor(orig_fitness_function):
def new_fitness_function(self, dv):
import time
start = time.monotonic()
fitness = orig_fitness_function(self, dv)
print("Elapsed time: {} seconds".format(time.monotonic() - start))
return fitness
return new_fitness_function
# The original problem
prob = pg.problem(pg.rosenbrock(dim = 10))
# The initial population
pop = pg.population(prob, size = 20)
# The algorithm
algo = pg.algorithm(pg.sade(gen = 1000))
# Evolve the population
pop = algo.evolve(pop)
new_prob = pg.problem(pg.decorator_problem(rb, fitness_decorator=f_decor))
#<what I want to do>
pop = pop.change_problem(new_prob)
Any help is much appreciated!
The text was updated successfully, but these errors were encountered:
You cannot replace a problem in a population, as it is supposed to be an "immutable" property of the population.
What you can do is to change the internal state of a problem. E.g., if the UDP stored in a population has a data member, you can alter that data member - that does not count as "changing the problem". I am not sure whether this helps in your situation though...
I'm slightly confused by what you mean by the UDP's data member. So for example, say I have a population defined with some associated UDP, can I change attributes of the UDP between evolutions? For example, given some UDP that depends on a variable self.myvar, could I instantiate the population with the some seed in the fitness function, then update it manually after some number of evolutions (i.e. is this what you mean by changing its data members)? (Just to be clear I'm not talking about a multi-objective function here or any optimisation of self.myvar, I just want to be able to 'perturb' the problem after solving).
(This should be under the feature-request/help labels, I'm just not sure how to add them)
I have written code that changes a problem using a decorator, but I'd also like to change the problem in an instantiated population. Is there currently a way to do this? For example, given some population with an associated problem at initialisation, is there a way to update the problem to the new decorated one without creating a new population? I know this is potentially very un-pygmonic (against the way PyGMO is designed), but I think it could be useful for some upcoming projects.
E.g.
Any help is much appreciated!
The text was updated successfully, but these errors were encountered: