This is the mgl-gpr Reference Manual, version 0.0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Jul 13 21:16:24 2025 GMT+0.
The main system appears first, followed by any subsystem dependency.
mgl-gpr
MGL-GPR is a library of evolutionary algorithms such
as Genetic Programming (evolving typed expressions from a set of
operators and constants) and Differential Evolution.
Gábor Melis <mega@retes.hu>
(GIT https://github.com/melisgl/mgl-gpr.git)
MIT, see COPYING.
0.0.1
alexandria
(system).
mgl-pax
(system).
src
(module).
Modules are listed depth-first from the system components tree.
mgl-gpr/src
mgl-gpr
(system).
package.lisp
(file).
evolutionary-algorithm.lisp
(file).
util.lisp
(file).
tree.lisp
(file).
genetic-programming.lisp
(file).
differential-evolution.lisp
(file).
doc.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
mgl-gpr/mgl-gpr.asd
mgl-gpr/src/package.lisp
mgl-gpr/src/evolutionary-algorithm.lisp
mgl-gpr/src/util.lisp
mgl-gpr/src/tree.lisp
mgl-gpr/src/genetic-programming.lisp
mgl-gpr/src/differential-evolution.lisp
mgl-gpr/src/doc.lisp
mgl-gpr/src/evolutionary-algorithm.lisp
package.lisp
(file).
src
(module).
add-individual
(function).
advance
(generic function).
evaluator
(reader method).
evolutionary-algorithm
(class).
fitness-key
(reader method).
fittest
(reader method).
fittest-changed-fn
(reader method).
(setf fittest-changed-fn)
(writer method).
generation-counter
(reader method).
mass-evaluator
(reader method).
population
(reader method).
(setf population)
(writer method).
population-size
(reader method).
(setf population-size)
(writer method).
@gpr-background
(special variable).
@gpr-ea
(special variable).
@gpr-ea-evaluation
(special variable).
@gpr-ea-population
(special variable).
@gpr-ea-training
(special variable).
@gpr-gp-links
(special variable).
@gpr-manual
(special variable).
fitnesses
(reader method).
(setf fitnesses)
(writer method).
nursery
(reader method).
(setf nursery)
(writer method).
mgl-gpr/src/util.lisp
evolutionary-algorithm.lisp
(file).
src
(module).
gaussian-random-1
(function).
insert-into-sorted-vector
(function).
max-position/vector
(function).
random-element
(function).
random-normal
(function).
sum-seq
(function).
mgl-gpr/src/tree.lisp
util.lisp
(file).
src
(module).
count-nodes
(function).
change-node-at
(function).
dotree
(macro).
map-tree
(function).
node-at
(function).
parent-of-node-at
(function).
mgl-gpr/src/genetic-programming.lisp
tree.lisp
(file).
src
(module).
advance
(method).
argument-types
(reader method).
builder
(reader method).
copy-chance
(reader method).
(setf copy-chance)
(writer method).
expression-class
(class).
genetic-programming
(class).
hold-tournament
(function).
keep-fittest-p
(reader method).
(setf keep-fittest-p)
(writer method).
literal
(macro).
literal
(class).
literals
(reader method).
mutation-chance
(reader method).
(setf mutation-chance)
(writer method).
name
(reader method).
operator
(macro).
operator
(class).
operators
(reader method).
print-object
(method).
print-object
(method).
random-expression
(function).
random-gp-expression
(function).
randomizer
(reader method).
result-type
(reader method).
selector
(reader method).
toplevel-type
(reader method).
weight
(reader method).
@gpr-gp
(special variable).
@gpr-gp-background
(special variable).
@gpr-gp-basics
(special variable).
@gpr-gp-environment
(special variable).
@gpr-gp-expressions
(special variable).
@gpr-gp-reproduction
(special variable).
@gpr-gp-search-space
(special variable).
@gpr-gp-tutorial
(special variable).
breed
(function).
calculate-fitnesses
(function).
copy-some
(function).
crossover-expressions
(function).
crossover-some
(function).
find-operator
(function).
mutate-expression
(function).
mutate-some
(function).
node-expected-type
(function).
random-expression-class
(function).
mgl-gpr/src/differential-evolution.lisp
genetic-programming.lisp
(file).
src
(module).
advance
(method).
advance
(method).
create-individual-fn
(reader method).
crossover-fn
(reader method).
crossover/binary
(function).
differential-evolution
(class).
map-weights-into-fn
(reader method).
mutate-fn
(reader method).
mutate/best/1
(function).
mutate/current-to-best/2
(function).
mutate/rand/1
(function).
sansde
(class).
select-distinct-random-numbers
(function).
@gpr-de
(special variable).
@gpr-de-sansde
(special variable).
autotune-fn
(reader method).
crossover-rate-mean
(reader method).
(setf crossover-rate-mean)
(writer method).
crossover/sansde
(function).
draw-cauchy
(function).
draw-positive-cauchy
(function).
draw-positive-normal
(function).
draw-rate
(function).
mutate/sansde
(function).
mutation-factor-pr
(reader method).
(setf mutation-factor-pr)
(writer method).
mutation-strategy-pr
(reader method).
(setf mutation-strategy-pr)
(writer method).
sansde-weighted-average
(function).
stats
(reader method).
(setf stats)
(writer method).
tune/sansde
(function).
update-sansde-strategy
(function).
mgl-gpr/src/doc.lisp
differential-evolution.lisp
(file).
src
(module).
pax-pages
(function).
pax-sections
(function).
Packages are listed by definition order.
mgl-gpr
See MGL-GPR::@GPR-MANUAL.
common-lisp
.
mgl-pax
.
add-individual
(function).
advance
(generic function).
argument-types
(generic reader).
builder
(generic reader).
copy-chance
(generic reader).
(setf copy-chance)
(generic writer).
count-nodes
(function).
create-individual-fn
(generic reader).
crossover-fn
(generic reader).
crossover/binary
(function).
differential-evolution
(class).
evaluator
(generic reader).
evolutionary-algorithm
(class).
expression-class
(class).
fitness-key
(generic reader).
fittest
(generic reader).
fittest-changed-fn
(generic reader).
(setf fittest-changed-fn)
(generic writer).
generation-counter
(generic reader).
genetic-programming
(class).
hold-tournament
(function).
keep-fittest-p
(generic reader).
(setf keep-fittest-p)
(generic writer).
literal
(macro).
literal
(class).
literals
(generic reader).
map-weights-into-fn
(generic reader).
mass-evaluator
(generic reader).
mutate-fn
(generic reader).
mutate/best/1
(function).
mutate/current-to-best/2
(function).
mutate/rand/1
(function).
mutation-chance
(generic reader).
(setf mutation-chance)
(generic writer).
name
(generic reader).
operator
(macro).
operator
(class).
operators
(generic reader).
population
(generic reader).
(setf population)
(generic writer).
population-size
(generic reader).
(setf population-size)
(generic writer).
random-expression
(function).
random-gp-expression
(function).
randomizer
(generic reader).
result-type
(generic reader).
sansde
(class).
select-distinct-random-numbers
(function).
selector
(generic reader).
toplevel-type
(generic reader).
weight
(generic reader).
@gpr-background
(special variable).
@gpr-de
(special variable).
@gpr-de-sansde
(special variable).
@gpr-ea
(special variable).
@gpr-ea-evaluation
(special variable).
@gpr-ea-population
(special variable).
@gpr-ea-training
(special variable).
@gpr-gp
(special variable).
@gpr-gp-background
(special variable).
@gpr-gp-basics
(special variable).
@gpr-gp-environment
(special variable).
@gpr-gp-expressions
(special variable).
@gpr-gp-links
(special variable).
@gpr-gp-reproduction
(special variable).
@gpr-gp-search-space
(special variable).
@gpr-gp-tutorial
(special variable).
@gpr-manual
(special variable).
autotune-fn
(generic reader).
breed
(function).
calculate-fitnesses
(function).
change-node-at
(function).
copy-some
(function).
crossover-expressions
(function).
crossover-rate-mean
(generic reader).
(setf crossover-rate-mean)
(generic writer).
crossover-some
(function).
crossover/sansde
(function).
dotree
(macro).
draw-cauchy
(function).
draw-positive-cauchy
(function).
draw-positive-normal
(function).
draw-rate
(function).
find-operator
(function).
fitnesses
(generic reader).
(setf fitnesses)
(generic writer).
gaussian-random-1
(function).
insert-into-sorted-vector
(function).
map-tree
(function).
max-position/vector
(function).
mutate-expression
(function).
mutate-some
(function).
mutate/sansde
(function).
mutation-factor-pr
(generic reader).
(setf mutation-factor-pr)
(generic writer).
mutation-strategy-pr
(generic reader).
(setf mutation-strategy-pr)
(generic writer).
node-at
(function).
node-expected-type
(function).
nursery
(generic reader).
(setf nursery)
(generic writer).
parent-of-node-at
(function).
pax-pages
(function).
pax-sections
(function).
random-element
(function).
random-expression-class
(function).
random-normal
(function).
sansde-weighted-average
(function).
stats
(generic reader).
(setf stats)
(generic writer).
sum-seq
(function).
tune/sansde
(function).
update-sansde-strategy
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Syntactic sugar for defining literal classes. The example given for
[LITERAL][class] could be written as:
(literal ((unsigned-byte 8))
(random 256))
See [WEIGHT][(reader expression-class)] for what WEIGHT means.
Syntactic sugar for instantiating operators. The example given for
[OPERATOR][class] could be written as:
(operator (+ float float) float)
See [WEIGHT][(reader expression-class)] for what WEIGHT means.
Adds INDIVIDUAL to POPULATION of EA. Usually called when initializing the EA.
Count the nodes in the sexp TREE. If INTERNAL then don’t count the leaves.
Destructively modify INDIVIDUAL-2 by replacement each element with a probability of 1 - CROSSOVER-RATE with the corresponding element in INDIVIDUAL-1. At least one, element is changed. Return INDIVIDUAL-2.
Select N-CONTESTANTS (all different) for the tournament randomly, represented by indices into FITNESSES and return the one with the highest fitness. If SELECT-CONTESTANT-FN is NIL then contestants are selected randomly with uniform probability. If SELECT-CONTESTANT-FN is a function, then it’s called with FITNESSES to return an index (that may or may not be already selected for the tournament). Specifying SELECT-CONTESTANT-FN allows one to conduct ’local’ tournaments biased towards a particular region of the index range. KEY is NIL or a function that select the real fitness value from elements of FITNESSES.
Return an expression built from OPERATORS and LITERALS that
evaluates to values of TYPE. TERMINATE-FN is a function of one
argument: the level of the root of the subexpression to be generated
in the context of the entire expression. If it returns T then a
[LITERAL][class] will be inserted (by calling its BUILDER function),
else an [OPERATOR][class] with all its necessary arguments.
The algorithm recursively generates the expression starting from
level 0 where only operators and literals with a RESULT-TYPE that’s
a subtype of TYPE are considered and one is selected with the
unnormalized probability given by its WEIGHT. On lower levels, the
ARGUMENT-TYPES specification of operators is similarly satisfied and
the resulting expression should evaluate without without a type
error.
The building of expressions cannot backtrack. If it finds itself in a situation where no literals or operators of the right type are available then it will fail with an error.
Creating the initial population by hand is tedious. This convenience function calls RANDOM-EXPRESSION to create a random individual that produces GP’s TOPLEVEL-TYPE. By passing in another TYPE one can create expressions that fit somewhere else in a larger expression, which is useful in a [RANDOMIZER][] function.
Create the next generation and place it in POPULATION of EA.
differential-evolution
)) ¶genetic-programming
)) ¶genetic-programming
)) ¶genetic-programming
)) ¶The probability of the copying reproduction
operator being chosen. Copying simply creates an exact copy of a
single individual.
differential-evolution
)) ¶Holds a function of one argument, the DE, that
returns a new individual that needs not be initialized in any way.
Typically this just calls MAKE-ARRAY.
differential-evolution
)) ¶A function of three arguments, the DE and two
individuals, that destructively modifies the second individual by
using some parts of the first one. Currently, the implemented
crossover function is CROSSOVER/BINARY.
evolutionary-algorithm
)) ¶A function of two arguments: the
EVOLUTIONARY-ALGORITHM object and an individual. It must return
the fitness of the individual. For @GPR-GP, the evaluator often
simply calls EVAL, or COMPILE + FUNCALL, and compares the result
to some gold standard. It is also typical to slightly penalize
solutions with too many nodes to control complexity and evaluation
cost (see COUNT-NODES). For @GPR-DE, individuals are
conceptually (and often implemented as) vectors of numbers so the
fitness function may include an L1 or L2 penalty term.
Alternatively, one can specify MASS-EVALUATOR instead.
evolutionary-algorithm
)) ¶A function that returns a real number for an
object returned by EVALUATOR. It is called when two fitness are to
be compared. The default value is #’IDENTITY which is sufficient
when EVALUATOR returns real numbers. However, sometimes the
evaluator returns more information about the solution (such as
fitness in various situations) and FITNESS-KEY key be used to
select the fitness value.
evolutionary-algorithm
)) ¶The fittest individual ever to be seen and its fittness as a cons cell.
evolutionary-algorithm
)) ¶evolutionary-algorithm
)) ¶If non-NIL, a function that’s called when FITTEST
is updated with three arguments: the EVOLUTIONARY-ALGORITHM
object, the fittest individual and its fitness. Useful for
tracking progress.
evolutionary-algorithm
)) ¶A counter that starts from 0 and is incremented by
ADVANCE. All accessors of EVOLUTIONARY-ALGORITHM are allowed to be
specialized on a subclass which allows them to be functions of
GENERATION-COUNTER.
genetic-programming
)) ¶genetic-programming
)) ¶If true, then the fittest individual is always
copied without mutation to the next generation. Of course, it may
also have other offsprings.
genetic-programming
)) ¶The set of [LITERAL][class]s from which (together with [OPERATOR][class]s) individuals are built.
differential-evolution
)) ¶The vector of numbers (the ’weights’) are most
often stored in some kind of array. All individuals must have the
same number of weights, but the actual representation can be
anything as long as the function in this slot mimics the semantics
of MAP-INTO that’s the default.
evolutionary-algorithm
)) ¶NIL or a function of three arguments: the
EVOLUTIONARY-ALGORITHM object, the population vector and the
fitness vector into which the fitnesses of the individuals in the
population vector shall be written. By specifying MASS-EVALUATOR
instead of an EVALUATOR, one can, for example, distribute costly
evaluations over multiple threads. MASS-EVALUATOR has precedence
over EVALUATOR.
differential-evolution
)) ¶One of the supplied mutation functions:
MUTATE/RAND/1 MUTATE/BEST/1 MUTATE/CURRENT-TO-BEST/2.
genetic-programming
)) ¶genetic-programming
)) ¶The probability of the mutation reproduction
operator being chosen. Mutation creates a randomly altered copy of
an individual. See RANDOMIZER.
genetic-programming
)) ¶The set of [OPERATOR][class]s from which (together with [LITERAL][class]s) individuals are built.
evolutionary-algorithm
)) ¶evolutionary-algorithm
)) ¶An adjustable array with a fill-pointer that holds the individuals that make up the population.
evolutionary-algorithm
)) ¶evolutionary-algorithm
)) ¶The number of individuals in a generation. This is
a very important parameter. Too low and there won’t be enough
diversity in the population, too high and convergence will be
slow.
genetic-programming
)) ¶Used for mutations, this is a function of three
arguments: the GP object, the type the expression must produce and
current expression to be replaced with the returned value. It is
called with subexpressions of individuals.
expression-class
)) ¶Expressions belonging to this expression class must evaluate to a value of this lisp type.
genetic-programming
)) ¶A function of two arguments: the GP object and a
vector of fitnesses. It must return the and index into the fitness
vector. The individual whose fitness was thus selected will be
selected for reproduction be it copying, mutation or crossover.
Typically, this defers to HOLD-TOURNAMENT.
genetic-programming
)) ¶The type of the results produced by individuals.
If the problem is to find the minimum a 1d real function then this
may be the symbol REAL. If the problem is to find the shortest
route, then this may be a vector. It all depends on the
representation of the problem, the operators and the literals.
expression-class
)) ¶The probability of an expression class to be
selected from a set of candidates is proportional to its
weight.
Differential evolution (DE) is an evolutionary
algorithm in which individuals are represented by vectors of
numbers. New individuals are created by taking linear combinations
or by randomly swapping some of these numbers between two
individuals.
The vector of numbers (the ’weights’) are most
often stored in some kind of array. All individuals must have the
same number of weights, but the actual representation can be
anything as long as the function in this slot mimics the semantics
of MAP-INTO that’s the default.
(function map-into)
:map-weights-into-fn
This slot is read-only.
Holds a function of one argument, the DE, that
returns a new individual that needs not be initialized in any way.
Typically this just calls MAKE-ARRAY.
:create-individual-fn
This slot is read-only.
One of the supplied mutation functions:
MUTATE/RAND/1 MUTATE/BEST/1 MUTATE/CURRENT-TO-BEST/2.
:mutate-fn
This slot is read-only.
A function of three arguments, the DE and two
individuals, that destructively modifies the second individual by
using some parts of the first one. Currently, the implemented
crossover function is CROSSOVER/BINARY.
(function mgl-gpr:crossover/binary)
:crossover-fn
This slot is read-only.
:autotune-fn
This slot is read-only.
The EVOLUTIONARY-ALGORITHM is an abstract base
class for generational, population based optimization algorithms.
A function of two arguments: the
EVOLUTIONARY-ALGORITHM object and an individual. It must return
the fitness of the individual. For @GPR-GP, the evaluator often
simply calls EVAL, or COMPILE + FUNCALL, and compares the result
to some gold standard. It is also typical to slightly penalize
solutions with too many nodes to control complexity and evaluation
cost (see COUNT-NODES). For @GPR-DE, individuals are
conceptually (and often implemented as) vectors of numbers so the
fitness function may include an L1 or L2 penalty term.
Alternatively, one can specify MASS-EVALUATOR instead.
:evaluator
This slot is read-only.
NIL or a function of three arguments: the
EVOLUTIONARY-ALGORITHM object, the population vector and the
fitness vector into which the fitnesses of the individuals in the
population vector shall be written. By specifying MASS-EVALUATOR
instead of an EVALUATOR, one can, for example, distribute costly
evaluations over multiple threads. MASS-EVALUATOR has precedence
over EVALUATOR.
:mass-evaluator
This slot is read-only.
A function that returns a real number for an
object returned by EVALUATOR. It is called when two fitness are to
be compared. The default value is #’IDENTITY which is sufficient
when EVALUATOR returns real numbers. However, sometimes the
evaluator returns more information about the solution (such as
fitness in various situations) and FITNESS-KEY key be used to
select the fitness value.
(function identity)
:fitness-key
This slot is read-only.
A counter that starts from 0 and is incremented by
ADVANCE. All accessors of EVOLUTIONARY-ALGORITHM are allowed to be
specialized on a subclass which allows them to be functions of
GENERATION-COUNTER.
0
This slot is read-only.
The number of individuals in a generation. This is
a very important parameter. Too low and there won’t be enough
diversity in the population, too high and convergence will be
slow.
:population-size
The fittest individual ever to be seen and its fittness as a cons cell.
This slot is read-only.
If non-NIL, a function that’s called when FITTEST
is updated with three arguments: the EVOLUTIONARY-ALGORITHM
object, the fittest individual and its fitness. Useful for
tracking progress.
:fittest-changed-fn
An adjustable array with a fill-pointer that holds the individuals that make up the population.
(make-array 0 :adjustable 0 :fill-pointer t)
An object of EXPRESSION-CLASS defines two things:
how to build a random expression that belongs to that expression
class and what lisp type those expressions evaluate to.
Expressions belonging to this expression class must evaluate to a value of this lisp type.
:result-type
This slot is read-only.
The GENETIC-PROGRAMMING class defines the search
space, how mutation and recombination occur, and hold various
parameters of the evolutionary process and the individuals
themselves.
The set of [OPERATOR][class]s from which (together with [LITERAL][class]s) individuals are built.
:operators
This slot is read-only.
The set of [LITERAL][class]s from which (together with [OPERATOR][class]s) individuals are built.
:literals
This slot is read-only.
The type of the results produced by individuals.
If the problem is to find the minimum a 1d real function then this
may be the symbol REAL. If the problem is to find the shortest
route, then this may be a vector. It all depends on the
representation of the problem, the operators and the literals.
t
:toplevel-type
This slot is read-only.
Used for mutations, this is a function of three
arguments: the GP object, the type the expression must produce and
current expression to be replaced with the returned value. It is
called with subexpressions of individuals.
:randomizer
This slot is read-only.
A function of two arguments: the GP object and a
vector of fitnesses. It must return the and index into the fitness
vector. The individual whose fitness was thus selected will be
selected for reproduction be it copying, mutation or crossover.
Typically, this defers to HOLD-TOURNAMENT.
:selector
This slot is read-only.
The probability of the copying reproduction
operator being chosen. Copying simply creates an exact copy of a
single individual.
0
:copy-chance
The probability of the mutation reproduction
operator being chosen. Mutation creates a randomly altered copy of
an individual. See RANDOMIZER.
0
:mutation-chance
If true, then the fittest individual is always
copied without mutation to the next generation. Of course, it may
also have other offsprings.
t
:keep-fittest-p
This is slightly misnamed. An object belonging to
the LITERAL class is not a literal itself, it’s a factory for
literals via its [BUILDER][] function. For example, the following
literal builds bytes:
(make-instance ’literal
:result-type ’(unsigned-byte 8)
:builder (lambda () (random 256)))
In practice, one rarely writes it out like that, because the LITERAL macro provides a more convenient shorthand.
Defines how the symbol NAME in the function
position of a list can be combined arguments: how many and of what
types. The following defines [‘+‘][dislocated] as an operator that
adds two ‘FLOAT‘s:
(make-instance ’operator
:name ’+
:result-type float
:argument-types ’(float float))
See the macro [OPERATOR][macro] for a shorthand for the above.
Currently no lambda list keywords are supported and there is no way to define how an expression with a particular operator is to be built. See RANDOM-EXPRESSION.
A symbol that’s the name of the operator.
:name
name
.
This slot is read-only.
A list of lisp types. One for each argument of this operator.
:argument-types
This slot is read-only.
SaNSDE is a special DE that dynamically adjust the
crossover and mutation are performed. The only parameters are the
generic EA ones: POPULATION-SIZE, EVALUATOR, etc. One also has to
specify MAP-WEIGHTS-INTO-FN and CREATE-INDIVIDUAL-FN.
0.5
0.5
0.5
(quote mgl-gpr::mutate/sansde)
(quote mgl-gpr::crossover/sansde)
(quote mgl-gpr::tune/sansde)
Return a double float of zero mean and unit variance.
Insert ITEM into VECTOR while keeping it sorted by TEST. Extend the vector if needed. Drop the first element if the size of the vector would be more than MAX-LENGTH.
Return the maximum value (according to TEST) in VECTOR and its index.
Choose an element randomly from the [START,END) subsequence of SEQ with given probabilities. KEY returns the unormalized probability of an element, SUM is the sum of these unnormalized probalities contains unnormalized probabilties. Return the element chosen and its index.
Return the sum of elements in the [START,END) subsequence of SEQ.
differential-evolution
)) ¶automatically generated reader method
evolutionary-algorithm
)) ¶automatically generated reader method
evolutionary-algorithm
)) ¶automatically generated writer method
evolutionary-algorithm
)) ¶automatically generated reader method
evolutionary-algorithm
)) ¶automatically generated writer method
Jump to: | (
A B C D E F G H I K L M N O P R S T U W |
---|
Jump to: | (
A B C D E F G H I K L M N O P R S T U W |
---|
Jump to: | @
A B C E F G K L M N O P R S T W |
---|
Jump to: | @
A B C E F G K L M N O P R S T W |
---|
Jump to: | C D E F G L M O P S T U |
---|
Jump to: | C D E F G L M O P S T U |
---|