@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
public NumericalGradientFB(FunctionNtoS function, double differenceScale) { this.function = function; this.differenceScale = differenceScale; this.N = function.getNumOfInputsN(); }
@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
public CachedGradientLineFunction(FunctionNtoS function, FunctionNtoN gradient) { this.function = function; this.gradient = gradient; this.N = function.getNumOfInputsN(); currentInput = new double[N]; currentGradient = new double[N]; }
@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
public NumericalGradientForward(FunctionNtoS function, double differenceScale) { this.function = function; this.differenceScale = differenceScale; this.N = function.getNumOfInputsN(); }
@Override public double process(double x) { for( int i = 0; i < N; i++ ) { point[i] = start[i] + x*direction[i]; } return function.process(point); } }
public NumericalGradientFB(FunctionNtoS function, double differenceScale) { this.function = function; this.differenceScale = differenceScale; this.N = function.getNumOfInputsN(); }
@Override public double computeFunction() { if( cachedFunction ) return currentOutput; currentOutput = function.process(currentInput); cachedFunction = true; return currentOutput; }
public CachedGradientLineFunction(FunctionNtoS function, FunctionNtoN gradient) { this.function = function; this.gradient = gradient; this.N = function.getNumOfInputsN(); currentInput = new double[N]; currentGradient = new double[N]; }
@Override protected double cost(DMatrixRMaj x) { return functionCost.process(x.data); }
public NumericalGradientForward(FunctionNtoS function, double differenceScale) { this.function = function; this.differenceScale = differenceScale; this.N = function.getNumOfInputsN(); }
@Override protected double cost(DMatrixRMaj x) { return functionCost.process(x.data); }
@Override public void initialize(double[] initial, double ftol, double gtol) { this.initialize(initial,functionCost.getNumOfInputsN(), minimumFunctionValue); config.ftol = ftol; config.gtol = gtol; }
@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 void initialize(double[] initial, double ftol, double gtol) { this.initialize(initial,functionCost.getNumOfInputsN(), minimumFunctionValue); config.ftol = ftol; config.gtol = gtol; }
@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; } } }
public CachedNumericalGradientLineFunction(FunctionNtoS function ) { this.function = function; this.N = function.getNumOfInputsN(); this.gradient = new NumericalGradientForward(function); FunctionStoS lineFunction = new LineFunction(); this.lineDerivative = new NumericalDerivativeForward(lineFunction); currentInput = new double[N]; currentGradient = new double[N]; }
@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; } } }
public CachedNumericalGradientLineFunction(FunctionNtoS function ) { this.function = function; this.N = function.getNumOfInputsN(); this.gradient = new NumericalGradientForward(function); FunctionStoS lineFunction = new LineFunction(); this.lineDerivative = new NumericalDerivativeForward(lineFunction); currentInput = new double[N]; currentGradient = new double[N]; }