diff src/samer/maths/opt/ConstrainedConjGrad.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/ConstrainedConjGrad.java	Tue Jan 17 17:50:20 2012 +0000
@@ -0,0 +1,48 @@
+/*
+ *	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 ConstrainedConjGrad extends ConjGrad
+{
+	Constraints C;
+
+	public ConstrainedConjGrad(State s, Constraints c) {
+		super(s); C=c;
+	}
+
+	public void init() {
+		C.negate(S.P1.g,S.h);
+		C.zeroInactive(S.h);
+		S.normh=Util.maxabs(S.h);
+	}
+
+	public void update()
+	{
+		C.sub(dg,S.P2.g,S.P1.g);
+		gg  = C.dot(S.P1.g,S.P1.g);
+		dgg = C.dot(dg,S.P2.g);
+
+		C.mul(S.h,dgg/gg);
+		C.sub(S.h,S.P2.g);
+		S.normh=Util.maxabs(S.h);
+
+		double s2=C.dot(S.P2.g,S.h);
+		if (s2>0) {
+			// Shell.trace("steepest descent");
+			C.negate(S.P2.g,S.h);
+			C.zeroInactive(S.h);
+			S.normh=Util.maxabs(S.h);
+			s2=C.dot(S.P2.g,S.h);
+		}
+		S.P2.s=s2;
+	}
+}
\ No newline at end of file