Package org.apache.commons.math3.analysis.differentiation

Examples of org.apache.commons.math3.analysis.differentiation.MultivariateDifferentiableFunction


                return false;
            }
            final int    n = FastMath.max(1, (int) FastMath.ceil(FastMath.abs(dt) / maxCheckInterval));
            final double h = dt / n;

            final UnivariateFunction f = new UnivariateFunction() {
                public double value(final double t) throws LocalMaxCountExceededException {
                    try {
                        interpolator.setInterpolatedTime(t);
                        return handler.g(t, getCompleteState(interpolator));
                    } catch (MaxCountExceededException mcee) {
                        throw new LocalMaxCountExceededException(mcee);
                    }
                }
            };

            double ta = t0;
            double ga = g0;
            for (int i = 0; i < n; ++i) {

                // evaluate handler value at the end of the substep
                final double tb = t0 + (i + 1) * h;
                interpolator.setInterpolatedTime(tb);
                final double gb = handler.g(tb, getCompleteState(interpolator));

                // check events occurrence
                if (g0Positive ^ (gb >= 0)) {
                    // there is a sign change: an event is expected during this step

                    // variation direction, with respect to the integration direction
                    increasing = gb >= ga;

                    // find the event time making sure we select a solution just at or past the exact root
                    final double root;
                    if (solver instanceof BracketedUnivariateSolver<?>) {
                        @SuppressWarnings("unchecked")
                        BracketedUnivariateSolver<UnivariateFunction> bracketing =
                                (BracketedUnivariateSolver<UnivariateFunction>) solver;
                        root = forward ?
                               bracketing.solve(maxIterationCount, f, ta, tb, AllowedSolution.RIGHT_SIDE) :
                               bracketing.solve(maxIterationCount, f, tb, ta, AllowedSolution.LEFT_SIDE);
                    } else {
                        final double baseRoot = forward ?
                                                solver.solve(maxIterationCount, f, ta, tb) :
                                                solver.solve(maxIterationCount, f, tb, ta);
                        final int remainingEval = maxIterationCount - solver.getEvaluations();
                        BracketedUnivariateSolver<UnivariateFunction> bracketing =
                                new PegasusSolver(solver.getRelativeAccuracy(), solver.getAbsoluteAccuracy());
                        root = forward ?
                               UnivariateSolverUtils.forceSide(remainingEval, f, bracketing,
                                                                   baseRoot, ta, tb, AllowedSolution.RIGHT_SIDE) :
                               UnivariateSolverUtils.forceSide(remainingEval, f, bracketing,
                                                                   baseRoot, tb, ta, AllowedSolution.LEFT_SIDE);
                    }

                    if ((!Double.isNaN(previousEventTime)) &&
                        (FastMath.abs(root - ta) <= convergence) &&
                        (FastMath.abs(root - previousEventTime) <= convergence)) {
                        // we have either found nothing or found (again ?) a past event,
                        // retry the substep excluding this value, and taking care to have the
                        // required sign in case the g function is noisy around its zero and
                        // crosses the axis several times
                        do {
                            ta = forward ? ta + convergence : ta - convergence;
                            ga = f.value(ta);
                        } while ((g0Positive ^ (ga >= 0)) && (forward ^ (ta >= tb)));
                        --i;
                    } else if (Double.isNaN(previousEventTime) ||
                               (FastMath.abs(previousEventTime - root) > convergence)) {
                        pendingEventTime = root;
View Full Code Here


     * @deprecated this conversion method is temporary in version 3.1, as the {@link
     * DifferentiableMultivariateFunction} interface itself is deprecated
     */
    @Deprecated
    public static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(final DifferentiableMultivariateFunction f) {
        return new MultivariateDifferentiableFunction() {

            /** {@inheritDoc} */
            public double value(final double[] x) {
                return f.value(x);
            }
View Full Code Here

     * @deprecated this conversion method is temporary in version 3.1, as the {@link
     * DifferentiableMultivariateFunction} interface itself is deprecated
     */
    @Deprecated
    public static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(final DifferentiableMultivariateFunction f) {
        return new MultivariateDifferentiableFunction() {

            /** {@inheritDoc} */
            public double value(final double[] x) {
                return f.value(x);
            }
View Full Code Here

    @Test
    @Deprecated
    public void testToDifferentiableMultivariateFunction() {

        MultivariateDifferentiableFunction hypot = new MultivariateDifferentiableFunction() {
           
            public double value(double[] point) {
                return FastMath.hypot(point[0], point[1]);
            }
           
            public DerivativeStructure value(DerivativeStructure[] point) {
                return DerivativeStructure.hypot(point[0], point[1]);
            }
        };

        DifferentiableMultivariateFunction converted = FunctionUtils.toDifferentiableMultivariateFunction(hypot);
        for (double x = 0.1; x < 0.5; x += 0.01) {
            for (double y = 0.1; y < 0.5; y += 0.01) {
                double[] point = new double[] { x, y };
                Assert.assertEquals(hypot.value(point), converted.value(point), 1.0e-10);
                Assert.assertEquals(x / hypot.value(point), converted.gradient().value(point)[0], 1.0e-10);
                Assert.assertEquals(y / hypot.value(point), converted.gradient().value(point)[1], 1.0e-10);
            }
        }

    }
View Full Code Here

                };
            }
           
        };

        MultivariateDifferentiableFunction converted = FunctionUtils.toMultivariateDifferentiableFunction(hypot);
        for (double x = 0.1; x < 0.5; x += 0.01) {
            for (double y = 0.1; y < 0.5; y += 0.01) {
                DerivativeStructure[] t = new DerivativeStructure[] {
                    new DerivativeStructure(3, 1, x, 1.0, 2.0, 3.0 ),
                    new DerivativeStructure(3, 1, y, 4.0, 5.0, 6.0 )
                };
                DerivativeStructure h = DerivativeStructure.hypot(t[0], t[1]);
                Assert.assertEquals(h.getValue(), converted.value(t).getValue(), 1.0e-10);
                Assert.assertEquals(h.getPartialDerivative(1, 0, 0),
                                    converted.value(t).getPartialDerivative(1, 0, 0),
                                    1.0e-10);
                Assert.assertEquals(h.getPartialDerivative(0, 1, 0),
                                    converted.value(t).getPartialDerivative(0, 1, 0),
                                    1.0e-10);
                Assert.assertEquals(h.getPartialDerivative(0, 0, 1),
                                    converted.value(t).getPartialDerivative(0, 0, 1),
                                    1.0e-10);
            }
        }
    }
View Full Code Here

     * @deprecated this conversion method is temporary in version 3.1, as the {@link
     * DifferentiableMultivariateFunction} interface itself is deprecated
     */
    @Deprecated
    public static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(final DifferentiableMultivariateFunction f) {
        return new MultivariateDifferentiableFunction() {

            /** {@inheritDoc} */
            public double value(final double[] x) {
                return f.value(x);
            }
View Full Code Here

     * @deprecated this conversion method is temporary in version 3.1, as the {@link
     * DifferentiableMultivariateFunction} interface itself is deprecated
     */
    @Deprecated
    public static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(final DifferentiableMultivariateFunction f) {
        return new MultivariateDifferentiableFunction() {

            /** {@inheritDoc} */
            public double value(final double[] x) {
                return f.value(x);
            }
View Full Code Here

    @Test
    @Deprecated
    public void testToDifferentiableMultivariateFunction() {

        MultivariateDifferentiableFunction hypot = new MultivariateDifferentiableFunction() {
           
            public double value(double[] point) {
                return FastMath.hypot(point[0], point[1]);
            }
           
            public DerivativeStructure value(DerivativeStructure[] point) {
                return DerivativeStructure.hypot(point[0], point[1]);
            }
        };

        DifferentiableMultivariateFunction converted = FunctionUtils.toDifferentiableMultivariateFunction(hypot);
        for (double x = 0.1; x < 0.5; x += 0.01) {
            for (double y = 0.1; y < 0.5; y += 0.01) {
                double[] point = new double[] { x, y };
                Assert.assertEquals(hypot.value(point), converted.value(point), 1.0e-10);
                Assert.assertEquals(x / hypot.value(point), converted.gradient().value(point)[0], 1.0e-10);
                Assert.assertEquals(y / hypot.value(point), converted.gradient().value(point)[1], 1.0e-10);
            }
        }

    }
View Full Code Here

                };
            }
           
        };

        MultivariateDifferentiableFunction converted = FunctionUtils.toMultivariateDifferentiableFunction(hypot);
        for (double x = 0.1; x < 0.5; x += 0.01) {
            for (double y = 0.1; y < 0.5; y += 0.01) {
                DerivativeStructure[] t = new DerivativeStructure[] {
                    new DerivativeStructure(3, 1, x, 1.0, 2.0, 3.0 ),
                    new DerivativeStructure(3, 1, y, 4.0, 5.0, 6.0 )
                };
                DerivativeStructure h = DerivativeStructure.hypot(t[0], t[1]);
                Assert.assertEquals(h.getValue(), converted.value(t).getValue(), 1.0e-10);
                Assert.assertEquals(h.getPartialDerivative(1, 0, 0),
                                    converted.value(t).getPartialDerivative(1, 0, 0),
                                    1.0e-10);
                Assert.assertEquals(h.getPartialDerivative(0, 1, 0),
                                    converted.value(t).getPartialDerivative(0, 1, 0),
                                    1.0e-10);
                Assert.assertEquals(h.getPartialDerivative(0, 0, 1),
                                    converted.value(t).getPartialDerivative(0, 0, 1),
                                    1.0e-10);
            }
        }
    }
View Full Code Here

                        final double baseRoot = forward ?
                                                solver.solve(maxIterationCount, f, ta, tb) :
                                                solver.solve(maxIterationCount, f, tb, ta);
                        final int remainingEval = maxIterationCount - solver.getEvaluations();
                        BracketedUnivariateSolver<UnivariateFunction> bracketing =
                                new PegasusSolver(solver.getRelativeAccuracy(), solver.getAbsoluteAccuracy());
                        root = forward ?
                               UnivariateSolverUtils.forceSide(remainingEval, f, bracketing,
                                                                   baseRoot, ta, tb, AllowedSolution.RIGHT_SIDE) :
                               UnivariateSolverUtils.forceSide(remainingEval, f, bracketing,
                                                                   baseRoot, tb, ta, AllowedSolution.LEFT_SIDE);
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.analysis.differentiation.MultivariateDifferentiableFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.