org.apache.commons.math3.analysis.solvers.UnivariateSolver Java Examples

The following examples show how to use org.apache.commons.math3.analysis.solvers.UnivariateSolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InversePowerLawLearningCurve.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public double getConvergenceValue() {
	UnivariateSolver solver = new BrentSolver(0, 1.0d);
	double convergencePoint = -1;
	int upperIntervalBound = 10000;
	int retriesLeft = 8;
	while (retriesLeft > 0 && convergencePoint == -1) {
		try {
			convergencePoint = solver.solve(1000, x -> this.getDerivativeCurveValue(x) - 0.0000001, 1, upperIntervalBound);
		} catch (NoBracketingException e) {
			this.logger.warn(String.format("No solution could be found in interval [1,%d]", upperIntervalBound));
			retriesLeft--;
			upperIntervalBound *= 2;
		}
	}
	if (convergencePoint == -1) {
		throw new IllegalStateException(String.format("No solution could be found in interval [1,%d]", upperIntervalBound));
	}
	return this.getCurveValue(convergencePoint);
}
 
Example #2
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #3
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    expandable        = null;
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #4
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #5
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    expandable        = null;
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #6
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #7
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    expandable        = null;
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #8
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #9
Source File: EventState.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Simple constructor.
 * @param handler event handler
 * @param maxCheckInterval maximal time interval between switching
 * function checks (this interval prevents missing sign changes in
 * case the integration steps becomes very large)
 * @param convergence convergence threshold in the event time search
 * @param maxIterationCount upper limit of the iteration count in
 * the event time search
 * @param solver Root-finding algorithm to use to detect state events
 */
public EventState(final EventHandler handler, final double maxCheckInterval,
                  final double convergence, final int maxIterationCount,
                  final UnivariateSolver solver) {
    this.handler           = handler;
    this.maxCheckInterval  = maxCheckInterval;
    this.convergence       = FastMath.abs(convergence);
    this.maxIterationCount = maxIterationCount;
    this.solver            = solver;

    // some dummy values ...
    expandable        = null;
    t0                = Double.NaN;
    g0                = Double.NaN;
    g0Positive        = true;
    pendingEvent      = false;
    pendingEventTime  = Double.NaN;
    previousEventTime = Double.NaN;
    increasing        = true;
    nextAction        = EventHandler.Action.CONTINUE;

}
 
Example #10
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #11
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the β parameter,
 * must be one of {@link Formula#FLETCHER_REEVES} or
 * {@link Formula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final Formula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1;
}
 
Example #12
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link ConjugateGradientFormula#FLETCHER_REEVES} or {@link
 * ConjugateGradientFormula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1.0;
}
 
Example #13
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #14
Source File: GraggBulirschStoerIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addEventHandler(final EventHandler function,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
  super.addEventHandler(function, maxCheckInterval, convergence,
                        maxIterationCount, solver);

  // reinitialize the arrays
  initializeArrays();

}
 
Example #15
Source File: GraggBulirschStoerIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addEventHandler(final EventHandler function,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
  super.addEventHandler(function, maxCheckInterval, convergence,
                        maxIterationCount, solver);

  // reinitialize the arrays
  initializeArrays();

}
 
Example #16
Source File: GraggBulirschStoerIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addEventHandler(final EventHandler function,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
  super.addEventHandler(function, maxCheckInterval, convergence,
                        maxIterationCount, solver);

  // reinitialize the arrays
  initializeArrays();

}
 
Example #17
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #18
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link ConjugateGradientFormula#FLETCHER_REEVES} or {@link
 * ConjugateGradientFormula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1.0;
}
 
Example #19
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link ConjugateGradientFormula#FLETCHER_REEVES} or {@link
 * ConjugateGradientFormula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1.0;
}
 
Example #20
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link Formula#FLETCHER_REEVES} or
 * {@link Formula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 * @deprecated as of 3.3. Please use
 * {@link #NonLinearConjugateGradientOptimizer(Formula,ConvergenceChecker,double,double,double,Preconditioner)} instead.
 */
@Deprecated
public NonLinearConjugateGradientOptimizer(final Formula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    this(updateFormula,
         checker,
         lineSearchSolver.getRelativeAccuracy(),
         lineSearchSolver.getAbsoluteAccuracy(),
         lineSearchSolver.getAbsoluteAccuracy(),
         preconditioner);
}
 
Example #21
Source File: RootFindingUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUnivariateSolverSolver_thenCorrect() {
    final UnivariateFunction function = v -> Math.pow(v, 2) - 2;
    UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-8, 5);
    double c = solver.solve(100, function, -10.0, 10.0, 0);

    Assert.assertEquals(-Math.sqrt(2), c, 1e-7);
}
 
Example #22
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link Formula#FLETCHER_REEVES} or
 * {@link Formula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final Formula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1;
}
 
Example #23
Source File: GraggBulirschStoerIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addEventHandler(final EventHandler function,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
  super.addEventHandler(function, maxCheckInterval, convergence,
                        maxIterationCount, solver);

  // reinitialize the arrays
  initializeArrays();

}
 
Example #24
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link ConjugateGradientFormula#FLETCHER_REEVES} or {@link
 * ConjugateGradientFormula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1.0;
}
 
Example #25
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #26
Source File: GraggBulirschStoerIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addEventHandler(final EventHandler function,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
  super.addEventHandler(function, maxCheckInterval, convergence,
                        maxIterationCount, solver);

  // reinitialize the arrays
  initializeArrays();

}
 
Example #27
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link Formula#FLETCHER_REEVES} or
 * {@link Formula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final Formula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1;
}
 
Example #28
Source File: NonLinearConjugateGradientOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param updateFormula formula to use for updating the &beta; parameter,
 * must be one of {@link ConjugateGradientFormula#FLETCHER_REEVES} or {@link
 * ConjugateGradientFormula#POLAK_RIBIERE}.
 * @param checker Convergence checker.
 * @param lineSearchSolver Solver to use during line search.
 * @param preconditioner Preconditioner.
 */
public NonLinearConjugateGradientOptimizer(final ConjugateGradientFormula updateFormula,
                                           ConvergenceChecker<PointValuePair> checker,
                                           final UnivariateSolver lineSearchSolver,
                                           final Preconditioner preconditioner) {
    super(checker);

    this.updateFormula = updateFormula;
    solver = lineSearchSolver;
    this.preconditioner = preconditioner;
    initialStep = 1.0;
}
 
Example #29
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}
 
Example #30
Source File: JGenProg2017_0030_t.java    From coming with MIT License 5 votes vote down vote up
/** {@inheritDoc} */
public void addEventHandler(final EventHandler handler,
                            final double maxCheckInterval,
                            final double convergence,
                            final int maxIterationCount,
                            final UnivariateSolver solver) {
    eventsStates.add(new EventState(handler, maxCheckInterval, convergence,
                                    maxIterationCount, solver));
}