@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
@Override public double process(double x) { for( int i = 0; i < N; i++ ) { point[i] = start[i] + x*direction[i]; } return function.process(point); } }
@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
@Override public double process(double x) { for( int i = 0; i < N; i++ ) { point[i] = start[i] + x*direction[i]; } return function.process(point); } }
@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
@Override protected double cost(DMatrixRMaj x) { return functionCost.process(x.data); }
@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
@Override protected double cost(DMatrixRMaj x) { return functionCost.process(x.data); }
@Override public void process(double[] input, double[] output) { double valueOrig = function.process(input); for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // takes in account round off error double temp = x+h; h = temp-x; input[i] = temp; double perturbed = function.process(input); output[i] = (perturbed - valueOrig)/h; input[i] = x; } } }
@Override public void process(double[] input, double[] output) { double valueOrig = function.process(input); for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // takes in account round off error double temp = x+h; h = temp-x; input[i] = temp; double perturbed = function.process(input); output[i] = (perturbed - valueOrig)/h; input[i] = x; } } }
@Override public void process(double[] input, double[] output) { double temp; for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // backwards input[i] = temp = x-h; double h0 = x-temp; double backwards = function.process(input); // forward input[i] = temp = x+h; double h1 = temp-x; double forward = function.process(input); output[i] = (forward - backwards)/(h0+h1); input[i] = x; } } }
@Override public void process(double[] input, double[] output) { double temp; for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // backwards input[i] = temp = x-h; double h0 = x-temp; double backwards = function.process(input); // forward input[i] = temp = x+h; double h1 = temp-x; double forward = function.process(input); output[i] = (forward - backwards)/(h0+h1); input[i] = x; } } }
@Test public void compareToNumeric() { TestLsToNonLinearDeriv.FuncLS funcLS = new TestLsToNonLinearDeriv.FuncLS(); FunctionNtoS func = new LsToNonLinear(funcLS); double point[] = new double[]{1,2}; double output[] = new double[funcLS.getNumOfOutputsM()]; funcLS.process(point,output); double found = func.process(point); double expected = 0; for( int i = 0; i < output.length; i++ ) expected += output[i]*output[i]; assertEquals(expected, found, 1e-8); } }