Mercurial > hg > jslab
view src/samer/maths/opt/ConjGrad.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * 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.*; public class ConjGrad { double[] dg; double gg, dgg; double invhess; State S; public ConjGrad(State s) { S = s; dg = new double[S.n]; invhess = 1; } public void init() { Mathx.negate(S.P1.g,S.h); Mathx.mul(S.h,invhess); S.normh=Util.maxabs(S.h); } public void update() { Mathx.sub(dg,S.P2.g,S.P1.g); gg = Mathx.norm2(S.P1.g); dgg = Mathx.dot(dg,S.P2.g); Mathx.mul(S.h,dgg/gg); Mathx.sub(S.h,S.P2.g); Mathx.mul(S.h,invhess); S.normh=Util.maxabs(S.h); double s2=Mathx.dot(S.P2.g,S.h); if (s2>0) { // Shell.trace("steepest descent"); Mathx.negate(S.P2.g,S.h); S.normh=Util.maxabs(S.h); s2=Mathx.dot(S.P2.g,S.h); } S.P2.s=s2; } }