Package org.apache.commons.math

Examples of org.apache.commons.math.MathException


    @Override
    public UnivariateRealFunction interpolate(double[] xx, double[] yy) throws MathException{
        final int n = xx.length - 1;
        for(int i=0; i<n; i++){
            if(xx[i + 1] <= xx[i]){
                throw new MathException("xx must be strictly increasing.");
            }
        }
        return new LinearInterpolation(xx, yy);
    }
View Full Code Here


            }
            if (FastMath.abs(rootFindingFunction.value(upperBound)) < getSolverAbsoluteAccuracy()) {
                return upperBound;
            }
            // Failed bracket convergence was not because of corner solution
            throw new MathException(ex);
        }

        // find root
        double root = UnivariateRealSolverUtils.solve(rootFindingFunction,
                // override getSolverAbsoluteAccuracy() to use a Brent solver with
View Full Code Here

     */
    private double checkedCumulativeProbability(int argument) throws MathException {
        double result = Double.NaN;
            result = cumulativeProbability(argument);
        if (Double.isNaN(result)) {
            throw new MathException(LocalizedFormats.DISCRETE_CUMULATIVE_PROBABILITY_RETURNED_NAN, argument);
        }
        return result;
    }
View Full Code Here

     * @see #LoessInterpolator(double, int)
     * @since 2.1
     */
    public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) throws MathException {
        if (bandwidth < 0 || bandwidth > 1) {
            throw new MathException(LocalizedFormats.BANDWIDTH_OUT_OF_INTERVAL,
                                    bandwidth);
        }
        this.bandwidth = bandwidth;
        if (robustnessIters < 0) {
            throw new MathException(LocalizedFormats.NEGATIVE_ROBUSTNESS_ITERATIONS, robustnessIters);
        }
        this.robustnessIters = robustnessIters;
        this.accuracy = accuracy;
    }
View Full Code Here

     * @since 2.1
     */
    public final double[] smooth(final double[] xval, final double[] yval, final double[] weights)
            throws MathException {
        if (xval.length != yval.length) {
            throw new MathException(LocalizedFormats.MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS,
                                    xval.length, yval.length);
        }

        final int n = xval.length;

        if (n == 0) {
            throw new MathException(LocalizedFormats.LOESS_EXPECTS_AT_LEAST_ONE_POINT);
        }

        checkAllFiniteReal(xval, LocalizedFormats.NON_REAL_FINITE_ABSCISSA);
        checkAllFiniteReal(yval, LocalizedFormats.NON_REAL_FINITE_ORDINATE);
        checkAllFiniteReal(weights, LocalizedFormats.NON_REAL_FINITE_WEIGHT);

        checkStrictlyIncreasing(xval);

        if (n == 1) {
            return new double[]{yval[0]};
        }

        if (n == 2) {
            return new double[]{yval[0], yval[1]};
        }

        int bandwidthInPoints = (int) (bandwidth * n);

        if (bandwidthInPoints < 2) {
            throw new MathException(LocalizedFormats.TOO_SMALL_BANDWIDTH,
                                    n, 2.0 / n, bandwidth);
        }

        final double[] res = new double[n];

View Full Code Here

     * </ul>
     */
    public final double[] smooth(final double[] xval, final double[] yval)
            throws MathException {
        if (xval.length != yval.length) {
            throw new MathException(LocalizedFormats.MISMATCHED_LOESS_ABSCISSA_ORDINATE_ARRAYS,
                                    xval.length, yval.length);
        }

        final double[] unitWeights = new double[xval.length];
        Arrays.fill(unitWeights, 1.0);
View Full Code Here

    private static void checkAllFiniteReal(final double[] values, final Localizable pattern)
        throws MathException {
        for (int i = 0; i < values.length; i++) {
            final double x = values[i];
            if (Double.isInfinite(x) || Double.isNaN(x)) {
                throw new MathException(pattern, i, x);
            }
        }
    }
View Full Code Here

     */
    private static void checkStrictlyIncreasing(final double[] xval)
        throws MathException {
        for (int i = 0; i < xval.length; ++i) {
            if (i >= 1 && xval[i - 1] >= xval[i]) {
                throw new MathException(LocalizedFormats.OUT_OF_ORDER_ABSCISSA_ARRAY,
                                        i - 1, xval[i - 1], i, xval[i]);
            }
        }
    }
View Full Code Here

     * @throws MathException if it cannot successfully be transformed.
     * @see <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/Transformer.html">Commons Collections Transformer</a>
     */
    public double transform(Object o) throws MathException {
        if (o == null) {
            throw new MathException(LocalizedFormats.OBJECT_TRANSFORMATION);
        }

        if (o instanceof Number) {
            return ((Number)o).doubleValue();
        }

        try {
            return Double.valueOf(o.toString()).doubleValue();
        } catch (NumberFormatException e) {
            throw new MathException(e,
                                    LocalizedFormats.CANNOT_TRANSFORM_TO_DOUBLE, e.getMessage());
        }
    }
View Full Code Here

     * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
     */
    public double transform(Object o) throws MathException{

        if (o == null) {
            throw new MathException("Conversion Exception in Transformation, Object is null");
        }

        if (o instanceof Number) {
            return ((Number)o).doubleValue();
        }
           
        try {
            return new Double(o.toString()).doubleValue();
        } catch (Exception e) {
            throw new MathException("Conversion Exception in Transformation: " + e.getMessage(), e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math.MathException

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.