1Simplex(3)            User Contributed Perl Documentation           Simplex(3)
2
3
4

NAME

6       PDL::Opt::Simplex -- Simplex optimization routines
7

SYNOPSIS

9         use PDL::Opt::Simplex;
10
11         ($optimum,$ssize,$optval) = simplex($init,$initsize,$minsize,
12                        $maxiter,
13                        sub {evaluate_func_at($_[0])},
14                        sub {display_simplex($_[0])}
15                        );
16
17         # more involved:
18         use PDL;
19         use PDL::Opt::Simplex;
20         use Data::Dumper;
21
22         my $count = 0;
23         # find value of $x that returns a minimum
24         sub f {
25           my ($vec) = @_;
26           $count++;
27           my $x = $vec->slice('(0)');
28           # The parabola (x+3)^2 - 5 has a minima at x=-3:
29           return (($x+3)**2 - 5);
30         }
31
32         sub log {
33           my ($vec, $vals, $ssize) = @_;
34           # $vec is the array of values being optimized
35           # $vals is f($vec)
36           # $ssize is the simplex size, or roughly, how close to being converged.
37           my $x = $vec->slice('(0)');
38           # each vector element passed to log() has a min and max value.
39           # ie: x=[6 0] -> vals=[76 4]
40           # so, from above: f(6) == 76 and f(0) == 4
41           print "$count [$ssize]: $x -> $vals\n";
42         }
43
44         my $vec_initial = pdl [30];
45         my ( $vec_optimal, $ssize, $optval ) = simplex($vec_initial, 3, 1e-6, 100, \&f, \&log);
46         my $x = $vec_optimal->slice('(0)');
47         print "ssize=$ssize  opt=$x -> minima=$optval\n";
48

DESCRIPTION

50       This package implements the commonly used simplex optimization
51       algorithm. The basic idea of the algorithm is to move a "simplex" of
52       N+1 points in the N-dimensional search space according to certain
53       rules. The main benefit of the algorithm is that you do not need to
54       calculate the derivatives of your function.
55
56       $init is a 1D vector holding the initial values of the N fitted
57       parameters, $optimum is a vector holding the final solution.  $optval
58       is the evaluation of the final solution.
59
60       $initsize is the size of $init (more...)
61
62       $minsize is some sort of convergence criterion (more...)  - e.g.
63       $minsize = 1e-6
64
65       The sub is assumed to understand more than 1 dimensions and threading.
66       Its signature is 'inp(nparams); [ret]out()'. An example would be
67
68               sub evaluate_func_at {
69                       my($xv) = @_;
70                       my $x1 = $xv->slice("(0)");
71                       my $x2 = $xv->slice("(1)");
72                       return $x1**4 + ($x2-5)**4 + $x1*$x2;
73               }
74
75       Here $xv is a vector holding the current values of the parameters being
76       fitted which are then sliced out explicitly as $x1 and $x2.
77
78       $ssize gives a very very approximate estimate of how close we might be
79       - it might be miles wrong. It is the euclidean distance between the
80       best and the worst vertices. If it is not very small, the algorithm has
81       not converged.
82

FUNCTIONS

84   simplex
85       Simplex optimization routine
86
87        ($optimum,$ssize,$optval) = simplex($init,$initsize,$minsize,
88                        $maxiter,
89                        sub {evaluate_func_at($_[0])},
90                        sub {display_simplex($_[0])}
91                        );
92
93       See module "PDL::Opt::Simplex" for more information.
94

CAVEATS

96       Do not use the simplex method if your function has local minima.  It
97       will not work. Use genetic algorithms or simulated annealing or
98       conjugate gradient or momentum gradient descent.
99
100       They will not really work either but they are not guaranteed not to
101       work ;) (if you have infinite time, simulated annealing is guaranteed
102       to work but only after it has visited every point in your space).
103

SEE ALSO

105       Ron Shaffer's chemometrics web page and references therein:
106       "http://chem1.nrl.navy.mil/~shaffer/chemoweb.html".
107
108       Numerical Recipes (bla bla bla XXX ref).
109
110       The demonstration (Examples/Simplex/tsimp.pl and tsimp2.pl).
111

AUTHOR

113       Copyright(C) 1997 Tuomas J. Lukka.  All rights reserved. There is no
114       warranty. You are allowed to redistribute this software / documentation
115       under certain conditions. For details, see the file COPYING in the PDL
116       distribution. If this file is separated from the PDL distribution, the
117       copyright notice should be included in the file.
118
119
120
121perl v5.34.0                      2021-08-16                        Simplex(3)
Impressum