org.apache.commons.math3.exception.NumberIsTooSmallException Java Examples

The following examples show how to use org.apache.commons.math3.exception.NumberIsTooSmallException. 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: StepNormalizerOutputTestBase.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The actual step normalizer output test code, shared by all the unit
 * tests.
 *
 * @param mode the step normalizer mode to use
 * @param bounds the step normalizer bounds setting to use
 * @param expected the expected output (normalized time points)
 * @param reverse whether to reverse the integration direction
 * @throws NoBracketingException 
 * @throws MaxCountExceededException 
 * @throws NumberIsTooSmallException 
 * @throws DimensionMismatchException 
 */
private void doTest(StepNormalizerMode mode, StepNormalizerBounds bounds,
                    double[] expected, boolean reverse)
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
    // Forward test.
    FirstOrderIntegrator integ = new GraggBulirschStoerIntegrator(
                                                    1e-8, 1.0, 1e-5, 1e-5);
    integ.addStepHandler(new StepNormalizer(0.5, this, mode, bounds));
    double[] y   = {0.0};
    double start = reverse ? getEnd()   : getStart();
    double end   = reverse ? getStart() : getEnd();
    output       = new ArrayList<Double>();
    integ.integrate(this, start, y, end, y);
    double[] actual = new double[output.size()];
    for(int i = 0; i < actual.length; i++) {
        actual[i] = output.get(i);
    }
    Assert.assertArrayEquals(expected, actual, 1e-5);
}
 
Example #2
Source File: BetaDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
Example #3
Source File: BetaDistribution.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
Example #4
Source File: DormandPrince54IntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testSmallLastStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblemAbstract pb = new TestProblem5();
  double minStep = 1.25;
  double maxStep = FastMath.abs(pb.getFinalTime() - pb.getInitialTime());
  double scalAbsoluteTolerance = 6.0e-4;
  double scalRelativeTolerance = 6.0e-4;

  AdaptiveStepsizeIntegrator integ =
    new DormandPrince54Integrator(minStep, maxStep,
                                  scalAbsoluteTolerance,
                                  scalRelativeTolerance);

  DP54SmallLastHandler handler = new DP54SmallLastHandler(minStep);
  integ.addStepHandler(handler);
  integ.setInitialStepSize(1.7);
  integ.integrate(pb,
                  pb.getInitialTime(), pb.getInitialState(),
                  pb.getFinalTime(), new double[pb.getDimension()]);
  Assert.assertTrue(handler.wasLastSeen());
  Assert.assertEquals("Dormand-Prince 5(4)", integ.getName());

}
 
Example #5
Source File: DormandPrince54IntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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 DormandPrince54Integrator(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() < 2800);

}
 
Example #6
Source File: MidpointIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testSmallStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem1 pb  = new TestProblem1();
  double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.001;

  FirstOrderIntegrator integ = new MidpointIntegrator(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-7);
  Assert.assertTrue(handler.getMaximalValueError() < 1.0e-6);
  Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
  Assert.assertEquals("midpoint", integ.getName());

}
 
Example #7
Source File: ClassicalRungeKuttaIntegratorTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testBigStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

  TestProblem1 pb = new TestProblem1();
  double step = (pb.getFinalTime() - pb.getInitialTime()) * 0.2;

  FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(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() > 0.0004);
  Assert.assertTrue(handler.getMaximalValueError() > 0.005);
  Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

}
 
Example #8
Source File: AdaptiveStepsizeIntegrator.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void sanityChecks(final ExpandableStatefulODE equations, final double t)
    throws DimensionMismatchException, NumberIsTooSmallException {

    super.sanityChecks(equations, t);

    mainSetDimension = equations.getPrimaryMapper().getDimension();

    if ((vecAbsoluteTolerance != null) && (vecAbsoluteTolerance.length != mainSetDimension)) {
        throw new DimensionMismatchException(mainSetDimension, vecAbsoluteTolerance.length);
    }

    if ((vecRelativeTolerance != null) && (vecRelativeTolerance.length != mainSetDimension)) {
        throw new DimensionMismatchException(mainSetDimension, vecRelativeTolerance.length);
    }

}
 
Example #9
Source File: NeuronString.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor with restricted access, solely used for deserialization.
 *
 * @param wrap Whether to wrap the dimension (i.e the first and last
 * neurons will be linked together).
 * @param featuresList Arrays that will initialize the features sets of
 * the network's neurons.
 * @throws NumberIsTooSmallException if {@code num < 2}.
 */
NeuronString(boolean wrap,
             double[][] featuresList) {
    size = featuresList.length;

    if (size < 2) {
        throw new NumberIsTooSmallException(size, 2, true);
    }

    this.wrap = wrap;

    final int fLen = featuresList[0].length;
    network = new Network(0, fLen);
    identifiers = new long[size];

    // Add neurons.
    for (int i = 0; i < size; i++) {
        identifiers[i] = network.createNeuron(featuresList[i]);
    }

    // Add links.
    createLinks();
}
 
Example #10
Source File: GaussianCurveFitter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs instance with the specified observed points.
 *
 * @param observations Observed points from which to guess the
 * parameters of the Gaussian.
 * @throws NullArgumentException if {@code observations} is
 * {@code null}.
 * @throws NumberIsTooSmallException if there are less than 3
 * observations.
 */
public ParameterGuesser(Collection<WeightedObservedPoint> observations) {
    if (observations == null) {
        throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
    }
    if (observations.size() < 3) {
        throw new NumberIsTooSmallException(observations.size(), 3, true);
    }

    final List<WeightedObservedPoint> sorted = sortObservations(observations);
    final double[] params = basicGuess(sorted.toArray(new WeightedObservedPoint[0]));

    norm = params[0];
    mean = params[1];
    sigma = params[2];
}
 
Example #11
Source File: ListPopulationTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test(expected=NumberIsTooSmallException.class)
public void testSetPopulationLimitTooSmall() {
    final ArrayList<Chromosome> chromosomes = new ArrayList<Chromosome> ();
    chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
    chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));
    chromosomes.add(new DummyBinaryChromosome(BinaryChromosome.randomBinaryRepresentation(3)));

    final ListPopulation population = new ListPopulation(chromosomes, 3) {
        public Population nextGeneration() {
            // not important
            return null;
        }
    };

    population.setPopulationLimit(2);
}
 
Example #12
Source File: FirstOrderConverterTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDecreasingSteps()
    throws DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException, NoBracketingException {

  double previousError = Double.NaN;
  for (int i = 0; i < 10; ++i) {

    double step  = FastMath.pow(2.0, -(i + 1));
    double error = integrateWithSpecifiedStep(4.0, 0.0, 1.0, step)
                 - FastMath.sin(4.0);
    if (i > 0) {
      Assert.assertTrue(FastMath.abs(error) < FastMath.abs(previousError));
    }
    previousError = error;

  }
}
 
Example #13
Source File: Array2DRowFieldMatrix.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public T walkInColumnOrder(final FieldMatrixChangingVisitor<T> visitor,
                           final int startRow, final int endRow,
                           final int startColumn, final int endColumn)
    throws OutOfRangeException, NumberIsTooSmallException {
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
    visitor.start(getRowDimension(), getColumnDimension(),
                  startRow, endRow, startColumn, endColumn);
    for (int j = startColumn; j <= endColumn; ++j) {
        for (int i = startRow; i <= endRow; ++i) {
            final T[] rowI = data[i];
            rowI[j] = visitor.visit(i, j, rowI[j]);
        }
    }
    return visitor.end();
}
 
Example #14
Source File: PowellOptimizer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This constructor allows to specify a user-defined convergence checker,
 * in addition to the parameters that control the default convergence
 * checking procedure and the line search tolerances.
 *
 * @param rel Relative threshold for this optimizer.
 * @param abs Absolute threshold for this optimizer.
 * @param lineRel Relative threshold for the internal line search optimizer.
 * @param lineAbs Absolute threshold for the internal line search optimizer.
 * @param checker Convergence checker.
 * @throws NotStrictlyPositiveException if {@code abs <= 0}.
 * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}.
 */
public PowellOptimizer(double rel,
                       double abs,
                       double lineRel,
                       double lineAbs,
                       ConvergenceChecker<PointValuePair> checker) {
    super(checker);

    if (rel < MIN_RELATIVE_TOLERANCE) {
        throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true);
    }
    if (abs <= 0) {
        throw new NotStrictlyPositiveException(abs);
    }
    relativeThreshold = rel;
    absoluteThreshold = abs;

    // Create the line search optimizer.
    line = new LineSearch(lineRel,
                          lineAbs);
}
 
Example #15
Source File: MatrixUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if submatrix ranges indices are valid.
 * Rows and columns are indicated counting from 0 to {@code n - 1}.
 *
 * @param m Matrix.
 * @param startRow Initial row index.
 * @param endRow Final row index.
 * @param startColumn Initial column index.
 * @param endColumn Final column index.
 * @throws OutOfRangeException if the indices are invalid.
 * @throws NumberIsTooSmallException if {@code endRow < startRow} or
 * {@code endColumn < startColumn}.
 */
public static void checkSubMatrixIndex(final AnyMatrix m,
                                       final int startRow, final int endRow,
                                       final int startColumn, final int endColumn)
    throws NumberIsTooSmallException, OutOfRangeException {
    checkRowIndex(m, startRow);
    checkRowIndex(m, endRow);
    if (endRow < startRow) {
        throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_ROW_AFTER_FINAL_ROW,
                                            endRow, startRow, false);
    }

    checkColumnIndex(m, startColumn);
    checkColumnIndex(m, endColumn);
    if (endColumn < startColumn) {
        throw new NumberIsTooSmallException(LocalizedFormats.INITIAL_COLUMN_AFTER_FINAL_COLUMN,
                                            endColumn, startColumn, false);
    }


}
 
Example #16
Source File: ThreeEighthesIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=DimensionMismatchException.class)
public void testDimensionCheck()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
    TestProblem1 pb = new TestProblem1();
    new ThreeEighthesIntegrator(0.01).integrate(pb,
                                                0.0, new double[pb.getDimension()+10],
                                                1.0, new double[pb.getDimension()+10]);
      Assert.fail("an exception should have been thrown");
}
 
Example #17
Source File: NeuronSquareMesh2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a two-dimensional network composed of square cells:
 * Each neuron not located on the border of the mesh has four
 * neurons linked to it.
 * <br/>
 * The links are bi-directional.
 * <br/>
 * The topology of the network can also be a cylinder (if one
 * of the dimensions is wrapped) or a torus (if both dimensions
 * are wrapped).
 *
 * @param numRows Number of neurons in the first dimension.
 * @param wrapRowDim Whether to wrap the first dimension (i.e the first
 * and last neurons will be linked together).
 * @param numCols Number of neurons in the second dimension.
 * @param wrapColDim Whether to wrap the second dimension (i.e the first
 * and last neurons will be linked together).
 * @param neighbourhoodType Neighbourhood type.
 * @param featureInit Array of functions that will initialize the
 * corresponding element of the features set of each newly created
 * neuron. In particular, the size of this array defines the size of
 * feature set.
 * @throws NumberIsTooSmallException if {@code numRows < 2} or
 * {@code numCols < 2}.
 */
public NeuronSquareMesh2D(int numRows,
                          boolean wrapRowDim,
                          int numCols,
                          boolean wrapColDim,
                          SquareNeighbourhood neighbourhoodType,
                          FeatureInitializer[] featureInit) {
    if (numRows < 2) {
        throw new NumberIsTooSmallException(numRows, 2, true);
    }
    if (numCols < 2) {
        throw new NumberIsTooSmallException(numCols, 2, true);
    }

    numberOfRows = numRows;
    wrapRows = wrapRowDim;
    numberOfColumns = numCols;
    wrapColumns = wrapColDim;
    neighbourhood = neighbourhoodType;
    identifiers = new long[numberOfRows][numberOfColumns];

    final int fLen = featureInit.length;
    network = new Network(0, fLen);

    // Add neurons.
    for (int i = 0; i < numRows; i++) {
        for (int j = 0; j < numCols; j++) {
            final double[] features = new double[fLen];
            for (int fIndex = 0; fIndex < fLen; fIndex++) {
                features[fIndex] = featureInit[fIndex].value();
            }
            identifiers[i][j] = network.createNeuron(features);
        }
    }

    // Add links.
    createLinks();
}
 
Example #18
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double tTest(final StatisticalSummary sampleStats1,
                           final StatisticalSummary sampleStats2)
    throws NullArgumentException, NumberIsTooSmallException,
    MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2);
}
 
Example #19
Source File: AbstractIntegrator.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Check the integration span.
 * @param equations set of differential equations
 * @param t target time for the integration
 * @exception NumberIsTooSmallException if integration span is too small
 * @exception DimensionMismatchException if adaptive step size integrators
 * tolerance arrays dimensions are not compatible with equations settings
 */
protected void sanityChecks(final ExpandableStatefulODE equations, final double t)
    throws NumberIsTooSmallException, DimensionMismatchException {

    final double threshold = 1000 * FastMath.ulp(FastMath.max(FastMath.abs(equations.getTime()),
                                                              FastMath.abs(t)));
    final double dt = FastMath.abs(equations.getTime() - t);
    if (dt <= threshold) {
        throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL,
                                            dt, threshold, false);
    }

}
 
Example #20
Source File: HarmonicFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Simple constructor.
 * @param observations sampled observations
 * @throws NumberIsTooSmallException if the sample is too short or if
 * the first guess cannot be computed.
 */
public ParameterGuesser(WeightedObservedPoint[] observations) {
    if (observations.length < 4) {
        throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE,
                                            observations.length, 4, true);
    }

    this.observations = observations.clone();
}
 
Example #21
Source File: Math_34_ListPopulation_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the maximal population size.
 * @param populationLimit maximal population size.
 * @throws NotPositiveException if the population limit is not a positive number (&lt; 1)
 * @throws NumberIsTooSmallException if the new population size is smaller than the current number
 * of chromosomes in the population
 */
public void setPopulationLimit(final int populationLimit) {
    if (populationLimit <= 0) {
        throw new NotPositiveException(LocalizedFormats.POPULATION_LIMIT_NOT_POSITIVE, populationLimit);
    }
    if (populationLimit < chromosomes.size()) {
        throw new NumberIsTooSmallException(populationLimit, chromosomes.size(), true);
    }
    this.populationLimit = populationLimit;
}
 
Example #22
Source File: UnivariatePeriodicInterpolatorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=NumberIsTooSmallException.class)
public void testTooFewSamples() {
    final double[] xval = { 2, 3, 7 };
    final double[] yval = { 1, 6, 5 };
    final double period = 10;

    final UnivariateInterpolator interpolator
        = new UnivariatePeriodicInterpolator(new LinearInterpolator(), period);
    interpolator.interpolate(xval, yval);
}
 
Example #23
Source File: DormandPrince853StepInterpolatorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void derivativesConsistency()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
  TestProblem3 pb = new TestProblem3(0.1);
  double minStep = 0;
  double maxStep = pb.getFinalTime() - pb.getInitialTime();
  double scalAbsoluteTolerance = 1.0e-8;
  double scalRelativeTolerance = scalAbsoluteTolerance;
  DormandPrince853Integrator integ = new DormandPrince853Integrator(minStep, maxStep,
                                                                    scalAbsoluteTolerance,
                                                                    scalRelativeTolerance);
  StepInterpolatorTestUtils.checkDerivativesConsistency(integ, pb, 1.0e-10);
}
 
Example #24
Source File: StepNormalizerOutputTestBase.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testIncBoth()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
    double[] exp = getArray(getExpInc(), getO()[6][0], getO()[6][1]);
    doTest(StepNormalizerMode.INCREMENT, StepNormalizerBounds.BOTH, exp, false);
}
 
Example #25
Source File: AdamsBashforthIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@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 #26
Source File: DormandPrince853IntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTooLargeFirstStep()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {

    AdaptiveStepsizeIntegrator integ =
            new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
    final double start = 0.0;
    final double end   = 0.001;
    FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {

        public int getDimension() {
            return 1;
        }

        public void computeDerivatives(double t, double[] y, double[] yDot) {
            Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
            Assert.assertTrue(t <= FastMath.nextAfter(end,   Double.POSITIVE_INFINITY));
            yDot[0] = -100.0 * y[0];
        }

    };

    integ.setStepSizeControl(0, 1.0, 1.0e-6, 1.0e-8);
    integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);

}
 
Example #27
Source File: ThreeEighthesIntegratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test(expected=DimensionMismatchException.class)
public void testDimensionCheck()
    throws DimensionMismatchException, NumberIsTooSmallException,
           MaxCountExceededException, NoBracketingException {
    TestProblem1 pb = new TestProblem1();
    new ThreeEighthesIntegrator(0.01).integrate(pb,
                                                0.0, new double[pb.getDimension()+10],
                                                1.0, new double[pb.getDimension()+10]);
      Assert.fail("an exception should have been thrown");
}
 
Example #28
Source File: AbstractFieldMatrix.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public T walkInOptimizedOrder(final FieldMatrixChangingVisitor<T> visitor,
                              final int startRow, final int endRow,
                              final int startColumn, final int endColumn)
    throws NumberIsTooSmallException, OutOfRangeException {
    return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
}
 
Example #29
Source File: BrentOptimizerTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testBoundaries() {
    final double lower = -1.0;
    final double upper = +1.0;
    UnivariateFunction f = new UnivariateFunction() {            
        public double value(double x) {
            if (x < lower) {
                throw new NumberIsTooSmallException(x, lower, true);
            } else if (x > upper) {
                throw new NumberIsTooLargeException(x, upper, true);
            } else {
                return x;
            }
        }
    };
    UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14);
    Assert.assertEquals(lower,
                        optimizer.optimize(new MaxEval(100),
                                           new UnivariateObjectiveFunction(f),
                                           GoalType.MINIMIZE,
                                           new SearchInterval(lower, upper)).getPoint(),
                        1.0e-8);
    Assert.assertEquals(upper,
                        optimizer.optimize(new MaxEval(100),
                                           new UnivariateObjectiveFunction(f),
                                           GoalType.MAXIMIZE,
                                           new SearchInterval(lower, upper)).getPoint(),
                        1.0e-8);
}
 
Example #30
Source File: StorelessBivariateCovariance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the current covariance estimate.
 *
 * @return the current covariance
 * @throws NumberIsTooSmallException if the number of observations
 * is &lt; 2
 */
public double getResult() throws NumberIsTooSmallException {
    if (n < 2) {
        throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_DIMENSION,
                                            n, 2, true);
    }
    if (biasCorrected) {
        return covarianceNumerator / (n - 1d);
    } else {
        return covarianceNumerator / n;
    }
}