Mercurial > hg > jslab
diff src/samer/maths/opt/ConstrainedGillMurray.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/ConstrainedGillMurray.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,69 @@ +/* + * 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 ConstrainedGillMurray extends GillMurray +{ + State S; + Constraints C; + + public ConstrainedGillMurray(State s, Constraints c) { + super(s); S=s; C=c; + } + + public void computeHg(double [] g) + { + C.zeroInactive(S.h); + C.mul(S.h,H,g); + C.negate(S.h); + S.normh = Util.maxabs(S.h); + } + + public void steepest() { + C.negate(S.P1.g,S.h); + C.zeroInactive(S.h); + S.normh = Util.maxabs(S.h); + } + + public void resetDimension(int k) { + double [] hk=H0.getArray()[k]; + for (int i=0; i<S.n; i++) H[i][k]=H[k][i]=hk[i]; + } + + /* calculate new hessian and search direction */ + public void update() + { + // sparse subtraction and dot product + C.sub(u,S.P2.x,S.P1.x); + C.sub(v,S.P2.g,S.P1.g); + double uv = C.dot(u,v); + + if (uvCheck(uv,C.dot(u,u),C.dot(v,v))) { + C.mul(Hv,H,v); + + double a = 1/uv; + double b = a*(1+a*C.dot(v,Hv)); + + for (int k=0; k<C.m; k++) { + int i=C.active[k]; + for (int l=0; l<k; l++) { + int j=C.active[l]; + H[i][j] = H[i][j] - a*(Hv[i]*u[j]+u[i]*Hv[j]) + b*u[i]*u[j]; + H[j][i] = H[i][j]; + } + H[i][i] = H[i][i] - a*(2*Hv[i]*u[i]) + b*u[i]*u[i]; + } + } + computeHg(S.P2.g); + S.setSlope2(C.dot(S.P2.g,S.h)); + } +}