Package org.jquantlib.math.distributions

Examples of org.jquantlib.math.distributions.GammaFunction


    }

    public static double incompleteBetaFunction(final double a, final double b, final double x, final double accuracy,
            final Integer maxIteration) {

        final GammaFunction gf = new GammaFunction();

        QL.require(a > 0.0 , "a must be greater than zero"); // QA:[RG]::verified // TODO: message
        QL.require(b > 0.0 , "b must be greater than zero"); // QA:[RG]::verified // TODO: message

        if (x == 0.0)
            return 0.0;
        else if (x == 1.0)
            return 1.0;
        else
            if (x<0.0 || x>1.0)
                throw new ArithmeticException("x must be in [0,1]");

        final double result = Math.exp(gf.logValue(a+b) - gf.logValue(a) - gf.logValue(b) + a*Math.log(x) + b*Math.log(1.0-x));

        if (x < (a+1.0)/(a+b+2.0))
            return result * betaContinuedFraction(a, b, x, accuracy, maxIteration)/a;
        else
            return 1.0 - result * betaContinuedFraction(b, a, 1.0-x, accuracy, maxIteration)/b;
View Full Code Here


        else
            return 1.0 - result * betaContinuedFraction(b, a, 1.0-x, accuracy, maxIteration)/b;
    }

    static double betaFunction(final double z, final double w) {
        final GammaFunction gf = new GammaFunction();
        return Math.exp(gf.logValue(z)+gf.logValue(w)-gf.logValue(z+w));
    }
View Full Code Here

    }

    public static double incompleteBetaFunction(final double a, final double b, final double x, final double accuracy,
            final Integer maxIteration) {

        final GammaFunction gf = new GammaFunction();

        QL.require(a > 0.0 , "a must be greater than zero"); // TODO: message
        QL.require(b > 0.0 , "b must be greater than zero"); // TODO: message

        if (x == 0.0)
            return 0.0;
        else if (x == 1.0)
            return 1.0;
        else
            if (x<0.0 || x>1.0)
                throw new ArithmeticException("x must be in [0,1]");

        final double result = Math.exp(gf.logValue(a+b) - gf.logValue(a) - gf.logValue(b) + a*Math.log(x) + b*Math.log(1.0-x));

        if (x < (a+1.0)/(a+b+2.0))
            return result * betaContinuedFraction(a, b, x, accuracy, maxIteration)/a;
        else
            return 1.0 - result * betaContinuedFraction(b, a, 1.0-x, accuracy, maxIteration)/b;
View Full Code Here

        else
            return 1.0 - result * betaContinuedFraction(b, a, 1.0-x, accuracy, maxIteration)/b;
    }

    static double betaFunction(final double z, final double w) {
        final GammaFunction gf = new GammaFunction();
        return Math.exp(gf.logValue(z)+gf.logValue(w)-gf.logValue(z+w));
    }
View Full Code Here

  }

  @Test
  public void testGammaFunction() {

      final GammaFunction gfn = new GammaFunction();

      double expected = 0.0;
      double calculated = gfn.logValue(1);
      if (Math.abs(calculated) > 1.0e-15)
          fail("GammaFunction(1)\n"
                      + "    calculated: " + calculated + "\n"
                      + "    expected:   " + expected);

      for (int i=2; i<9000; i++) {
          expected  += Math.log(i);
          calculated = gfn.logValue(i+1);
          if (Math.abs(calculated-expected)/expected > 1.0e-9)
              fail("GammaFunction(" + i + ")\n"
                          + "    calculated: " + calculated + "\n"
                          + "    expected:   " + expected + "\n"
                          + "    rel. error: " + Math.abs(calculated-expected)/expected);
View Full Code Here

    final double[][] values =  {  {1.075, -0.0388257395},
                {1.225, -0.0922078291},
                {1.5,   -0.1207822376},
                {1.975, -0.0103670060} };

    final GammaFunction gammaFunction = new GammaFunction();
    for (final double[] value : values) {
      final double x = value[0];
      final double expected = value[1];
      final double realised = gammaFunction.logValue(x);
      final double tolerance = 1.0e-10;
      if (Math.abs(expected-realised)>tolerance)
          fail("x: " + x + " expected: " + expected + " realised: " + realised);
    }
  }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.distributions.GammaFunction

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.