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]Is there a way to provide initial values before starting optimization? #22

Closed amir1m closed 3 years ago

amir1m commented 3 years ago

Hello, Hope you keeping well.

I am looking to provide an initial value to optimization loop. Is there a way through searchspace or otherwise to provide initial/starting solution?

Thanks.

gugarosa commented 3 years ago

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

Yes, definetely. Prior to the Opytimizer.start() function, you can iterate over every agent in the search space and apply a constant value to their position, such as:

for agent in search_space.agents:
  agent.fill_with_static(values)

where values is a numpy array with the same size of n_variables. Please note that this method completely ignore the lower and upper bounds, so use it with caution!

If you need a more complex mechanism than just filling with static values, I would suggest to directly change their position array, such as:

for agent in search_space.agents:
  for j in range(agent.n_variables):
    agent.position[j] = value

Best regards, Gustavo.

amir1m commented 3 years ago

Thanks @gugarosa !