Package org.apache.commons.math

Examples of org.apache.commons.math.ConvergenceException


            Math.abs(epsilon * f[1][0] * f[1][1]))
        {
            ret = f[0][0] / f[1][0];
        } else {
            if (n >= maxIterations) {
                throw new ConvergenceException(
                    "Continued fraction convergents failed to converge.");
            }
            // compute next
            ret = evaluate(n + 1, x, f /* new a */
            , an /* reuse an */
 
View Full Code Here


public class ConvergenceExceptionTest extends TestCase {
    /**
     *
     */
    public void testConstructor(){
        ConvergenceException ex = new ConvergenceException();
        assertNull(ex.getCause());
        assertNull(ex.getMessage());
    }
View Full Code Here

    /**
     *
     */
    public void testConstructorMessage(){
        String msg = "message";
        ConvergenceException ex = new ConvergenceException(msg);
        assertNull(ex.getCause());
        assertEquals(msg, ex.getMessage());
    }
View Full Code Here

     */
    public void testConstructorMessageCause(){
        String outMsg = "outer message";
        String inMsg = "inner message";
        Exception cause = new Exception(inMsg);
        ConvergenceException ex = new ConvergenceException(outMsg, cause);
        assertEquals(outMsg, ex.getMessage());
        assertEquals(cause, ex.getCause());
    }
View Full Code Here

     *
     */
    public void testConstructorCause(){
        String inMsg = "inner message";
        Exception cause = new Exception(inMsg);
        ConvergenceException ex = new ConvergenceException(cause);
        assertEquals(cause, ex.getCause());
    }
View Full Code Here

                return result;
            }
        }

        // should never happen
        throw new ConvergenceException();
    }
View Full Code Here

            numIterations++ ;
        } while ((fa * fb > 0.0) && (numIterations < maximumIterations) &&
                ((a > lowerBound) || (b < upperBound)));

        if (fa * fb > 0.0 ) {
            throw new ConvergenceException(
                      "number of iterations={0}, maximum iterations={1}, " +
                      "initial={2}, lower bound={3}, upper bound={4}, final a value={5}, " +
                      "final b value={6}, f(a)={7}, f(b)={8}",
                      numIterations, maximumIterations, initial,
                      lowerBound, upperBound, a, b, fa, fb);
View Full Code Here

                double scaleFactor = 1d;
                double lastScaleFactor = 1d;
                final int maxPower = 5;
                final double scale = Math.max(a,b);
                if (scale <= 0) {  // Can't scale
                    throw new ConvergenceException(
                            "Continued fraction convergents diverged to +/- infinity for value {0}",
                             x);
                }
                infinite = true;
                for (int i = 0; i < maxPower; i++) {
                    lastScaleFactor = scaleFactor;
                    scaleFactor *= scale;
                    if (a != 0.0 && a > b) {
                        p2 = p1 / lastScaleFactor + (b / scaleFactor * p0);
                        q2 = q1 / lastScaleFactor + (b / scaleFactor * q0);
                    } else if (b != 0) {
                        p2 = (a / scaleFactor * p1) + p0 / lastScaleFactor;
                        q2 = (a / scaleFactor * q1) + q0 / lastScaleFactor;
                    }
                    infinite = Double.isInfinite(p2) || Double.isInfinite(q2);
                    if (!infinite) {
                        break;
                    }
                }
            }

            if (infinite) {
               // Scaling failed
               throw new ConvergenceException(
                 "Continued fraction convergents diverged to +/- infinity for value {0}",
                  x);
            }

            double r = p2 / q2;

            if (Double.isNaN(r)) {
                throw new ConvergenceException(
                  "Continued fraction diverged to NaN for value {0}",
                  x);
            }
            relativeError = Math.abs(r / c - 1.0);

View Full Code Here

                return result;
            }
        }

        // should never happen
        throw new ConvergenceException();
    }
View Full Code Here

        // null elements
        Arrays.sort(minima, pointCostPairComparator);

        // return the found point given the lowest cost
        if (minima[0] == null) {
            throw new ConvergenceException("none of the {0} start points" +
                                           " lead to convergence",
                                           new Object[] {
                                             Integer.toString(starts)
                                           });
        }
View Full Code Here

TOP

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

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.