optimpv.scipyOpti package
Submodules
optimpv.scipyOpti.scipyOptimizer module
scipyOptimizer module. This module contains the ScipyOptimizer class, which is used to optimize a given function using the scipy library.
- class optimpv.scipyOpti.scipyOptimizer.ScipyOptimizer(params=None, agents=None, method='L-BFGS-B', options=None, name='scipy_opti', **kwargs)[source]
Bases:
BaseAgent
Initialize the ScipyOptimizer class. This class is used to optimize a given function using the scipy library.
- Parameters:
params (list of Fitparam() objects, optional) – List of Fitparam() objects, by default None
agents (list of Agent() objects, optional) – List of Agent() objects see optimpv/general/BaseAgent.py for a base class definition, by default None
method (str, optional) – Optimization method to use with scipy.minimize, by default ‘L-BFGS-B’
options (dict, optional) – Options to pass to scipy.minimize, by default None
name (str, optional) – Name of the optimization process, by default ‘scipy_opti’
**kwargs (dict) – Additional keyword arguments including: - parallel_agents: bool, whether to run agents in parallel - max_parallelism: int, maximum number of parallel processes - verbose_logging: bool, whether to log verbose information
- create_metrics_list()[source]
Create a list of all metrics from all agents.
- Returns:
List of metric names
- Return type:
list
- create_objective(multi_objective=False)[source]
Create an objective function for scipy.minimize based on agent evaluations.
- Parameters:
multi_objective (bool, optional) – Whether to handle multiple objectives, by default False
- Returns:
Objective function that takes a parameter vector and returns a scalar value
- Return type:
callable
- create_search_space(params)[source]
Create a search space suitable for scipy.optimize.minimize based on parameters.
- Parameters:
params (list of Fitparam() objects) – List of parameter objects
- Returns:
A tuple containing (x0, bounds) where x0 is the initial parameter vector and bounds is a list of (lower, upper) bound tuples
- Return type:
tuple
- evaluate(args)[source]
Evaluate the agent on a parameter point.
- Parameters:
args (tuple) – Tuple containing the index of the agent, the agent, the index of the parameter point and the parameter point
- Returns:
Tuple containing the index of the parameter point and the results of the agent on the parameter point
- Return type:
tuple
- optimize(multi_objective=False)[source]
Run the optimization process using scipy.minimize.
- Parameters:
multi_objective (bool, optional) – Whether to use multi-objective optimization, by default False
- Returns:
The optimization results
- Return type:
object
- reconstruct_params(x)[source]
Reconstruct a parameter dictionary from an optimization vector.
- Parameters:
x (array-like) – Parameter vector from the optimizer
- Returns:
Dictionary mapping parameter names to values
- Return type:
dict
- update_params_with_best_balance(return_best_balance=False)[source]
Update the parameters with the best balance of all metrics. The best balance is defined by ranking the results for each metric and taking the parameters that has the lowest sum of ranks.
- Parameters:
return_best_balance (bool, optional) – Whether to return the best balance index and parameters, by default False
- Returns:
Tuple containing the best balance index and parameters, if return_best_balance is True
- Return type:
tuple, optional
- Raises:
ValueError – We need at least one metric to update the parameters