gugarosa / opytimizer

🐦 Opytimizer is a Python library consisting of meta-heuristic optimization algorithms.
https://opytimizer.readthedocs.io
Apache License 2.0
606 stars 41 forks source link

[REG] How to get a detailed print out during optimization? #30

Closed TamerAbdelmigid closed 2 years ago

TamerAbdelmigid commented 2 years ago

Greetings,

My function takes time getting evaluated, and I want to closely monitor what happens during optimization process. When using grid search space and printing the fitness from my function, I could see the movement along the grid. But, when using normal search space, my processor utilization is 100% and it takes hours with no print out. So, hot to get more details? is there something like a degree of verbosity?

Thanks in advance.

gugarosa commented 2 years ago

Hello @TamerAbdelmigid! I hope everything is going well with you.

We usually rely on printing logs during each optimization epoch, so this might be the case where your fitness function is taking too long to be evaluated and during the evaluation of individual agents no logs are being produced. Additionally, callbacks might be the most suitable approach for you because they are usually called before/after the evaluation function, which is where the loop of agents is implemented.

I would say that the most straightforward way for now would be to add a log/print function inside the evaluate function of the meta-heuristic technique you are using. For example, inside the evaluate() function (https://github.com/gugarosa/opytimizer/blob/master/opytimizer/optimizers/swarm/pso.py#L148), you could add a logger.info(f"{agent.position} | {fit}") just after fit = function(agent.position) (L160). Thus, for every agent that is being evaluated, an additional log will be produced and saved in the log file.

Nevertheless, I will take a closer look on how to implement a verbosity level with additional logging, just to make things clearer!

Best regards, Gustavo.

TamerAbdelmigid commented 2 years ago

Hey @gugarosa, Thanks for your response and clarification, much appreciated.