pypop icon indicating copy to clipboard operation
pypop copied to clipboard

How to get candidate solutions from each iteration?

Open BruthYU opened this issue 3 years ago • 3 comments

Thanks for the excellent work :partying_face:

  1. I'm looking for black-box optimization algorithms to perform prompt tuning on my neural network, which requires candidate solutions from each iteration.
  2. Following the “ask-tell” form of pycma, the pseudo-code is shown as below:
while not es.stop():
    solutions = es.ask()
    fitness = [cma.ff.rosen(s) for s in solutions]
    es.tell(solutions, fitness)
  1. Question: How can I obtain the solutions from each iteration to calculate new fitness (e.g. loss functions)?

BruthYU avatar Oct 25 '22 02:10 BruthYU

Thanks for your interest. Currently this libaray does not return the solution from each iteration by default. We only return the solution value for saving memory. For large-scale black-box optimization, typically returning the solutions from each iteration is memory-expensive ().

However, it is possible to do this via slightly modifying the code. Here is a related example: https://github.com/Evolutionary-Intelligence/pypop/blob/main/pypop7/optimizers/es/_repeat_fmaes.py#L74

In fact, you only need to add a variable to record it (I think this is a very simple coding task since all the optimizer class are OOP).

If you still have questions, you can write a simple demo. And I can help to add them. Thanks for your interest again.

I find myself in the same situation. My fitness function is costly and its computation needs to be distributed. The ask/tell interface of pycma makes it easy to do so, but I cannot see an easy way to achieve the same with pypop. Overriding method iterate might work but not without deep changes to my code base. I understand the philosophy behind the current design choices. However, providing a ask/tell interface compatible with pycma's would encourage pycma users to swap it out for pypop. Seeing that this is one of the very best BBO libraries around, it would surely attract users. What do you think?

twoletters avatar Feb 01 '23 00:02 twoletters