fitAlgs.evolutionary module

Author:Dominic Hunt
class fitAlgs.evolutionary.Evolutionary(strategy=None, polish=False, population_size=20, tolerance=0.01, **kwargs)[source]

Bases: fitAlgs.fitAlg.FitAlg

The class for fitting data using scipy.optimise.differential_evolution

Parameters:
  • fit_sim (fitAlgs.fitSims.FitSim instance, optional) – An instance of one of the fitting simulation methods. Default fitAlgs.fitSims.FitSim
  • fit_measure (string, optional) – The name of the function used to calculate the quality of the fit. The value it returns provides the fitter with its fitting guide. Default -loge
  • fit_measure_args (dict, optional) – The parameters used to initialise fit_measure and extra_fit_measures. Default None
  • extra_fit_measures (list of strings, optional) – List of fit measures not used to fit the model, but to provide more information. Any arguments needed for these measures should be placed in fit_measure_args. Default None
  • bounds (dictionary of tuples of length two with floats, optional) – The boundaries for methods that use bounds. If unbounded methods are specified then the bounds will be ignored. Default is None, which translates to boundaries of (0, np.inf) for each parameter.
  • boundary_excess_cost (str or callable returning a function, optional) – The function is used to calculate the penalty for exceeding the boundaries. Default is boundFunc.scalarBound()
  • boundary_excess_cost_properties (dict, optional) – The parameters for the boundary_excess_cost function. Default {}
  • strategy (string or list of strings, optional) – The name of the fitting strategy or list of names of fitting strategies or name of a list of fitting strategies. Valid names found in the notes. Default best1bin
  • polish (bool, optional) – If True (default), then scipy.optimize.minimize with the L-BFGS-B method is used to polish the best population member at the end, which can improve the minimization slightly. Default False
  • population_size (int, optional) – A multiplier for setting the total population size. The population has popsize * len(x) individuals. Default 20
  • tolerance (float, optional) – When the mean of the population energies, multiplied by tol, divided by the standard deviation of the population energies is greater than 1 the solving process terminates: convergence = mean(pop) * tol / stdev(pop) > 1 Default 0.01
Name

The name of the fitting strategies

Type:string
strategySet

The list of valid fitting strategies. Currently these are: ‘best1bin’, ‘best1exp’, ‘rand1exp’, ‘randtobest1exp’, ‘best2exp’, ‘rand2exp’, ‘randtobest1bin’, ‘best2bin’, ‘rand2bin’, ‘rand1bin’ For all strategies, use ‘all’

Type:list

See also

fitAlgs.fitAlg.FitAlg
The general fitting strategy class, from which this one inherits
fitAlgs.fitSims.FitSim
The general class for seeing how a parameter combination perform
scipy.optimise.differential_evolution
The fitting method this wraps around
callback(xk, convergence)[source]

Used for storing the state after each stage of fitting

Parameters:
  • xk (coordinates of best fit) –
  • convergence (the proportion of the points from the iteration that have converged) –
fit(simulator, model_parameter_names, model_initial_parameters)[source]

Runs the model through the fitting algorithms and starting parameters and returns the best one.

Parameters:
  • simulator (function) – The function used by a fitting algorithm to generate a fit for given model parameters. One example is fitAlgs.fitSim.fitness
  • model_parameter_names (list of strings) – The list of initial parameter names
  • model_initial_parameters (list of floats) – The list of the initial parameters
Returns:

  • best_fit_parameters (list of floats) – The best fitting parameters
  • fit_quality (float) – The quality of the fit as defined by the quality function chosen.
  • testedParams (tuple of two lists and a dictionary) – The two lists are a list containing the parameter values tested, in the order they were tested, and the fit qualities of these parameters. The dictionary contains the parameters and convergence values from each iteration, stored in two lists.

See also

fitAlgs.fitAlg.fitness()

validStrategySet = ['best1bin', 'best1exp', 'rand1exp', 'randtobest1exp', 'best2exp', 'rand2exp', 'randtobest1bin', 'best2bin', 'rand2bin', 'rand1bin']