/** {@inheritDoc} */ public double value(double x) { double r = x; for (int i = f.length - 1; i >= 0; i--) { r = f[i].value(r); } return r; } };
/** {@inheritDoc} */ @Override public ArrayRealVector mapToSelf(UnivariateFunction function) { for (int i = 0; i < data.length; i++) { data[i] = function.value(data[i]); } return this; }
/** {@inheritDoc} */ public double value() { final double result = f.value(arg); arg += inc; return result; } };
/** {@inheritDoc} */ public double boundedToUnbounded(final double x) { return unboundingFunction.value(x); } }
/** {@inheritDoc} */ public double unboundedToBounded(final double y) { return boundingFunction.value(y); }
/** {@inheritDoc} */ public double value(final double x) throws MathIllegalArgumentException { return function.value(x); }
/** {@inheritDoc} */ public double unboundedToBounded(final double y) { return boundingFunction.value(y); }
/** {@inheritDoc} */ public double boundedToUnbounded(final double x) { return unboundingFunction.value(x); }
/** * Returns an estimate of the integral of {@code f(x) * w(x)}, * where {@code w} is a weight function that depends on the actual * flavor of the Gauss integration scheme. * The algorithm uses the points and associated weights, as passed * to the {@link #GaussIntegrator(double[],double[]) constructor}. * * @param f Function to integrate. * @return the integral of the weighted function. */ public double integrate(UnivariateFunction f) { double s = 0; double c = 0; for (int i = 0; i < points.length; i++) { final double x = points[i]; final double w = weights[i]; final double y = w * f.value(x) - c; final double t = s + y; c = (t - s) - y; s = t; } return s; }
/** {@inheritDoc} */ public double value(final double x) throws MathIllegalArgumentException { return f.value(MathUtils.reduce(x, period, offset)); } };
/** * Check whether the interval bounds bracket a root. That is, if the * values at the endpoints are not equal to zero, then the function takes * opposite signs at the endpoints. * * @param function Function. * @param lower Lower endpoint. * @param upper Upper endpoint. * @return {@code true} if the function values have opposite signs at the * given points. * @throws NullArgumentException if {@code function} is {@code null}. */ public static boolean isBracketing(UnivariateFunction function, final double lower, final double upper) throws NullArgumentException { if (function == null) { throw new NullArgumentException(LocalizedFormats.FUNCTION); } final double fLo = function.value(lower); final double fHi = function.value(upper); return (fLo >= 0 && fHi <= 0) || (fLo <= 0 && fHi >= 0); }
/** * Compute the objective function value. * * @param point Point at which the objective function must be evaluated. * @return the objective function value at specified point. * @throws TooManyEvaluationsException if the maximal number of evaluations is exceeded. */ protected double computeDerivativeObjectiveValue(double point) throws TooManyEvaluationsException { incrementEvaluationCount(); return functionDerivative.value(point); }
/** * Compute the objective function value. * * @param point Point at which the objective function must be evaluated. * @return the objective function value at specified point. * @throws TooManyEvaluationsException if the maximal number of evaluations * is exceeded. */ protected double computeObjectiveValue(double point) throws TooManyEvaluationsException { incrementEvaluationCount(); return function.value(point); }
/** * Computes the objective function value. * This method <em>must</em> be called by subclasses to enforce the * evaluation counter limit. * * @param x Point at which the objective function must be evaluated. * @return the objective function value at the specified point. * @throws TooManyEvaluationsException if the maximal number of * evaluations is exceeded. */ protected double computeObjectiveValue(double x) { super.incrementEvaluationCount(); return function.value(x); } }
/** * Find the upper bound b ensuring bracketing of a root between a and b. * * @param f function whose root must be bracketed. * @param a lower bound of the interval. * @param h initial step to try. * @return b such that f(a) and f(b) have opposite signs. * @throws MathIllegalStateException if no bracket can be found. */ private double findUpperBound(final UnivariateFunction f, final double a, final double h) { final double yA = f.value(a); double yB = yA; for (double step = h; step < Double.MAX_VALUE; step *= FastMath.max(2, yA / yB)) { final double b = a + step; yB = f.value(b); if (yA * yB <= 0) { return b; } } throw new MathIllegalStateException(LocalizedFormats.UNABLE_TO_BRACKET_OPTIMUM_IN_LINE_SEARCH); }