class Rivet::MendelMin

Rivet::MendelMin

A genetic algorithm functional minimizer. More…

#include <MendelMin.hh>

Public Types

Name
using std::valarray< double >Params
Typedef for a valaray of parameters to the function to be minimised.
using std::function< double(const Params &, const Params &)>FuncT
Typedef for the function to be minimised.
using std::function< double(const Params &)>FuncNoFixedT
Typedef for the function to be minimised.

Public Functions

Name
MendelMin(const FuncT & fin, unsigned int ndim, const Params & fixpar, unsigned int npop =20, unsigned int ngen =20, double margin =0.1)
MendelMin(const FuncNoFixedT & fin, unsigned int ndim, unsigned int npop =20, unsigned int ngen =20, double margin =0.1)
voidguess(const Params & p)
doubleevolve(unsigned int NGen)
Paramsfittest() const
Return the fittest parameter point found.
doublefit() const
Return the fittest value found.
doublernd() const
Simple wrapper around the random number generator.
ParamsrndParams() const
Return a random parameter point in the unit hypercube.
voidlimit01(Params & p) const
Limit a parameter point to inside the unit hypercube.
voidmove(Params & bad, const Params & better) const
doublef(const Params & p) const
Simple wrapper around the function to be minimised.
std::pair< double, double >minmax()

Public Attributes

Name
boolshowTrace
Set true to get a verbose record of the evolution.

Detailed Description

class Rivet::MendelMin;

A genetic algorithm functional minimizer.

MendelMin implements a home brewed genetic algorithm for finding the minimum of a function defined on a unit hypercube returning a non-negative real number (eg. a Chi-squared value).

Public Types Documentation

using Params

using Rivet::MendelMin::Params =  std::valarray<double>;

Typedef for a valaray of parameters to the function to be minimised.

using FuncT

using Rivet::MendelMin::FuncT =  std::function<double(const Params&, const Params&)>;

Typedef for the function to be minimised.

using FuncNoFixedT

using Rivet::MendelMin::FuncNoFixedT =  std::function<double(const Params&)>;

Typedef for the function to be minimised.

Public Functions Documentation

function MendelMin

inline MendelMin(
    const FuncT & fin,
    unsigned int ndim,
    const Params & fixpar,
    unsigned int npop =20,
    unsigned int ngen =20,
    double margin =0.1
)

Constructor with fixed parameters

Mandatory arguments: the function, fin, to be minimised; the dimension, ndim, of the unit hypercube for which fin is defined; a set of fixed parameters not to be optimised.

Optional arguments are: the number, npop, of individuals in the population; and margin which determines how much randomness is involved when an individual is evolved twowards the fittest individual.

function MendelMin

inline MendelMin(
    const FuncNoFixedT & fin,
    unsigned int ndim,
    unsigned int npop =20,
    unsigned int ngen =20,
    double margin =0.1
)

Constructor without fixed parameters

Mandatory arguments: the function, fin, to be minimised; the dimension, ndim, of the unit hypercube for which fin is defined.

Optional arguments are: the number, npop, of individuals in the population; and margin which determines how much randomness is involved when an individual is evolved twowards the fittest individual.

function guess

inline void guess(
    const Params & p
)

Supply a best guess for the fittest parameter point to help things along.

function evolve

inline double evolve(
    unsigned int NGen
)

Evolve the population a given number of generations and return the best fit value.

function fittest

inline Params fittest() const

Return the fittest parameter point found.

function fit

inline double fit() const

Return the fittest value found.

function rnd

inline double rnd() const

Simple wrapper around the random number generator.

function rndParams

inline Params rndParams() const

Return a random parameter point in the unit hypercube.

function limit01

inline void limit01(
    Params & p
) const

Limit a parameter point to inside the unit hypercube.

function move

inline void move(
    Params & bad,
    const Params & better
) const

Move a bad parameter point towards a better one. The new point is picked randomly within the generalized hypercube where bad and better are at diagonally opposite corners, enlarged by a fraction _margin.

function f

inline double f(
    const Params & p
) const

Simple wrapper around the function to be minimised.

function minmax

inline std::pair< double, double > minmax()

Return: the best and worst fitness values.

Calculate the fitness values of all individuals and put the fittest one first.

Public Attributes Documentation

variable showTrace

bool showTrace;

Set true to get a verbose record of the evolution.


Updated on 2022-08-07 at 20:17:17 +0100