예제 #1
0
def pdtri(k, p):
    """Inverse of Poisson distribution.

    Finds Poission mean such that integral from 0 to k is p.
    """
    p = fix_rounding_error(p)
    if k < 0 or p < 0.0 or p >= 1.0:
        raise ZeroDivisionError, "k must be >=0, p between 1 and 0."
    v = k+1;
    return igami(v, p)
예제 #2
0
def gdtri(a, b, y):
    """Returns Gamma such that y is the probability in the integral.
    
    WARNING: if 1-y == 1, gives incorrect result. The scipy implementation
    gets around this by using cdflib, which is in Fortran. Until someone
    gets around to translating that, only use this function for values of
    p greater than 1e-15 or so!
    """
    y = fix_rounding_error(y)
    if y < 0.0 or y > 1.0 or a <= 0.0 or b < 0.0:
        raise ZeroDivisionError, "a and b must be non-negative, y from 0 to 1."
    return igami(b, 1.0-y) / a
예제 #3
0
    def test_igami(self):
        """igami should give same result as cephes implementation"""
        a_vals = [1e-10, 1e-5, 0.5, 1, 10, 200]
        y_vals = range(0,10,2)
        obs = [igami(a, y/10.0) for a in a_vals for y in y_vals]
        exp=[1.79769313486e+308,
0.0,
0.0,
0.0,
0.0,
1.79769313486e+308,
0.0,
0.0,
0.0,
0.0,
1.79769313486e+308,
0.821187207575,
0.3541631504,
0.137497948864,
0.0320923773337,
1.79769313486e+308,
1.60943791243,
0.916290731874,
0.510825623766,
0.223143551314,
1.79769313486e+308,
12.5187528198,
10.4756841889,
8.9044147366,
7.28921960854,
1.79769313486e+308,
211.794753362,
203.267574402,
196.108740945,
188.010915412,
]
        for o, e in zip(obs, exp):
            self.assertFloatEqual(o,e)
예제 #4
0
def chdtri(df, y):
    """Returns inverse of chi-squared distribution."""
    y = fix_rounding_error(y)
    if(y < 0.0 or y > 1.0 or df < 1.0):
        raise ZeroDivisionError, "y must be between 0 and 1; df >= 1"
    return 2 * igami(0.5*df, y)