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

CMA_ES_Base([algParams, save_path])

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: object

Base class for single-objective CMA-ES optimization.

Parameters:
  • algParams (dict, optional) –

    Algorithm configuration dictionary. Expected keys are:

    • dim: problem dimension.

    • popSize: population size (lambda in CMA-ES).

    • maxGen: number of generations.

    • sigma: initial global step size.

  • save_path (str, optional) – Checkpoint path used by load_state() and save_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

get_obs()[source]

Placeholder for loading observed values used by subclasses.

get_sim()[source]

Placeholder for loading simulated values used by subclasses.

createFitness()[source]

Create DEAP fitness type for single-objective minimization.

createInd()[source]

Create DEAP individual type bound to creator.Fitness.

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

registerEvaluate()[source]

Register the fitness evaluation function in self.toolbox.

registerGenerate()[source]

Register offspring generation based on current CMA strategy.

registerUpdate()[source]

Register CMA strategy update operation.

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_path if available.

When checkpoint does not exist, initialize a fresh CMA strategy and leave population creation to __init__().

save_state()[source]

Serialize current algorithm state to save_path.

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