Math-Evol
view release on metacpan or search on metacpan
This function whose reference is passed to I<text_evol>
must accept a list of text strings;
the first will contain the current values
while the others contain alternative values.
The user should then judge which of the strings produces the best result.
I<choose_best_text> must return I<($preference, $continue)> where
I<$preference> is the index of the preferred string (0, 1, etc).
The other argument I<($continue)> is set false if the user
thinks the optimal result has been arrived at;
this is I<text_evol>'s only convergence criterion.
As an example, see the script called I<ps_evol> for fine-tuning
A4 PostScript drawings which is included with this package.
=back
=head1 CONVERGENCE CRITERIA
$ec (>0.0) is the convergence test, absolute. The search is
terminated if the distance between the best and worst values
of the objective function within the last 25 trials is less
than or equal to $ec.
The absolute convergence test is suppressed if $ec is undefined.
$ed (>0.0) is the convergence test, relative. The search is
terminated if the difference between the best and worst values
of the objective function within the last 25 trials is less
than or equal to $ed multiplied by the absolute value of the
objective function.
The relative convergence test is suppressed if $ed is undefined.
These interact with two other small numbers $ea and $eb, which are
the minimum allowable step-sizes, absolute and relative respectively.
These number are set within Math::Evol as follows:
$ea = 0.00000000000001; # absolute stepsize
$eb = 0.000000001; # relative stepsize
$ec = 0.0000000000000001; # absolute error
$ed = 0.00000000001; # relative error
You can change those settings before invoking the evol subroutine, e.g.:
$Math::Evol::ea = 0.00000000000099; # absolute stepsize
$Math::Evol::eb = 0.000000042; # relative stepsize
undef $Math::Evol::ec; # disable absolute-error-criterion
$Math::Evol::ec = 0.0000000000000031; # absolute error
$Math::Evol::ed = 0.00000000067; # relative error
The most robust criterion is the maximum-cpu-time parameter $tm
=head1 LUA
In the C<lua/> subdirectory of the install directory there is
I<Evol.lua>, which is an exact translation of this Perl code into Lua.
The function names and arguments are unchanged,
except that I<text_evol> is not yet implemented.
Brief Synopsis:
local M = require 'Evol'
local function minimise(x) -- returns a number to be minimised
local sum = 1.0
for k,v in pairs(x) do sum = sum + v * v end
return sum
end
local function constrain(x)
if x[1] > 1.0 then x[1] = 1.0 -- it's a greyscale value
elseif x[1] < 0.0 then x[1] = 0.0
end
return x
end
local function choose_best(arglist)
local preference = 1; local i_arg
for i_arg=1,#arglist do
local x = arglist[i_arg]
if that_suits_me() then preference = i_arg; break end
end
local continue = true or false
return preference, continue
end
M.ed = 0.00000000067 -- relative error
local x = {3.456, 1.234, -2.345, 4.567} -- starting values
local sm = {.8, .4, .6, 1.2} -- starting step-sizes
local tm = 5.0 -- max time in seconds
-- and now...
xb,sm,fb,lf = M.evol(xb, sm, minimise, constrain, tm)
-- or
xb,sm = M.select_evol(xb, sm, choose_best, constrain)
-- not yet implemented :
-- new_text = M.text_evol(text, choose_best_text, nchoices)
=head1 AUTHOR
Peter J Billam, www.pjb.com.au/comp/contact.html
=head1 CREDITS
The strategy of adjusting the step-size to give a success rate of 0.2
comes from the work of I. Rechenberg in his
I<Optimisation of Technical Systems in Accordance with the
Principles of Biological Evolution>
(Problemata Series, Vol. 15, Verlag Fromman-Holzboog, Stuttgart 1973).
The code of I<evol> is based on the Fortran version in
I<Numerical Optimisation of Computer Models>
by Hans-Paul Schwefel, Wiley 1981, pp 104-117, 330-337,
translated into english by M.W. Finnis from
I<Numerische Optimierung von Computer-Modellen mittels der Evolutionsstrategie>
(Interdiscipliniary Systems Research, Vol. 26), Birkhaeuser Verlag, Basel 1977.
The calling interface has been greatly Perlised,
and the constraining of values has been much simplified.
=head1 SEE ALSO
The deterministic optimistation strategies can offer faster
convergence on smaller problems (say 50 or 60 variables or less)
with fairly smooth functions;
see John A.R. Williams CPAN module Math::Amoeba
( run in 1.123 second using v1.01-cache-2.11-cpan-39bf76dae61 )