Calibration#

class pyxel.calibration.Calibration(target_data_path, fitness_function, algorithm, parameters, outputs=None, readout=None, mode='pipeline', result_type='image', result_fit_range=None, result_input_arguments=None, target_fit_range=None, pygmo_seed=None, pipeline_seed=None, num_islands=1, num_evolutions=1, num_best_decisions=None, topology='unconnected', type_islands='multiprocessing', weights_from_file=None, weights=None, working_directory=None)[source]#

Bases: object

TBW.

property calibration_mode#

TBW.

property result_type#

TBW.

property result_fit_range#

TBW.

property result_input_arguments#

TBW.

property target_data_path#

TBW.

property target_fit_range#

TBW.

property fitness_function#

TBW.

property algorithm#

TBW.

property parameters#

TBW.

property pygmo_seed#

TBW.

property pipeline_seed#

TBW.

property num_islands#

TBW.

property num_evolutions#

TBW.

property num_best_decisions#

TBW.

property topology#

TBW.

property weights_from_file#

TBW.

property weights#

TBW.

get_problem(processor, output_dir)[source]#

Convert a ‘processor’ object into a Pygmo Problem.

Examples

Create a ‘Pygmo Problem’ >>> calibration = Calibration(…) >>> problem = calibration.get_problem(processor=…, output_dir=…)

Create a decision vector >>> problem.get_bounds() >>> decision_vector = […]

Compute fitness >>> problem.fitness(decision_vector)

run_calibration(processor, output_dir, with_inherited_coords, with_progress_bar=True)[source]#

Run calibration pipeline.

classmethod from_json(dct)[source]#

Create a new object from a JSON dictionary.

class pyxel.calibration.CalibrationResult(dataset, processors, logs, filenames)[source]#

Bases: NamedTuple

Result class for calibration class.

dataset#

Alias for field number 0

processors#

Alias for field number 1

logs#

Alias for field number 2

filenames#

Alias for field number 3

count(value, /)#

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

class pyxel.calibration.MyArchipelago(**kwargs)[source]#

Bases: object

User-defined Archipelago.

run_evolve(readout, num_evolutions=1, num_best_decisions=None)[source]#

Run evolution(s) several time.

Parameters:
  • readout

  • num_evolutions (int) – Number of time to run the evolutions.

  • num_best_decisions (int or None, optional.) – Number of best individuals to extract. If this parameter is set to None then no individuals are extracted.

Returns:

TBW.

get_best_individuals(num_best_decisions)[source]#

Get the best decision vectors and fitness from the island of an archipelago.

Parameters:

num_best_decisions (int or None, optional.) – Number of best individuals to extract. If this parameter is set to None then no individuals are extracted.

Returns:

Dataset – A new dataset with two data arrays ‘best_decision’ and ‘best_fitness’.

Examples

>>> archi = MyArchipelago(...)
>>> archi.get_best_individuals(num_best_decisions=5)
<xarray.Dataset>
Dimensions:          (individual: 10, island: 2, param_id: 7)
Coordinates:
  * island           (island) int64 0 1
  * individual       (individual) int64 0 1 2 3 4 5 6 7 8 9
Dimensions without coordinates: param_id
Data variables:
    best_decision    (island, individual, param_id) float64 0.1526 ... 0.1608
    best_parameters  (island, individual, param_id) float64 0.1526 ... 0.1608
    best_fitness     (island, individual) float64 3.285e+04 ... 5.732e+04
Raises:

ValueError – Raised if ‘num_best_decisions’ is a negative ‘int’ value.

class pyxel.calibration.Algorithm(type='sade', generations=1, population_size=1, variant=2, variant_adptv=1, ftol=1e-06, xtol=1e-06, memory=False, cr=0.9, eta_c=1.0, m=0.02, param_m=1.0, param_s=2, crossover='exponential', mutation='polynomial', selection='tournament', nlopt_solver='neldermead', maxtime=0, maxeval=0, xtol_rel=1e-08, xtol_abs=0.0, ftol_rel=0.0, ftol_abs=0.0, stopval=None, local_optimizer=None, replacement='best', nlopt_selection='best')[source]#

Bases: object

TBW.

property type#

TBW.

property generations#

TBW.

property population_size#

TBW.

property variant#

TBW.

property variant_adptv#

TBW.

property ftol#

TBW.

property xtol#

TBW.

property memory#

TBW.

property cr#

TBW.

property eta_c#

TBW.

property m#

TBW.

property param_m#

TBW.

property param_s#

TBW.

property crossover#

TBW.

property mutation#

TBW.

property selection#

TBW.

property nlopt_solver#

TBW.

property maxtime#

TBW.

property maxeval#

TBW.

property xtol_rel#

TBW.

property xtol_abs#

TBW.

property ftol_rel#

TBW.

property ftol_abs#

TBW.

property stopval#

TBW.

property local_optimizer#

TBW.

property replacement#

TBW.

property nlopt_selection#

TBW.

get_algorithm()[source]#

TBW.

Fitness functions#

pyxel.calibration.sum_of_abs_residuals(simulated, target, weighting)[source]#

Calculate the sum of absolute residuals between simulated and target values.

Parameters:
  • simulated (np.ndarray) – An array containing simulated values.

  • target (np.ndarray) – An array containing target (observed) values.

  • weighting (np.ndarray) – An array containing weights for each data point. These weights adjust the contribution of each residual to the final sum.

Returns:

float – The sum of absolute residuals, considering the provided weighting.

pyxel.calibration.sum_of_squared_residuals(simulated, target, weighting)[source]#

Calculate the sum of squared residuals between simulated and target values.

Parameters:
  • simulated (np.ndarray) – An array containing simulated values.

  • target (np.ndarray) – An array containing target (observed) values.

  • weighting (np.ndarray) – An array containing weights for each data point. These weights adjust the contribution of each squared residual to the final sum.

Returns:

float – The sum of squared residuals, considering the provided weighting.

pyxel.calibration.reduced_chi_squared(simulated, target, weighting, free_parameters)[source]#

Compute the reduced chi-square error statistic.

Notes

You can find more information at this link https://en.wikipedia.org/wiki/Goodness_of_fit

Parameters:
  • simulated (np.ndarray) – An array containing simulated values.

  • target (np.ndarray) – An array containing target (observed) values.

  • weighting (np.ndarray) – An array containing weights for each data point. These weights adjust the contribution of each squared deviation to the final statistic.

  • free_parameters (int) – Number of free parameters in the model.

Returns:

float – The reduced \(\chi^{2}\).