hyponic.optimizers.physics_based package

hyponic.optimizers.physics_based.SA module

class hyponic.optimizers.physics_based.SA.SA(epoch: int = 10, population_size: int = 10, minmax: str = None, verbose: bool = False, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]

Bases: BaseOptimizer

Simulated Annealing

Example

>>> from hyponic.optimizers.physics_based.SA import SA
>>> import numpy as np
>>>
>>> def sphere(x):
>>>     return np.sum(x ** 2)
>>>
>>> problem_dict = {
>>>     'fit_func': sphere,
>>>     'lb': [-5.12, -5, -14, -6, -0.9],
>>>     'ub': [5.12, 5, 14, 6, 0.9],
>>>     'minmax': 'min'
>>> }
>>>
>>> sa = SA(epoch=40, population_size=100, verbose=True, early_stopping=4)
>>> sa.solve(problem_dict)
>>> print(sa.get_best_score())
>>> print(sa.get_best_solution())
evolve(current_epoch)[source]

Evolve the population for one epoch

Parameters:

current_epoch – current epoch number

get_best_score()[source]

Get the best score of the current population

Returns:

best score of the fitness function

get_best_solution()[source]

Get the best solution of the current population

Returns:

coordinates of the best solution

get_current_best_score()[source]

Get the best score of the current population

Returns:

current best score of the fitness function

get_current_best_solution()[source]

Get the best solution of the current population

Returns:

current coordinates of the best solution

initialize(problem_dict)[source]

Initialize the optimizer with the problem dictionary

Parameters:

problem_dict – dictionary containing the problem definition