Mercurial > hg > jslab
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/maths/opt/UnconstrainedConjGrad.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2000, Samer Abdallah, King's College London. + * All rights reserved. + * + * This software is provided AS iS and WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + */ + +package samer.maths.opt; +import samer.maths.*; +import samer.core.*; +import samer.core.types.*; +import samer.core.util.heavy.*; + +/** + unconstrained minimiser for smooth functions: + - ConjugateGradient + - OR Quasi-newton (using GillMurray updates) + + - Safeguarded cubic interpolation line search using gradients + */ + + +public class UnconstrainedConjGrad extends MinimiserBase +{ + ConjGrad dir; + double guess; + + public UnconstrainedConjGrad(Vec v, Functionx f) + { + super(v,f); + dir = new ConjGrad(this); + add(new VParameter( "hessian", new DoubleModel() { + public void set(double h) { dir.invhess=1/h; } + public double get() { return 1/dir.invhess; } + } )); + } + + public void stopping() {} + public void run() + { + double beta; + int i, maxiter=getMaxiter(); + boolean triedSteepest=false; + + // dir.resetHessian(1); + evaluate(); + dir.init(); + setSlope(); + // beta = vs.beta.value; + beta = initialStep(); + sig1.off(); + + for (i=0; i<maxiter; i++) { + + step(beta); + lstest.init(); + ls.run(lstest); // line search + lsiters.next(lstest.count); + steplength.next(alpha); + + if (lstest.tiny && (P2.f>=P1.f)) { + // tiny step was no good + sig1.on(); + sig2.off(); + if (gconv.isSatisfied(P1.g,this)) break; + if (triedSteepest=true) break; + sig2.on(); + + beta = this.beta.value; + + + dir.init(); // reset to steepest descent + setSlope(); + triedSteepest=true; + continue; + } + + if (xfconv.isSatisfied(this)) { break; } + + beta = nextStep(); + // beta = vs.beta.value; + dir.update(); + move(); + perIteration(); + } + + perOptimisation(i); // finishing off stuff + } +}