easy_vic_build.tools.calibrate_func.algorithm_CMA_ES
CMA-ES base algorithm used by calibration workflows.
This module provides CMA_ES_Base, a lightweight wrapper around
deap.cma.Strategy with:
checkpoint save/load support;
generation history recording;
optional convergence plotting.
Users typically subclass CMA_ES_Base and override evaluate().
Classes
|
Base class for single-objective CMA-ES optimization. |
- class easy_vic_build.tools.calibrate_func.algorithm_CMA_ES.CMA_ES_Base(algParams={'dim': None, 'maxGen': 250, 'popSize': 20, 'sigma': 0.5}, save_path='checkpoint.pkl')[source]
Bases:
objectBase class for single-objective CMA-ES optimization.
- Parameters:
algParams (dict, optional) –
Algorithm configuration dictionary. Expected keys are:
dim: problem dimension.popSize: population size (lambdain CMA-ES).maxGen: number of generations.sigma: initial global step size.
save_path (str, optional) – Checkpoint path used by
load_state()andsave_state().
- dim
Problem dimension.
- Type:
int
- popSize
Population size.
- Type:
int
- maxGen
Maximum number of generations.
- Type:
int
- sigma
Initial CMA-ES sigma.
- Type:
float
- history
Per-generation records containing population snapshots and best individual snapshots.
- Type:
list of dict
- current_generation
Current generation index.
- Type:
int
- population
Current population.
- Type:
list
- initial_population
Population right after initialization or checkpoint loading.
- Type:
list
Initialize the algorithm state and register DEAP operations.
- Parameters:
algParams (dict, optional) – Algorithm configuration. See class docstring for accepted keys.
save_path (str, optional) – Checkpoint file path.
- __init__(algParams={'dim': None, 'maxGen': 250, 'popSize': 20, 'sigma': 0.5}, save_path='checkpoint.pkl')[source]
Initialize the algorithm state and register DEAP operations.
- Parameters:
algParams (dict, optional) – Algorithm configuration. See class docstring for accepted keys.
save_path (str, optional) – Checkpoint file path.
- init_cma_strategy(dim, popSize, sigma, **kwargs)[source]
Create and return a DEAP CMA strategy object.
- Parameters:
dim (int) – Problem dimension.
popSize (int) – Population size (
lambda_).sigma (float) – Initial global step size.
**kwargs – Extra keyword arguments forwarded to
deap.cma.Strategy.
- Returns:
Configured CMA-ES strategy instance.
- Return type:
deap.cma.Strategy
- evaluate(ind)[source]
Evaluate one individual.
Notes
This is a default demo objective and should be overridden by subclasses.
- Parameters:
ind (sequence) – Candidate solution.
- Returns:
Fitness tuple compatible with DEAP.
- Return type:
tuple of float
- evaluatePop(population)[source]
Evaluate all individuals in a population in-place.
- Parameters:
population (list) – Population to evaluate.
- updatePop(offspring)[source]
Update and return population for the next iteration.
- Parameters:
offspring (list) – Newly generated and evaluated offspring.
- Returns:
Population for next generation.
- Return type:
list
Notes
Default behavior is
(mu, lambda)style replacement with offspring only. Subclasses may override this method.
- load_state()[source]
Load checkpoint from
save_pathif available.When checkpoint does not exist, initialize a fresh CMA strategy and leave population creation to
__init__().
- print_results(population)[source]
Log best individual and fitness for a population.
- Parameters:
population (list) – Population to summarize.
- plot_progress(plot_dir='cmaes_progress', ylim=None)[source]
Plot per-generation fitness scatter and best-fitness curve.
- Parameters:
plot_dir (str, optional) – Output directory for figure files.
ylim (float or tuple(float, float), optional) – If float, used as lower bound of y-axis. If 2-tuple/list, used as explicit
(ymin, ymax).
- run(plot_progress=False, plot_dir='cmaes_progress', plot_ylim=None)[source]
Run CMA-ES optimization loop.
- Parameters:
plot_progress (bool, optional) – Whether to generate convergence plot at each generation.
plot_dir (str, optional) – Plot output directory.
plot_ylim (float or tuple(float, float), optional) – Y-axis setting passed to
plot_progress().
- Returns:
Final population.
- Return type:
list