Function l2RegFunction = new L2RegFunction(function, l2Cost); this.dimension = l2RegFunction.getDimension(); this.updateInfo = new UpdateInfo(this.m, this.dimension);
private void checkDimension(double[] x) { if (x.length != getDimension()) throw new IllegalArgumentException( "x's dimension is not the same as function's dimension"); } }
Function l2RegFunction = new L2RegFunction(function, l2Cost); this.dimension = l2RegFunction.getDimension(); this.updateInfo = new UpdateInfo(this.m, this.dimension);
Function l2RegFunction = new L2RegFunction(function, l2Cost); this.dimension = l2RegFunction.getDimension(); this.updateInfo = new UpdateInfo(this.m, this.dimension);
@Override public double valueAt(double[] x) { checkDimension(x); double value = f.valueAt(x); if (l2Cost > 0) { value += l2Cost * ArrayMath.innerProduct(x, x); } return value; }
@Override public double[] gradientAt(double[] x) { checkDimension(x); double[] gradient = f.gradientAt(x); if (l2Cost > 0) { for (int i = 0; i < x.length; i++) { gradient[i] += 2 * l2Cost * x[i]; } } return gradient; }
private void checkDimension(double[] x) { if (x.length != getDimension()) throw new IllegalArgumentException( "x's dimension is not the same as function's dimension"); } }
private void checkDimension(double[] x) { if (x.length != getDimension()) throw new IllegalArgumentException( "x's dimension is not the same as function's dimension"); } }
@Override public double valueAt(double[] x) { checkDimension(x); double value = f.valueAt(x); if (l2Cost > 0) { value += l2Cost * ArrayMath.innerProduct(x, x); } return value; }
@Override public double[] gradientAt(double[] x) { checkDimension(x); double[] gradient = f.gradientAt(x); if (l2Cost > 0) { for (int i = 0; i < x.length; i++) { gradient[i] += 2 * l2Cost * x[i]; } } return gradient; }
@Override public double valueAt(double[] x) { checkDimension(x); double value = f.valueAt(x); if (l2Cost > 0) { value += l2Cost * ArrayMath.innerProduct(x, x); } return value; }
@Override public double[] gradientAt(double[] x) { checkDimension(x); double[] gradient = f.gradientAt(x); if (l2Cost > 0) { for (int i = 0; i < x.length; i++) { gradient[i] += 2 * l2Cost * x[i]; } } return gradient; }