org.apache.commons.math3.exception.MaxCountExceededException Java Examples
The following examples show how to use
org.apache.commons.math3.exception.MaxCountExceededException.
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: cardumen_two_s.java From coming with MIT License | 6 votes |
/** * Solves Phase 1 of the Simplex method. * @param tableau simple tableau for the problem * @throws MaxCountExceededException if the maximal iteration count has been exceeded * @throws UnboundedSolutionException if the model is found not to have a bounded solution * @throws NoFeasibleSolutionException if there is no feasible solution */ protected void solvePhase1(final SimplexTableau tableau) throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { // make sure we're in Phase 1 if (tableau.getNumArtificialVariables() == 0) { return; } while (!tableau.isOptimal()) { doIteration(tableau); } // if W is not zero then we have no feasible solution if (!Precision.equals(tableau.getEntry(0, tableau.getRhsOffset()), 0d, epsilon)) { throw new NoFeasibleSolutionException(); } }
Example #2
Source File: patchedMannWhitneyUTest.java From coming with MIT License | 6 votes |
/** * @param Umin smallest Mann-Whitney U value * @param n1 number of subjects in first sample * @param n2 number of subjects in second sample * @return two-sided asymptotic p-value * @throws ConvergenceException if the p-value can not be computed * due to a convergence error * @throws MaxCountExceededException if the maximum number of * iterations is exceeded */ private double calculateAsymptoticPValue(final double Umin, final int n1, final int n2) throws ConvergenceException, MaxCountExceededException { final int n1n2prod = n1 * n2; // http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation final double EU = n1n2prod / 2.0; final double VarU = (double) ((double) n1n2prod * (n1 + n2 + 1)) / 12.0; final double z = (Umin - EU) / FastMath.sqrt(VarU); final NormalDistribution standardNormal = new NormalDistribution(0, 1); return 2 * standardNormal.cumulativeProbability(z); }
Example #3
Source File: AbstractIntegrator.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public double integrate(final FirstOrderDifferentialEquations equations, final double t0, final double[] y0, final double t, final double[] y) throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { if (y0.length != equations.getDimension()) { throw new DimensionMismatchException(y0.length, equations.getDimension()); } if (y.length != equations.getDimension()) { throw new DimensionMismatchException(y.length, equations.getDimension()); } // prepare expandable stateful equations final ExpandableStatefulODE expandableODE = new ExpandableStatefulODE(equations); expandableODE.setTime(t0); expandableODE.setPrimaryState(y0); // perform integration integrate(expandableODE, t); // extract results back from the stateful equations System.arraycopy(expandableODE.getPrimaryState(), 0, y, 0, y.length); return expandableODE.getTime(); }
Example #4
Source File: Cardumen_00214_t.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public PointValuePair doOptimize() throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { final SimplexTableau tableau = new SimplexTableau(getFunction(), getConstraints(), getGoalType(), restrictToNonNegative(), epsilon, maxUlps); solvePhase1(tableau); tableau.dropPhase1Objective(); while (!tableau.isOptimal()) { doIteration(tableau); } return tableau.getSolution(); }
Example #5
Source File: 1_SimplexSolver.java From SimFix with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ @Override public PointValuePair doOptimize() throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { final SimplexTableau tableau = new SimplexTableau(getFunction(), getConstraints(), getGoalType(), restrictToNonNegative(), epsilon, maxUlps); solvePhase1(tableau); tableau.dropPhase1Objective(); while (!tableau.isOptimal()) { doIteration(tableau); } return tableau.getSolution(); }
Example #6
Source File: ThreeEighthesIntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSmallStep() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem1 pb = new TestProblem1(); double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001; FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); Assert.assertTrue(handler.getLastError() < 2.0e-13); Assert.assertTrue(handler.getMaximalValueError() < 4.0e-12); Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12); Assert.assertEquals("3/8", integ.getName()); }
Example #7
Source File: DormandPrince853IntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testVariableSteps() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { final TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = 1.0e-8; double scalRelativeTolerance = scalAbsoluteTolerance; FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); integ.addStepHandler(new VariableHandler()); double stopTime = integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); Assert.assertEquals(pb.getFinalTime(), stopTime, 1.0e-10); Assert.assertEquals("Dormand-Prince 8 (5, 3)", integ.getName()); }
Example #8
Source File: DormandPrince54IntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void handleStep(StepInterpolator interpolator, boolean isLast) throws MaxCountExceededException { ++nbSteps; for (int a = 1; a < 10; ++a) { double prev = interpolator.getPreviousTime(); double curr = interpolator.getCurrentTime(); double interp = ((10 - a) * prev + a * curr) / 10; interpolator.setInterpolatedTime(interp); double[] interpolatedY = interpolator.getInterpolatedState (); double[] theoreticalY = pb.computeTheoreticalState(interpolator.getInterpolatedTime()); double dx = interpolatedY[0] - theoreticalY[0]; double dy = interpolatedY[1] - theoreticalY[1]; double error = dx * dx + dy * dy; if (error > maxError) { maxError = error; } } if (isLast) { Assert.assertTrue(maxError < 7.0e-10); Assert.assertTrue(nbSteps < 400); } }
Example #9
Source File: JacobianMatrices.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public void computeMainStateJacobian(double t, double[] y, double[] yDot, double[][] dFdY) throws MaxCountExceededException, DimensionMismatchException { final int n = ode.getDimension(); final double[] tmpDot = new double[n]; for (int j = 0; j < n; ++j) { final double savedYj = y[j]; y[j] += hY[j]; ode.computeDerivatives(t, y, tmpDot); for (int i = 0; i < n; ++i) { dFdY[i][j] = (tmpDot[i] - yDot[i]) / hY[j]; } y[j] = savedYj; } }
Example #10
Source File: cardumen_two_s.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public PointValuePair doOptimize() throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { final SimplexTableau tableau = new SimplexTableau(getFunction(), getConstraints(), getGoalType(), restrictToNonNegative(), epsilon, maxUlps); solvePhase1(tableau); tableau.dropPhase1Objective(); while (!tableau.isOptimal()) { doIteration(tableau); } return tableau.getSolution(); }
Example #11
Source File: Arja_0080_s.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public PointValuePair doOptimize() throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { final SimplexTableau tableau = new SimplexTableau(getFunction(), getConstraints(), getGoalType(), restrictToNonNegative(), epsilon, maxUlps); solvePhase1(tableau); tableau.dropPhase1Objective(); while (!tableau.isOptimal()) { doIteration(tableau); } return tableau.getSolution(); }
Example #12
Source File: HighamHall54IntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test(expected=NumberIsTooSmallException.class) public void testMinStep() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem1 pb = new TestProblem1(); double minStep = 0.1 * (pb.getFinalTime() - pb.getInitialTime()); double maxStep = pb.getFinalTime() - pb.getInitialTime(); double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 }; double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 }; FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); Assert.fail("an exception should have been thrown"); }
Example #13
Source File: jMutRepair_0049_s.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public PointValuePair doOptimize() throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { final SimplexTableau tableau = new SimplexTableau(getFunction(), getConstraints(), getGoalType(), restrictToNonNegative(), epsilon, maxUlps); solvePhase1(tableau); tableau.dropPhase1Objective(); while (!tableau.isOptimal()) { doIteration(tableau); } return tableau.getSolution(); }
Example #14
Source File: ParameterJacobianWrapper.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public void computeParameterJacobian(double t, double[] y, double[] yDot, String paramName, double[] dFdP) throws DimensionMismatchException, MaxCountExceededException { final int n = fode.getDimension(); if (pode.isSupported(paramName)) { final double[] tmpDot = new double[n]; // compute the jacobian df/dp w.r.t. parameter final double p = pode.getParameter(paramName); final double hP = hParam.get(paramName); pode.setParameter(paramName, p + hP); fode.computeDerivatives(t, y, tmpDot); for (int i = 0; i < n; ++i) { dFdP[i] = (tmpDot[i] - yDot[i]) / hP; } pode.setParameter(paramName, p); } else { Arrays.fill(dFdP, 0, n, 0.0); } }
Example #15
Source File: EulerStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void noReset() throws MaxCountExceededException { double[] y = { 0.0, 1.0, -2.0 }; double[][] yDot = { { 1.0, 2.0, -2.0 } }; EulerStepInterpolator interpolator = new EulerStepInterpolator(); interpolator.reinitialize(new DummyIntegrator(interpolator), y, yDot, true, new EquationsMapper(0, y.length), new EquationsMapper[0]); interpolator.storeTime(0); interpolator.shift(); interpolator.storeTime(1); double[] result = interpolator.getInterpolatedState(); for (int i = 0; i < result.length; ++i) { Assert.assertTrue(FastMath.abs(result[i] - y[i]) < 1.0e-10); } }
Example #16
Source File: DormandPrince853IntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testKepler() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { final TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = 1.0e-8; double scalRelativeTolerance = scalAbsoluteTolerance; FirstOrderIntegrator integ = new DormandPrince853Integrator(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); integ.addStepHandler(new KeplerHandler(pb)); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); Assert.assertEquals(integ.getEvaluations(), pb.getCalls()); Assert.assertTrue(pb.getCalls() < 3300); }
Example #17
Source File: jMutRepair_009_s.java From coming with MIT License | 6 votes |
/** * Runs one iteration of the Simplex method on the given model. * @param tableau simple tableau for the problem * @throws MaxCountExceededException if the maximal iteration count has been exceeded * @throws UnboundedSolutionException if the model is found not to have a bounded solution */ protected void doIteration(final SimplexTableau tableau) throws MaxCountExceededException, UnboundedSolutionException { incrementIterationsCounter(); Integer pivotCol = getPivotColumn(tableau); Integer pivotRow = getPivotRow(tableau, pivotCol); if (pivotRow == null) { throw new UnboundedSolutionException(); } // set the pivot element to 1 double pivotVal = tableau.getEntry(pivotRow, pivotCol); tableau.divideRow(pivotRow, pivotVal); // set the rest of the pivot column to 0 for (int i = 0; i < tableau.getHeight(); i++) { if (i != pivotRow) { final double multiplier = tableau.getEntry(i, pivotCol); tableau.subtractRow(i, pivotRow, multiplier); } } }
Example #18
Source File: JGenProg2017_0060_t.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public PointValuePair doOptimize() throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException { final SimplexTableau tableau = new SimplexTableau(getFunction(), getConstraints(), getGoalType(), restrictToNonNegative(), epsilon, maxUlps); solvePhase1(tableau); tableau.dropPhase1Objective(); while (!tableau.isOptimal()) { doIteration(tableau); } return tableau.getSolution(); }
Example #19
Source File: AdamsBashforthIntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void backward() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem5 pb = new TestProblem5(); double range = FastMath.abs(pb.getFinalTime() - pb.getInitialTime()); FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); Assert.assertTrue(handler.getLastError() < 1.5e-8); Assert.assertTrue(handler.getMaximalValueError() < 1.5e-8); Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-16); Assert.assertEquals("Adams-Bashforth", integ.getName()); }
Example #20
Source File: HighamHall54IntegratorTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testKepler() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { final TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double[] vecAbsoluteTolerance = { 1.0e-8, 1.0e-8, 1.0e-10, 1.0e-10 }; double[] vecRelativeTolerance = { 1.0e-10, 1.0e-10, 1.0e-8, 1.0e-8 }; FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); Assert.assertEquals(0.0, handler.getMaximalValueError(), 1.5e-4); Assert.assertEquals("Higham-Hall 5(4)", integ.getName()); }
Example #21
Source File: TestUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double) */ public static boolean tTest(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2, final double alpha) throws NullArgumentException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException { return T_TEST.tTest(sampleStats1, sampleStats2, alpha); }
Example #22
Source File: ContinuousOutputModelTest.java From astor with GNU General Public License v2.0 | 5 votes |
private boolean checkAppendError(ContinuousOutputModel cm, double t0, double[] y0, double t1) throws MaxCountExceededException, MathIllegalArgumentException { try { ContinuousOutputModel otherCm = new ContinuousOutputModel(); otherCm.handleStep(buildInterpolator(t0, y0, t1), true); cm.append(otherCm); } catch(IllegalArgumentException iae) { return true; // there was an allowable error } return false; // no allowable error }
Example #23
Source File: AdamsBashforthIntegratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test(expected = MaxCountExceededException.class) public void exceedMaxEvaluations() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem1 pb = new TestProblem1(); double range = pb.getFinalTime() - pb.getInitialTime(); AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(2, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.setMaxEvaluations(650); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); }
Example #24
Source File: BaseAbstractMultivariateVectorOptimizer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Compute the objective function value. * * @param point 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[] point) { try { evaluations.incrementCount(); } catch (MaxCountExceededException e) { throw new TooManyEvaluationsException(e.getMax()); } return function.value(point); }
Example #25
Source File: GraggBulirschStoerStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void derivativesConsistency() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem3 pb = new TestProblem3(0.9); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double absTolerance = 1.0e-8; double relTolerance = 1.0e-8; GraggBulirschStoerIntegrator integ = new GraggBulirschStoerIntegrator(minStep, maxStep, absTolerance, relTolerance); StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.0e-8); }
Example #26
Source File: AdamsMoultonIntegratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIncreasingTolerance() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { int previousCalls = Integer.MAX_VALUE; for (int i = -12; i < -2; ++i) { TestProblem1 pb = new TestProblem1(); double minStep = 0; double maxStep = pb.getFinalTime() - pb.getInitialTime(); double scalAbsoluteTolerance = FastMath.pow(10.0, i); double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance; FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); // the 0.5 and 11.0 factors are only valid for this test // and has been obtained from trial and error // there is no general relation between local and global errors Assert.assertTrue(handler.getMaximalValueError() > ( 0.5 * scalAbsoluteTolerance)); Assert.assertTrue(handler.getMaximalValueError() < (11.0 * scalAbsoluteTolerance)); Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-16); int calls = pb.getCalls(); Assert.assertEquals(integ.getEvaluations(), calls); Assert.assertTrue(calls <= previousCalls); previousCalls = calls; } }
Example #27
Source File: StepNormalizerOutputTestBase.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testIncNeither() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { double[] exp = getArray(getExpInc(), getO()[0][0], getO()[0][1]); doTest(StepNormalizerMode.INCREMENT, StepNormalizerBounds.NEITHER, exp, false); }
Example #28
Source File: GraggBulirschStoerIntegratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test(expected=DimensionMismatchException.class) public void testDimensionCheck() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { TestProblem1 pb = new TestProblem1(); AdaptiveStepsizeIntegrator integrator = new GraggBulirschStoerIntegrator(0.0, 1.0, 1.0e-10, 1.0e-10); integrator.integrate(pb, 0.0, new double[pb.getDimension()+10], 1.0, new double[pb.getDimension()+10]); }
Example #29
Source File: DummyStepInterpolatorTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testNoReset() throws MaxCountExceededException { double[] y = { 0.0, 1.0, -2.0 }; DummyStepInterpolator interpolator = new DummyStepInterpolator(y, new double[y.length], true); interpolator.storeTime(0); interpolator.shift(); interpolator.storeTime(1); double[] result = interpolator.getInterpolatedState(); for (int i = 0; i < result.length; ++i) { Assert.assertTrue(FastMath.abs(result[i] - y[i]) < 1.0e-10); } }
Example #30
Source File: OverlappingEventsTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** Test for events that occur at the exact same time, but due to numerical * calculations occur very close together instead. Uses event type 1. See * {@link org.apache.commons.math3.ode.events.EventHandler#g(double, double[]) * EventHandler.g(double, double[])}. */ @Test public void testOverlappingEvents1() throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException { test(1); }