/** * Returns a MultivariateFunction h(x[]) defined by <pre> <code> * h(x[]) = combiner(...combiner(combiner(initialValue,x[0]),x[1])...),x[x.length-1]) * </code></pre> * * @param combiner Combiner function. * @param initialValue Initial value. * @return a collector function. */ public static MultivariateFunction collector(final BivariateFunction combiner, final double initialValue) { return collector(combiner, new Identity(), initialValue); }
/** * Divide each entry by the argument. * The instance is changed in-place. * * @param d Value to divide by. * @return {@code this}. */ public RealVector mapDivideToSelf(double d){ return mapToSelf(FunctionUtils.fix2ndArgument(new Divide(), d)); }
/** * {@inheritDoc} * * @throws org.apache.commons.math3.exception.NonMonotonicSequenceException * if the lower bound is greater than, or equal to the upper bound * @throws org.apache.commons.math3.exception.NotStrictlyPositiveException * if the number of sample points is negative * @throws MathIllegalArgumentException if the number of sample points is not a power of two */ public double[] transform(final UnivariateFunction f, final double min, final double max, final int n, final TransformType type) { return transform(FunctionUtils.sample(f, min, max, n), type); }
/** {@inheritDoc} * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} */ @Deprecated public UnivariateFunction derivative() { return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); }
/** {@inheritDoc} * @deprecated As of 3.1. Please use * {@link BaseAbstractMultivariateVectorOptimizer#optimize(int, * org.apache.commons.math3.analysis.MultivariateVectorFunction,OptimizationData[]) * optimize(int,MultivariateDifferentiableVectorFunction,OptimizationData...)} * instead. */ @Override @Deprecated public PointVectorValuePair optimize(int maxEval, final DifferentiableMultivariateVectorFunction f, final double[] target, final double[] weights, final double[] startPoint) { return optimizeInternal(maxEval, FunctionUtils.toMultivariateDifferentiableVectorFunction(f), new Target(target), new Weight(weights), new InitialGuess(startPoint)); }
/** * Optimize an objective function. * * @param f Objective function. * @param goalType Type of optimization goal: either * {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}. * @param startPoint Start point for optimization. * @param maxEval Maximum number of function evaluations. * @return the point/value pair giving the optimal value for objective * function. * @throws org.apache.commons.math3.exception.DimensionMismatchException * if the start point dimension is wrong. * @throws org.apache.commons.math3.exception.TooManyEvaluationsException * if the maximal number of evaluations is exceeded. * @throws org.apache.commons.math3.exception.NullArgumentException if * any argument is {@code null}. */ public PointValuePair optimize(final int maxEval, final MultivariateDifferentiableFunction f, final GoalType goalType, final double[] startPoint) { return optimizeInternal(maxEval, FunctionUtils.toDifferentiableMultivariateFunction(f), goalType, startPoint); } }
return super.optimizeInternal(maxEval, FunctionUtils.toDifferentiableMultivariateVectorFunction(f), optData);
/** {@inheritDoc} * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} */ @Deprecated public UnivariateFunction derivative() { return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); }
/** {@inheritDoc} */ @Override protected void setUp() { super.setUp(); // Reset counter. jacobianEvaluations = 0; // Square-root of the weight matrix. weightMatrixSqrt = squareRoot(getWeight()); // Store least squares problem characteristics. // XXX The conversion won't be necessary when the generic argument of // the base class becomes "MultivariateDifferentiableVectorFunction". // XXX "jF" is not strictly necessary anymore but is currently more // efficient than converting the value returned from "getObjectiveFunction()" // every time it is used. jF = FunctionUtils.toMultivariateDifferentiableVectorFunction((DifferentiableMultivariateVectorFunction) getObjectiveFunction()); // Arrays shared with "private" and "protected" methods. point = getStartPoint(); rows = getTarget().length; cols = point.length; }
/** * Optimize an objective function. * * @param f Objective function. * @param goalType Type of optimization goal: either * {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}. * @param startPoint Start point for optimization. * @param maxEval Maximum number of function evaluations. * @return the point/value pair giving the optimal value for objective * function. * @throws org.apache.commons.math3.exception.DimensionMismatchException * if the start point dimension is wrong. * @throws org.apache.commons.math3.exception.TooManyEvaluationsException * if the maximal number of evaluations is exceeded. * @throws org.apache.commons.math3.exception.NullArgumentException if * any argument is {@code null}. */ public PointValuePair optimize(final int maxEval, final MultivariateDifferentiableFunction f, final GoalType goalType, final double[] startPoint) { return optimizeInternal(maxEval, FunctionUtils.toDifferentiableMultivariateFunction(f), goalType, startPoint); } }
return super.optimizeInternal(maxEval, FunctionUtils.toDifferentiableMultivariateVectorFunction(f), optData);
/** {@inheritDoc} * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} */ @Deprecated public UnivariateFunction derivative() { return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); }
/** * {@inheritDoc} * * @throws org.apache.commons.math3.exception.NonMonotonicSequenceException * if the lower bound is greater than, or equal to the upper bound * @throws org.apache.commons.math3.exception.NotStrictlyPositiveException * if the number of sample points is negative * @throws MathIllegalArgumentException if the number of sample points is * not a power of two plus one */ public double[] transform(final UnivariateFunction f, final double min, final double max, final int n, final TransformType type) throws MathIllegalArgumentException { final double[] data = FunctionUtils.sample(f, min, max, n); return transform(data, type); }
/** * Multiply each entry. * The instance is changed in-place. * * @param d Multiplication factor. * @return {@code this}. */ public RealVector mapMultiplyToSelf(double d){ return mapToSelf(FunctionUtils.fix2ndArgument(new Multiply(), d)); }
/** * Returns a MultivariateFunction h(x[]) defined by <pre> <code> * h(x[]) = combiner(...combiner(combiner(initialValue,x[0]),x[1])...),x[x.length-1]) * </code></pre> * * @param combiner Combiner function. * @param initialValue Initial value. * @return a collector function. */ public static MultivariateFunction collector(final BivariateFunction combiner, final double initialValue) { return collector(combiner, new Identity(), initialValue); }
/** {@inheritDoc} * @deprecated As of 3.1. Please use * {@link BaseAbstractMultivariateVectorOptimizer#optimize(int, * org.apache.commons.math3.analysis.MultivariateVectorFunction,OptimizationData[]) * optimize(int,MultivariateDifferentiableVectorFunction,OptimizationData...)} * instead. */ @Override @Deprecated public PointVectorValuePair optimize(int maxEval, final DifferentiableMultivariateVectorFunction f, final double[] target, final double[] weights, final double[] startPoint) { return optimizeInternal(maxEval, FunctionUtils.toMultivariateDifferentiableVectorFunction(f), new Target(target), new Weight(weights), new InitialGuess(startPoint)); }
/** {@inheritDoc} * @deprecated as of 3.1, replaced by {@link #value(DerivativeStructure)} */ @Deprecated public UnivariateFunction derivative() { return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); }
/** * {@inheritDoc} * * This implementation enforces {@code f(x) = 0.0} at {@code x = 0.0}. * * @throws org.apache.commons.math3.exception.NonMonotonicSequenceException * if the lower bound is greater than, or equal to the upper bound * @throws org.apache.commons.math3.exception.NotStrictlyPositiveException * if the number of sample points is negative * @throws MathIllegalArgumentException if the number of sample points is not a power of two */ public double[] transform(final UnivariateFunction f, final double min, final double max, final int n, final TransformType type) { final double[] data = FunctionUtils.sample(f, min, max, n); data[0] = 0.0; return transform(data, type); }
/** * Add a value to each entry. * The instance is changed in-place. * * @param d Value to be added to each entry. * @return {@code this}. */ public RealVector mapAddToSelf(double d) { if (d != 0) { return mapToSelf(FunctionUtils.fix2ndArgument(new Add(), d)); } return this; }
/** * Returns a MultivariateFunction h(x[]) defined by <pre> <code> * h(x[]) = combiner(...combiner(combiner(initialValue,x[0]),x[1])...),x[x.length-1]) * </code></pre> * * @param combiner Combiner function. * @param initialValue Initial value. * @return a collector function. */ public static MultivariateFunction collector(final BivariateFunction combiner, final double initialValue) { return collector(combiner, new Identity(), initialValue); }