Mercurial > hg > jslab
comparison src/samer/maths/opt/UnconstrainedConjGrad.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
3 * All rights reserved. | |
4 * | |
5 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
6 * without even the implied warranty of MERCHANTABILITY or | |
7 * FITNESS FOR A PARTICULAR PURPOSE. | |
8 */ | |
9 | |
10 package samer.maths.opt; | |
11 import samer.maths.*; | |
12 import samer.core.*; | |
13 import samer.core.types.*; | |
14 import samer.core.util.heavy.*; | |
15 | |
16 /** | |
17 unconstrained minimiser for smooth functions: | |
18 - ConjugateGradient | |
19 - OR Quasi-newton (using GillMurray updates) | |
20 | |
21 - Safeguarded cubic interpolation line search using gradients | |
22 */ | |
23 | |
24 | |
25 public class UnconstrainedConjGrad extends MinimiserBase | |
26 { | |
27 ConjGrad dir; | |
28 double guess; | |
29 | |
30 public UnconstrainedConjGrad(Vec v, Functionx f) | |
31 { | |
32 super(v,f); | |
33 dir = new ConjGrad(this); | |
34 add(new VParameter( "hessian", new DoubleModel() { | |
35 public void set(double h) { dir.invhess=1/h; } | |
36 public double get() { return 1/dir.invhess; } | |
37 } )); | |
38 } | |
39 | |
40 public void stopping() {} | |
41 public void run() | |
42 { | |
43 double beta; | |
44 int i, maxiter=getMaxiter(); | |
45 boolean triedSteepest=false; | |
46 | |
47 // dir.resetHessian(1); | |
48 evaluate(); | |
49 dir.init(); | |
50 setSlope(); | |
51 // beta = vs.beta.value; | |
52 beta = initialStep(); | |
53 sig1.off(); | |
54 | |
55 for (i=0; i<maxiter; i++) { | |
56 | |
57 step(beta); | |
58 lstest.init(); | |
59 ls.run(lstest); // line search | |
60 lsiters.next(lstest.count); | |
61 steplength.next(alpha); | |
62 | |
63 if (lstest.tiny && (P2.f>=P1.f)) { | |
64 // tiny step was no good | |
65 sig1.on(); | |
66 sig2.off(); | |
67 if (gconv.isSatisfied(P1.g,this)) break; | |
68 if (triedSteepest=true) break; | |
69 sig2.on(); | |
70 | |
71 beta = this.beta.value; | |
72 | |
73 | |
74 dir.init(); // reset to steepest descent | |
75 setSlope(); | |
76 triedSteepest=true; | |
77 continue; | |
78 } | |
79 | |
80 if (xfconv.isSatisfied(this)) { break; } | |
81 | |
82 beta = nextStep(); | |
83 // beta = vs.beta.value; | |
84 dir.update(); | |
85 move(); | |
86 perIteration(); | |
87 } | |
88 | |
89 perOptimisation(i); // finishing off stuff | |
90 } | |
91 } |