Examples of BrentSolver


Examples of org.apache.commons.math.analysis.BrentSolver

          // there is a sign change: an event is expected during this step

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

          UnivariateRealSolver solver = new BrentSolver(new UnivariateRealFunction() {
              public double value(double t) throws FunctionEvaluationException {
                  try {
                      interpolator.setInterpolatedTime(t);
                      return function.g(t, interpolator.getInterpolatedState());
                  } catch (DerivativeException e) {
                      throw new FunctionEvaluationException(t, e);
                  }
              }
          });
          solver.setAbsoluteAccuracy(convergence);
          solver.setMaximalIterationCount(maxIterationCount);
          double root = solver.solve(ta, tb);
          if (Double.isNaN(previousEventTime) || (Math.abs(previousEventTime - root) > convergence)) {
              pendingEventTime = root;
              if (pendingEvent && (Math.abs(t1 - pendingEventTime) <= convergence)) {
                  // we were already waiting for this event which was
                  // found during a previous call for a step that was
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

        }, new double[] { 32, 23, 33, 31 });
        NonLinearConjugateGradientOptimizer optimizer =
            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
        optimizer.setMaxIterations(100);
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-13, 1.0e-13));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-15);
        solver.setRelativeAccuracy(1.0e-15);
        optimizer.setLineSearchSolver(solver);
        RealPointValuePair optimum1 =
            optimizer.optimize(problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 });
        assertEquals(1.0, optimum1.getPoint()[0], 1.0e-5);
        assertEquals(1.0, optimum1.getPoint()[1], 1.0e-5);
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

        circle.addPoint( 45.097.0);
        NonLinearConjugateGradientOptimizer optimizer =
            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
        optimizer.setMaxIterations(100);
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-30, 1.0e-30));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-13);
        solver.setRelativeAccuracy(1.0e-15);
        optimizer.setLineSearchSolver(solver);
        RealPointValuePair optimum =
            optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

  @Internal
  public static DoubleVector zeroin2(@Current Context context, @Current Environment rho, Function fn,
                             double lower, double upper, double fLower, double fUpper,
           double tol, int maximumIterations) {

    BrentSolver solver = new BrentSolver(maximumIterations, tol);

    double root;
    int iterations;
    double estimatedPrecision = DoubleVector.EPSILON; // not exposed by commons math impl

    try {
      root = solver.solve(maximumIterations, new UnivariateRealClosure(context, rho, fn), lower, upper);
      iterations = 1; // the Commons math impl doesn't expose this
    } catch (MaxIterationsExceededException e) {
      root = DoubleVector.NA;
      iterations = -1;
    } catch (FunctionEvaluationException e) {
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

                            } catch (EventException e) {
                                throw new EmbeddedEventException(e);
                            }
                        }
                    };
                    final BrentSolver solver = new BrentSolver(convergence);

                    if (ga * gb >= 0) {
                        // this is a corner case:
                        // - there was an event near ta,
                        // - there is another event between ta and tb
                        // - when ta was computed, convergence was reached on the "wrong side" of the interval
                        // this implies that the real sign of ga is the same as gb, so we need to slightly
                        // shift ta to make sure ga and gb get opposite signs and the solver won't complain
                        // about bracketing
                        final double epsilon = (forward ? 0.25 : -0.25) * convergence;
                        for (int k = 0; (k < 4) && (ga * gb > 0); ++k) {
                            ta += epsilon;
                            try {
                                ga = f.value(ta);
                            } catch (FunctionEvaluationException ex) {
                                throw new DerivativeException(ex);
                            }
                        }
                        if (ga * gb > 0) {
                            // this should never happen
                            throw new MathInternalError();
                        }
                    }

                    final double root;
                    try {
                        root = (ta <= tb) ?
                                solver.solve(maxIterationCount, f, ta, tb) :
                                    solver.solve(maxIterationCount, f, tb, ta);
                    } catch (FunctionEvaluationException ex) {
                        throw new DerivativeException(ex);
                    }

                    if ((!Double.isNaN(previousEventTime)) &&
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

        }, new double[] { 32, 23, 33, 31 });
        NonLinearConjugateGradientOptimizer optimizer =
            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
        optimizer.setMaxIterations(100);
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-13, 1.0e-13));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-15);
        solver.setRelativeAccuracy(1.0e-15);
        optimizer.setLineSearchSolver(solver);
        RealPointValuePair optimum1 =
            optimizer.optimize(problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 });
        assertEquals(1.0, optimum1.getPoint()[0], 1.0e-5);
        assertEquals(1.0, optimum1.getPoint()[1], 1.0e-5);
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

        circle.addPoint( 45.097.0);
        NonLinearConjugateGradientOptimizer optimizer =
            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
        optimizer.setMaxIterations(100);
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-30, 1.0e-30));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-13);
        solver.setRelativeAccuracy(1.0e-15);
        optimizer.setLineSearchSolver(solver);
        RealPointValuePair optimum =
            optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        Point2D.Double center = new Point2D.Double(optimum.getPointRef()[0], optimum.getPointRef()[1]);
        assertEquals(69.960161753, circle.getRadius(center), 1.0e-8);
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

            // initialization
            if (preconditioner == null) {
                preconditioner = new IdentityPreconditioner();
            }
            if (solver == null) {
                solver = new BrentSolver();
            }
            final int n = point.length;
            double[] r = computeObjectiveGradient(point);
            if (goal == GoalType.MINIMIZE) {
                for (int i = 0; i < n; ++i) {
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

        optimizer.setMaxIterations(100);
        assertEquals(100, optimizer.getMaxIterations());
        optimizer.setMaxEvaluations(100);
        assertEquals(100, optimizer.getMaxEvaluations());
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-13);
        solver.setRelativeAccuracy(1.0e-15);
        RealPointValuePair optimum =
            optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
        RealPointValuePair[] optima = optimizer.getOptima();
        for (RealPointValuePair o : optima) {
            Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]);
View Full Code Here

Examples of org.apache.commons.math.analysis.solvers.BrentSolver

        }, new double[] { 32, 23, 33, 31 });
        NonLinearConjugateGradientOptimizer optimizer =
            new NonLinearConjugateGradientOptimizer(ConjugateGradientFormula.POLAK_RIBIERE);
        optimizer.setMaxIterations(100);
        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-13, 1.0e-13));
        BrentSolver solver = new BrentSolver();
        solver.setAbsoluteAccuracy(1.0e-15);
        solver.setRelativeAccuracy(1.0e-15);
        optimizer.setLineSearchSolver(solver);
        RealPointValuePair optimum1 =
            optimizer.optimize(problem1, GoalType.MINIMIZE, new double[] { 0, 1, 2, 3 });
        assertEquals(1.0, optimum1.getPoint()[0], 1.0e-5);
        assertEquals(1.0, optimum1.getPoint()[1], 1.0e-5);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.