Package org.apache.commons.math

Examples of org.apache.commons.math.MathException


            (Number) PropertyUtils.getProperty(
              o,
              getPropertyName()))
            .doubleValue();
        } catch (IllegalAccessException e) {
          throw new MathException(
            "IllegalAccessException in Transformation: "
              + e.getMessage(),
            e);
        } catch (InvocationTargetException e) {
          throw new MathException(
            "InvocationTargetException in Transformation: "
              + e.getMessage(),
            e);
        } catch (NoSuchMethodException e) {
          throw new MathException(
            "oSuchMethodException in Transformation: "
              + e.getMessage(),
            e);
        }
      }
View Full Code Here


    public double getResult() throws MathException {
        if (resultComputed) {
            return result;
        } else {
            // TODO: could this be an IllegalStateException instead?
            throw new MathException("No result available");
        }
    }
View Full Code Here

    public int getIterationCount() throws MathException {
        if (resultComputed) {
            return iterationCount;
        } else {
            // TODO: could this be an IllegalStateException instead?
            throw new MathException("No result available");
        }
    }
View Full Code Here

        double x0 = min;
        double x1 = max;
        double y0 = f.value(x0);
        double y1 = f.value(x1);
        if ((y0 > 0) == (y1 > 0)) {
            throw new MathException("Interval doesn't bracket a zero.");
        }
        double x2 = x0;
        double y2 = y0;
        double delta = x1 - x0;
        double oldDelta = delta;

        int i = 0;
        while (i < maximalIterationCount) {
            if (Math.abs(y2) < Math.abs(y1)) {
                x0 = x1;
                x1 = x2;
                x2 = x0;
                y0 = y1;
                y1 = y2;
                y2 = y0;
            }
            if (Math.abs(y1) <= functionValueAccuracy) {
                // Avoid division by very small values. Assume
                // the iteration has converged (the problem may
                // still be ill conditioned)
                setResult(x1, i);
                return result;
            }
            double dx = (x2 - x1);
            double tolerance =
                Math.max(relativeAccuracy * Math.abs(x1), absoluteAccuracy);
            if (Math.abs(dx) <= tolerance) {
                setResult(x1, i);
                return result;
            }
            if ((Math.abs(oldDelta) < tolerance) ||
                    (Math.abs(y0) <= Math.abs(y1))) {
                // Force bisection.
                delta = 0.5 * dx;
                oldDelta = delta;
            } else {
                double r3 = y1 / y0;
                double p;
                double p1;
                if (x0 == x2) {
                    // Linear interpolation.
                    p = dx * r3;
                    p1 = 1.0 - r3;
                } else {
                    // Inverse quadratic interpolation.
                    double r1 = y0 / y2;
                    double r2 = y1 / y2;
                    p = r3 * (dx * r1 * (r1 - r2) - (x1 - x0) * (r2 - 1.0));
                    p1 = (r1 - 1.0) * (r2 - 1.0) * (r3 - 1.0);
                }
                if (p > 0.0) {
                    p1 = -p1;
                } else {
                    p = -p;
                }
                if (2.0 * p >= 1.5 * dx * p1 - Math.abs(tolerance * p1) ||
                        p >= Math.abs(0.5 * oldDelta * p1)) {
                    // Inverse quadratic interpolation gives a value
                    // in the wrong direction, or progress is slow.
                    // Fall back to bisection.
                    delta = 0.5 * dx;
                    oldDelta = delta;
                } else {
                    oldDelta = delta;
                    delta = p / p1;
                }
            }
            // Save old X1, Y1
            x0 = x1;
            y0 = y1;
            // Compute new X1, Y1
            if (Math.abs(delta) > tolerance) {
                x1 = x1 + delta;
            } else if (dx > 0.0) {
                x1 = x1 + 0.5 * tolerance;
            } else if (dx <= 0.0) {
                x1 = x1 - 0.5 * tolerance;
            }
            y1 = f.value(x1);
            if ((y1 > 0) == (y2 > 0)) {
                x2 = x0;
                y2 = y0;
                delta = x1 - x0;
                oldDelta = delta;
            }
            i++;
        }
        throw new MathException("Maximal iteration number exceeded.");
    }
View Full Code Here

        double x0 = min;
        double x1 = max;
        double y0 = f.value(x0);
        double y1 = f.value(x1);
        if ((y0 > 0) == (y1 > 0)) {
            throw new MathException("Interval doesn't bracket a zero.");
        }
        double x2 = x0;
        double y2 = y0;
        double oldDelta = x2 - x1;
        int i = 0;
        while (i < maximalIterationCount) {
            if (Math.abs(y2) < Math.abs(y1)) {
                x0 = x1;
                x1 = x2;
                x2 = x0;
                y0 = y1;
                y1 = y2;
                y2 = y0;
            }
            if (Math.abs(y1) <= functionValueAccuracy) {
                setResult(x1, i);
                return result;
            }
            if (Math.abs(oldDelta) <
                Math.max(relativeAccuracy * Math.abs(x1), absoluteAccuracy)) {
                setResult(x1, i);
                return result;
            }
            double delta;
            if (Math.abs(y1) > Math.abs(y0)) {
                // Function value increased in last iteration. Force bisection.
                delta = 0.5 * oldDelta;
            } else {
                delta = (x0 - x1) / (1 - y0 / y1);
                if (delta / oldDelta > 1) {
                    // New approximation falls outside bracket.
                    // Fall back to bisection.
                    delta = 0.5 * oldDelta;
                }
            }
            x0 = x1;
            y0 = y1;
            x1 = x1 + delta;
            y1 = f.value(x1);
            if ((y1 > 0) == (y2 > 0)) {
                // New bracket is (x0,x1).                   
                x2 = x0;
                y2 = y0;
            }
            oldDelta = x2 - x1;
            i++;
        }
        throw new MathException("Maximal iteration number exceeded");
    }
View Full Code Here

                return m;
            }
            ++i;
        }
       
        throw new MathException("Maximal iteration number exceeded");
    }
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

     */
    public double transform(final Object o) throws MathException {
        try {
      return ((Number) org.apache.commons.beanutils.PropertyUtils.getProperty(o, getPropertyName())).doubleValue();
        } catch (IllegalAccessException e) {
      throw new MathException("IllegalAccessException in Transformation: " + e.getMessage(), e);
        } catch (InvocationTargetException e) {
      throw new MathException("InvocationTargetException in Transformation: " + e.getMessage(), e);
        } catch (NoSuchMethodException e) {
      throw new MathException("oSuchMethodException in Transformation: " + e.getMessage(), e);
        }
    }
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("bandwidth must be in the interval [0,1], but got {0}",
                                    bandwidth);
        }
        this.bandwidth = bandwidth;
        if (robustnessIters < 0) {
            throw new MathException("the number of robustness iterations must " +
                                    "be non-negative, but got {0}",
                                    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(
                    "Loess expects the abscissa and ordinate arrays " +
                    "to be of the same size, " +
                    "but got {0} abscissae and {1} ordinatae",
                    xval.length, yval.length);
        }

        final int n = xval.length;

        if (n == 0) {
            throw new MathException("Loess expects at least 1 point");
        }

        checkAllFiniteReal(xval, "all abscissae must be finite real numbers, but {0}-th is {1}");
        checkAllFiniteReal(yval, "all ordinatae must be finite real numbers, but {0}-th is {1}");
        checkAllFiniteReal(weights, "all weights must be finite real numbers, but {0}-th is {1}");

        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(
                    "the bandwidth must be large enough to " +
                    "accomodate at least 2 points. There are {0} " +
                    " data points, and bandwidth must be at least {1} " +
                    " but it is only {2}",
                    n, 2.0 / n, bandwidth);
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.