4
# Simplex Demo - Alison Offer (aro@aaocbn.aao.gov.au)
7
# this is some sort of convergence criterion
9
# max number of iterations ?
13
1: least squares gaussian fit to data + noise \n
14
32 *exp (-((x-10)/6)^2) + noise
15
2: minimise polynomial \n
16
(x-3)^2 + 2.*(x-3)*(y-2.5) + 3.*(y-2.5)^2 \n
17
Please make your choice (1 or 2):";
20
print "Please enter noise factor (small number, 0-6):";
23
# data : gaussian + noise
26
$data[$j] = 32*exp(-(($j-10)/6)**2) +
27
$factor * (rand() - 0.5);
30
# initial guess - $initsize controls the size of the initial simplex (I think)
32
$init = pdl [ 33, 9, 12 ];
36
($optimum,$ssize) = simplex($init,$initsize,$minsize,$maxiter,
37
# this sub returns the function to be minimised.
39
my $a = $xv->slice("(0)");
40
my $b = $xv->slice("(1)");
41
my $c = $xv->slice("(2)");
45
$a*exp(-(($j-$b)/$c)**2))**2;
51
$init = pdl [ 2 , 2 ];
53
($optimum,$ssize) = simplex($init,$initsize,$minsize,$maxiter,
55
my $x = $xv->slice("(0)");
56
my $y = $xv->slice("(1)");
57
return ($x-3)**2 + 2.*($x-3)*($y-2.5)
63
print "OPTIMUM = $optimum \n";
64
print "SSIZE = $ssize\n";