Platypus
Platypus copied to clipboard
Store extra solution information along with optimization results?
Hello,
I am just getting started with platypus, switching to python from MATLAB, and everything is working well so far. I am wondering if there is a way to store additional information for each solution that I could use later for post processing? Right now the function to be optimized returns the result along with any constraints, what would really help is if I could also pass along another variable, a dictionary say, that would live with each solution. Then when I am post processing the Pareto front I would not have to reevaluate all the non-dominated solutions to get this extra information.
Thanks,
Hi
Would be easy to have this in you objective function. Just write/append to a file all the data and variables.
I use this so I can use Xdat to make parallel plots.
Not that it couldn't be part of Platypus, just saying until then you can do it yourself.
I have been using this archive class for that purpose. Switch platypus.Archive for any other Archive that you need, and then call the algorithm with archive = LoggingArchive(any_args_here)
class LoggingArchive(platypus.Archive):
def __init__(self, *args, **kwargs):
super().__init__(*args, *kwargs)
self.log = []
def add(self, solution):
super().add(solution)
self.log.append(solution)
Then use algorithm.archive.log
to retrieve the list of solutions.
Can you please show snippets how to use the procedure in an optimization model (for a python and platypus newbie)?
from platypus import NSGAII, Problem, Real, Archive
# We can subclass other kinds of Archive instead if needed.
class LoggingArchive(Archive):
def __init__(self, *args, **kwargs):
super().__init__(*args, *kwargs)
self.log = []
def add(self, solution):
super().add(solution)
self.log.append(solution)
log_archive = LoggingArchive()
# copy the example from the platypus README
def schaffer(x):
return [x[0]**2, (x[0]-2)**2]
problem = Problem(1, 2)
problem.types[:] = Real(-10, 10)
problem.function = schaffer
# here we tell the optimizer to use the archive we chose.
algorithm = NSGAII(problem, archive = log_archive)
algorithm.run(10)
print(log_archive.log[:5]) # print the first 5 solutions in the log
from platypus import NSGAII, Problem, Real, Archive # We can subclass other kinds of Archive instead if needed. class LoggingArchive(Archive): def __init__(self, *args, **kwargs): super().__init__(*args, *kwargs) self.log = [] def add(self, solution): super().add(solution) self.log.append(solution) log_archive = LoggingArchive() # copy the example from the platypus README def schaffer(x): return [x[0]**2, (x[0]-2)**2] problem = Problem(1, 2) problem.types[:] = Real(-10, 10) problem.function = schaffer # here we tell the optimizer to use the archive we chose. algorithm = NSGAII(problem, archive = log_archive) algorithm.run(10) print(log_archive.log[:5]) # print the first 5 solutions in the log
Thanks, but there is another question. I want to save the records from EpsNSGAII. Could you show me how to do that?
Has anyone found a way to use this data to create an unbounded archive? So that it is guaranteed that platypus keeps the best results from the previous iteration into the next iteration.
I am doing a 3 objective optimisation at the moment, but currently the hypervolume does not improve greatly over 50,000 iterations. I thought maybe an unbound archive might help with the huge search space? Please let me know if anyone has any tips.
This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.