samer@0
|
1 /*
|
samer@0
|
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
3 * All rights reserved.
|
samer@0
|
4 *
|
samer@0
|
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
6 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
7 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
8 */
|
samer@0
|
9
|
samer@0
|
10 package samer.maths.opt;
|
samer@0
|
11 import samer.maths.*;
|
samer@0
|
12 import samer.core.*;
|
samer@0
|
13 import samer.core.util.heavy.*;
|
samer@0
|
14
|
samer@0
|
15
|
samer@0
|
16 /**
|
samer@0
|
17 unconstrained minimiser for smooth functions:
|
samer@0
|
18 - ConjugateGradient
|
samer@0
|
19 - OR Quasi-newton (using GillMurray uydates)
|
samer@0
|
20
|
samer@0
|
21 - Safeguarded cubic interpolation line search using gradients
|
samer@0
|
22 */
|
samer@0
|
23
|
samer@0
|
24
|
samer@0
|
25
|
samer@0
|
26
|
samer@0
|
27
|
samer@0
|
28 public class UnconstrainedMinimiser extends MinimiserBase
|
samer@0
|
29 {
|
samer@0
|
30 GillMurray dir;
|
samer@0
|
31 double guess;
|
samer@0
|
32
|
samer@0
|
33 /** expects to find Vec at top of stack,
|
samer@0
|
34 Functionx just below.
|
samer@0
|
35 */
|
samer@0
|
36 public UnconstrainedMinimiser(Vec v, Functionx f)
|
samer@0
|
37 {
|
samer@0
|
38 // can we rely on evaluation order here?
|
samer@0
|
39 super(v,f);
|
samer@0
|
40 dir = new GillMurray(this);
|
samer@0
|
41 add( dir.hessin.viewable());
|
samer@0
|
42 }
|
samer@0
|
43
|
samer@0
|
44 public void run()
|
samer@0
|
45 {
|
samer@0
|
46 double beta;
|
samer@0
|
47 int i, maxiter=getMaxiter();
|
samer@0
|
48 // boolean triedSteepest=false;
|
samer@0
|
49
|
samer@0
|
50 // dir.resetHessian(1);
|
samer@0
|
51 evaluate();
|
samer@0
|
52 dir.init();
|
samer@0
|
53 setSlope();
|
samer@0
|
54 // beta = beta.value;
|
samer@0
|
55 beta = initialStep();
|
samer@0
|
56 sig1.off();
|
samer@0
|
57
|
samer@0
|
58 for (i=1; i<=maxiter; i++) {
|
samer@0
|
59
|
samer@0
|
60 lstest.init();
|
samer@0
|
61 step(beta);
|
samer@0
|
62 ls.run(lstest); // line search
|
samer@0
|
63 lsiters.next(lstest.count);
|
samer@0
|
64 steplength.next(alpha);
|
samer@0
|
65
|
samer@0
|
66 if (lstest.tiny && (P2.f>=P1.f)) {
|
samer@0
|
67 // tiny step was no good
|
samer@0
|
68 sig1.on();
|
samer@0
|
69 sig2.off();
|
samer@0
|
70 if (gconv.isSatisfied(P1.g,this)) break;
|
samer@0
|
71 // if (triedSteepest=true) break;
|
samer@0
|
72 sig2.on();
|
samer@0
|
73
|
samer@0
|
74 beta = this.beta.value;
|
samer@0
|
75 // dir.steepest();
|
samer@0
|
76 dir.update();
|
samer@0
|
77 dir.init();
|
samer@0
|
78 setSlope();
|
samer@0
|
79 // triedSteepest=true;
|
samer@0
|
80 continue;
|
samer@0
|
81 }
|
samer@0
|
82
|
samer@0
|
83 if (xfconv.isSatisfied(this)) { break; }
|
samer@0
|
84
|
samer@0
|
85 // beta = beta.value;
|
samer@0
|
86 beta = nextStep();
|
samer@0
|
87 dir.update();
|
samer@0
|
88 move();
|
samer@0
|
89 perIteration();
|
samer@0
|
90 }
|
samer@0
|
91
|
samer@0
|
92 perOptimisation(i);
|
samer@0
|
93 dir.hessin.changed();
|
samer@0
|
94 }
|
samer@0
|
95 }
|