ga

compas.numerical.ga(fit_function, fit_type, num_var, boundaries, num_gen=100, num_pop=100, num_elite=10, mutation_probability=0.01, n_cross=1, num_bin_dig=None, num_pop_init=None, num_gen_init_pop=None, start_from_gen=False, min_fit=None, fit_name=None, fargs=None, fkwargs=None, output_path=None, input_path=None, print_refresh=1)[source]

Genetic Algorithm optimisation.

Parameters
  • fit_function (callable) – The function used by the :class’GA’ to determine the fitness value. The function must have as a first argument a list of variables that determine the fitness value. Other arguments and keyword arguments can be used to feed the function relevant data.

  • fit_type (str) – String that indicates if the fitness function is to be minimized or maximized. “min” for minimization and “max” for maximization.

  • num_var (int) – The number of variables used by the fitness function.

  • boundaries (list) – The minimum and vaximum values each variable is allowed to have. Must be a num_var long list of tuples in the form [(min, max),…].

  • num_gen (int, optional [100]) – The maximum number of generations.

  • num_pop (int, optional [100]) – The number of individuals in the population. Must be an even number.

  • num_elite (int, optional [10]) – The number of individuals in the elite population. Must be an even number.

  • mutation_probablity (float, optional [0.001]) – Float from 0 to 1. Percentage of genes that will be mutated.

  • n_cross (int, optional [1]) – Number of crossover points used in the crossover operator.

  • num_bin_dig (list, optional [None]) – Number of genes used to codify each variable. Must be a num_var long list of intergers. If None is given, each variable will be coded with a 8 digit binary number, corresponding to 256 steps.

  • num_pop_init (int, optional [None]) – The number of individuals in the population for the first num_gen_init_pop generations.

  • num_gen_init_pop (int, optional) – The number of generations to keep a num_pop_init size population for.

  • start_from_get (int, optional [None]) – The generation number to restart a previous optimization process.

  • min_fit (float, optional [None]) – A target fitness value. If the GA finds a solution with a fitness value equal or better than min_fit, the optimization is stopped.

  • fit_name (str, optional [None]) – The name of the optimisation. If None is given, the name of the fitness function is used.

  • fargs (list, optional [None]) – Arguments fo be fed to the fitness function.

  • fkwargs (dict, optional [None]) – Keyword arguments to be fed to the fitness function.

  • output_path (str, optional [None]) – Path for the optimization result files.

  • input_path (str, optional [None]) – Path to the fitness function file.

  • print_refresh (int) – Print current generation summary every print_refresh generations.

Returns

ga_ (object) – The resulting :class’GA’ instance.

Notes

For more info, see 1.

References

1

Holland, J. H., Adaptation in Natural and Artificial Systems, 1st edn, The University of Michigan, Ann Arbor, 1975.

Examples

>>>