gugarosa / opytimizer

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

[REG] How to get best agent values? #18

Closed amir1m closed 3 years ago

amir1m commented 3 years ago

Hello, I am following the tutorial. After running opt.start() how do we get the optimized parameters? opt object has history. best_agent attributes, is there way to directly get the best parameters?

Also, by default it does minimization or maximization?

gugarosa commented 3 years ago

Hello amir1m! I hope everything is going well with you!

Usually, we use the history object to get the values over the iterations, which you can retrieve using the history.get() method. On the other hand, if you just need to access the value of the best parameters, you can directly use the following:

# The best agent's position stores the best parameters
best_params = opt.space.best_agent.position

# Note that as we use a (n_variables, n_dimensions) tensor, you need to index both dimensions to retrieve the parameters 
# In most cases, we use n_dimensions=1, so you can access them with its first index
x1 = best_params[0][0]
x2 = best_params[1][0]
x3 = best_params[2][0]
...
xN = best_params[N-1][0]

And finally, by default, we focus on minimization.

I hope that I could help you at all, but if you have any problems or concerns, please let me know!

Best regards, Gustavo.

amir1m commented 3 years ago

Got it. Thanks @gugarosa ! Working as you mentioned.