Package com.opengamma.analytics.math

Examples of com.opengamma.analytics.math.MathException


    for (i = 2; i <= n; i++) {
      theta[i] = a[i - 1] * theta[i - 1] - b[i - 2] * c[i - 2] * theta[i - 2];
    }

    if (theta[n] == 0.0) {
      throw new MathException("Zero determinant. Cannot invert the matrix");
    }

    phi[n - 1] = 1.0;
    phi[n - 2] = a[n - 1];
    for (i = n - 3; i >= 0; i--) {
View Full Code Here


    if (!getNextPosition(function, estimate, data)) {
      if (isConverged(data)) {
        return data.getX(); // this can happen if the starting position is the root
      }
      throw new MathException("Cannot work with this starting position. Please choose another point");
    }

    int count = 0;
    int jacReconCount = 1;
    while (!isConverged(data)) {
      // Want to reset the Jacobian every so often even if backtracking is working
      if ((jacReconCount) % FULL_RECALC_FREQ == 0) {
        estimate = _initializationFunction.getInitializedMatrix(jacobianFunction, data.getX());
        jacReconCount = 1;
      } else {
        estimate = _updateFunction.getUpdatedMatrix(jacobianFunction, data.getX(), data.getDeltaX(), data.getDeltaY(), estimate);
        jacReconCount++;
      }
      // if backtracking fails, could be that Jacobian estimate has drifted too far
      if (!getNextPosition(function, estimate, data)) {
        estimate = _initializationFunction.getInitializedMatrix(jacobianFunction, data.getX());
        jacReconCount = 1;
        if (!getNextPosition(function, estimate, data)) {
          if (isConverged(data)) {
            return data.getX(); //non-standard exit. Cannot find an improvement from this position, so provided we are close enough to the root, exit.
          }
          String msg = "Failed to converge in backtracking, even after a Jacobian recalculation." + getErrorMessage(data, jacobianFunction);
          s_logger.info(msg);
          throw new MathException(msg);
        }
      }
      count++;
      if (count > _maxSteps) {
        throw new MathException("Failed to converge - maximum iterations of " + _maxSteps + " reached." + getErrorMessage(data, jacobianFunction));
      }
    }
    return data.getX();
  }
View Full Code Here

    do {
      data.setLambda0(data.getLambda0() * 0.1);
      updatePosition(p, function, data);

      if (data.getLambda0() == 0.0) {
        throw new MathException("Failed to converge");
      }
    } while (Double.isNaN(data.getG1()) || Double.isInfinite(data.getG1()) || Double.isNaN(data.getG2()) || Double.isInfinite(data.getG2()));

  }
View Full Code Here

    double f1 = 0;
    double f2 = 0;
    f1 = f.evaluate(x1);
    f2 = f.evaluate(x2);
    if (Double.isNaN(f1)) {
      throw new MathException("Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1);
    }
    if (Double.isNaN(f2)) {
      throw new MathException("Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2);
    }

    for (int count = 0; count < MAX_STEPS; count++) {
      if (f1 * f2 < 0) {
        return new double[] {x1, x2 };
      }
      if (Math.abs(f1) < Math.abs(f2)) {
        x1 += RATIO * (x1 - x2);
        f1 = f.evaluate(x1);
        if (Double.isNaN(f1)) {
          throw new MathException("Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1);
        }
      } else {
        x2 += RATIO * (x2 - x1);
        f2 = f.evaluate(x2);
        if (Double.isNaN(f2)) {
          throw new MathException("Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2);
        }
      }
    }
    throw new MathException("Failed to bracket root");
  }
View Full Code Here

    boolean lowerLimitReached = false;
    boolean upperLimitReached = false;
    f1 = f.evaluate(x1);
    f2 = f.evaluate(x2);
    if (Double.isNaN(f1)) {
      throw new MathException("Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1);
    }
    if (Double.isNaN(f2)) {
      throw new MathException("Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2);
    }
    for (int count = 0; count < MAX_STEPS; count++) {
      if (f1 * f2 <= 0) {
        return new double[] {x1, x2 };
      }
      if (lowerLimitReached && upperLimitReached) {
        throw new MathException("Failed to bracket root: no root found between minX and maxX");
      }
      if (Math.abs(f1) < Math.abs(f2) && !lowerLimitReached) {
        x1 += RATIO * (x1 - x2);
        if (x1 < minX) {
          x1 = minX;
          lowerLimitReached = true;
        }
        f1 = f.evaluate(x1);
        if (Double.isNaN(f1)) {
          throw new MathException("Failed to bracket root: function invalid at x = " + x1 + " f(x) = " + f1);
        }
      } else {
        x2 += RATIO * (x2 - x1);
        if (x2 > maxX) {
          x2 = maxX;
          upperLimitReached = true;
        }
        f2 = f.evaluate(x2);
        if (Double.isNaN(f2)) {
          throw new MathException("Failed to bracket root: function invalid at x = " + x2 + " f(x) = " + f2);
        }
      }
    }
    throw new MathException("Failed to bracket root: max iterations");
  }
View Full Code Here

    checkInputs(function, xLow, xHigh);
    final UnivariateRealFunction wrapped = CommonsMathWrapper.wrapUnivariate(function);
    try {
      return _ridder.solve(wrapped, xLow, xHigh);
    } catch (final MaxIterationsExceededException e) {
      throw new MathException(e);
    } catch (final FunctionEvaluationException e) {
      throw new MathException(e);
    }
  }
View Full Code Here

      }
      f1 = function.evaluate(x1);
      f2 = function.evaluate(x2);
      f3 = function.evaluate(x3);
    }
    throw new MathException("Could not converge to root in " + MAX_ITER + " attempts");
  }
View Full Code Here

        if (CompareUtils.closeEquals(c.getImaginary(), 0, EPS)) {
          realRoots.add(c.getReal());
        }
      }
      if (realRoots.isEmpty()) {
        throw new MathException("Could not find any real roots");
      }
      return realRoots.toArray(EMPTY_ARRAY);
    } catch (final FunctionEvaluationException e) {
      throw new MathException(e);
    } catch (final org.apache.commons.math.ConvergenceException e) {
      throw new MathException(e);
    }
  }
View Full Code Here

      }
      if (Math.abs(dx) < _accuracy || Math.abs(y) < ZERO) {
        return xRoot;
      }
    }
    throw new MathException("Could not find root in " + MAX_ITER + " attempts");
  }
View Full Code Here

        x3 = x;
      } else {
        x4 = x;
      }
    }
    throw new MathException("Could not find root in " + MAX_ITER + " attempts");
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.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.