optimpv.pymooOpti package
Submodules
optimpv.pymooOpti.pymooOptimizer module
PymooOptimizer module. This module contains the PymooOptimizer class, which is used to optimize a given function using pymoo’s genetic algorithms.
- class optimpv.pymooOpti.pymooOptimizer.PymooOptimizer(params=None, agents=None, algorithm='NSGA2', pop_size=100, n_gen=100, algorithm_kwargs=None, existing_data=None, suggest_only=False, name='pymoo', **kwargs)[source]
Bases:
BaseAgent
Initialize the PymooOptimizer class. This class is used to optimize a given function using pymoo algorithms.
- 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
algorithm (str, optional) – Optimization algorithm to use, by default ‘NSGA2’ Options: ‘NSGA2’, ‘NSGA3’, ‘MOEAD’, ‘GA’, ‘DE’, ‘PSO’
pop_size (int, optional) – Population size, by default 100
n_gen (int, optional) – Number of generations, by default 100
algorithm_kwargs (dict, optional) – Additional keyword arguments for the algorithm, by default None
existing_data (DataFrame, optional) – existing data to use for the optimization process, by default None
suggest_only (bool, optional) – if True, the optimization process will only suggest new points without running the agents, by default False
name (str, optional) – Name of the optimization process, by default ‘pymoo’
**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 - seed: int, random seed for reproducibility
- create_algorithm()[source]
Create a pymoo algorithm based on the specified algorithm name or return the provided algorithm object.
- get_best_solution(balance_objectives=True)[source]
Get the best solution from the optimization results.
- Parameters:
balance_objectives (bool, optional) – If True and multiple objectives exist, return the solution with best balance. If False, return the first solution from the Pareto front.
- Returns:
Dictionary containing the best parameters
- Return type:
dict
- get_df_from_pymoo()[source]
Convert the optimization results to a pandas DataFrame.
- Returns:
DataFrame containing the optimization results
- Return type:
pd.DataFrame
- get_pareto_front()[source]
Get the Pareto front solutions for multi-objective optimization.
- Returns:
Tuple containing (parameters_list, objectives_array)
- Return type:
tuple
- plot_convergence(save_path=None, **kwargs)[source]
Plot the convergence history of the optimization.
- Parameters:
save_path (str, optional) – Path to save the plot, by default None
**kwargs (dict) –
Additional keyword arguments for the plot.
- xscalestr, optional
Scale for the x-axis, by default ‘linear’
- yscalestr, optional
Scale for the y-axis, by default ‘linear’
- update_params_with_best_balance(return_best_balance=False)[source]
- Update the parameters with the best balance of all metrics.
If multiple objectives exist, find the best balance based on ranks.
- Parameters:
return_best_balance (bool, optional) – If True, return the index and parameters of the best balance, by default False
- Returns:
If return_best_balance is True, return the index and parameters of the best balance. Otherwise, return None.
- Return type:
tuple
- Raises:
ValueError – If no evaluations have been performed or no metrics are available.
- class optimpv.pymooOpti.pymooOptimizer.PymooProblem(agents, **kwargs)[source]
Bases:
ElementwiseProblem
- 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
- parse_constraints(constraints)[source]
Parse parameter constraints from string format to numerical format.
- Parameters:
constraints (list of str) – List of constraint strings in format like “x1 + 2*x2 <= 5”
- Returns:
List of constraint dictionaries with ‘indices’, ‘coefficients’, ‘rhs’, ‘operator’
- Return type:
list of dict