view src/samer/maths/opt/ConstrainedGillMurray.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 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));
	}
}