Project-Platypus / Platypus

A Free and Open Source Python Library for Multiobjective Optimization
GNU General Public License v3.0
573 stars 152 forks source link

Question #209

Closed todaylsy closed 1 year ago

todaylsy commented 1 year ago

run(count) runtime and swarm_size conflict when I use the OMOPSO optimization algorithm. When I set the runtime to a different size swarm_size, For example, if I warm_size=10 and runtime=20, I will run it according to 20, and the number of model iterations will be performed in a single iteration according to a larger number

dakoluk commented 1 year ago

Run() takes the number of function evaluations as an argument, not the number of generations or iterations. Have you tried using max_iterations?

todaylsy commented 1 year ago

Thank you for your reply. I would like to ask if swarm_size is the population size and max_iterations is the maximum number of iterations. This test is set to Run(1). When I use the parameter max_iterations as 100,200, swarm_size=10 does not change. Only 10 times of fitness results were output. My model has several parameters. I want to set swarm_size to 100 and max_iterations to 1000. How do I set this parameter?

dhadka commented 1 year ago

You'll want to use something like:


max_iterations = 1000
swarm_size = 100

algorithm = OMOPSO(problem, epsilons=[0.01], swarm_size = swarm_size, max_iterations = max_iterations)

algorithm.run(max_iterations * swarm_size)

It's understandably confusing, but the max_iterations parameter used by OMOPSO (and SMPSO) does not affect how long the algorithm runs. Instead, max_iterations here controls the scaling for OMOPSO and SMPSO's non-uniform mutation operator. This operator makes large mutations early in the run and scales down to smaller and smaller mutations later in the run. max_iterations controls how quickly it scales down. It's not required, but we would typically set this to the total number of iterations we plan to run the algorithm.

We can confirm how long the algorithm ran in terms of the number of function evalutions (NFE) using:


print("Total Evaluations: ", algorithm.nfe)
todaylsy commented 1 year ago

When I configured the parameters you sent me, the operation was ok. Since the model I need to optimize has more than 10 parameters and the model calculation process is long, I would like to ask you for advice on how to input an initial parameter, and I hope you can give me some ways to improve the computational efficiency when using this algorithm. Thank you

dhadka commented 1 year ago

how to input an initial parameter

The algorithms take a generator input, which is typically set to RandomGenerator. You can use InjectedGenerator to inject one or more solutions into the initial population. If you need more flexibility, the Generator class can be extended to produce the initial solutions however you need.

and I hope you can give me some ways to improve the computational efficiency when using this algorithm

If your model evaluations are computationally expensive, one option is to parallelize those evaluations across multiple cores. Please refer to the example - https://github.com/Project-Platypus/Platypus/blob/master/examples/simple_parallel.py

todaylsy commented 1 year ago

Thanks for your help!