public void PartialDerivative02() { double tVal=-2; double eps=1e-5; double[] vector = {0,0,0}; TestFunction f = new TestFunction(); double der = f.GetPartialDerivativeVal(0,2,vector); Assert.IsTrue(System.Math.Abs(tVal-der)<=eps); }
public void Hessian() { double eps = 1e-5; double[] vector = {0,0,0}; double[][] result = {new double[]{10.0, 2.0, -2.0}, new double[]{ 2.0, 4.0, 2.0}, new double[]{-2.0, 2.0, 4.0}}; GeneralMatrix expectedMatrix = new GeneralMatrix(result); TestFunction f = new TestFunction(); GeneralMatrix hessian = f.CalculateHessian(vector); for (int i=0;i<3; i++) for (int j=0;j<3; j++) Assert.IsTrue(System.Math.Abs(hessian.GetElement(i,j)-expectedMatrix.GetElement(i,j))<eps); }
public void FitDFP1() { double eps = 1e-5; double rEps = eps*10; double step = 1; int itMax=50; double[] vector = {0,0,0}; double[] expVector = {1,-2,3}; TestFunction f = new TestFunction(); int dim = f.Dimension; DFP alg = new DFP(dim, vector, f, step, eps, itMax); alg.FindMinimum(); Assert.IsTrue(Diff(expVector,alg.Minimum,dim)<rEps); }