Esempio n. 1
0
 def test(self):
     self.v_i = dict()
     for i in xrange(0, self.m):
         max_number = 2 ** (i+1) - 1
         tmp = []
         for j in xrange(0, max_number + 1):
             b = "{0:b}".format(j)
             if len(b) < self.m:
                 b = "0"*(i + 1 - len(b)) + b
             tmp.append(len(Utils.get_all_indexes(self.seq[i+1], b)))
         self.v_i[i+1] = tmp
     xsi, xsi_2 = self.__calc_xsi()
     pv1 = igamc(2**(self.m - 2), xsi)
     pv2 = 0
     if xsi_2 is not None:
         pv2 = igamc(2**(self.m - 3), xsi_2)
     is_random = False if pv1 < 0.01 and pv2 < 0.01 else True
     return (pv1, pv2, is_random)
Esempio n. 2
0
 def __test(self):
     chi = 0
     consts = LongestRunOfOnes.CONSTS[self.M]
     for i in range(0, consts['k'] + 1):
         tmp = self.blocks_count * consts['pi'][i]
         chi += (self.v_i.get(i, 0) - tmp) ** 2 / tmp
     self.chi_2 = chi
     self.p_value = igamc(consts['k'] / 2.0, self.chi_2 / 2.0)
     self.is_random = False if self.p_value < 0.01 else True
Esempio n. 3
0
def pdtr(k, m):
    """Returns sum of left tail of Poisson distribution, 0 through k.

    See Cephes docs for details.
    """
    if k < 0:
        raise ValueError, "Poisson k must be >= 0."
    if m < 0:
        raise ValueError, "Poisson m must be >= 0."
    return igamc(k+1, m)
Esempio n. 4
0
def pdtr(k, m):
    """Returns sum of left tail of Poisson distribution, 0 through k.

    See Cephes docs for details.
    """
    if k < 0:
        raise ValueError, "Poisson k must be >= 0."
    if m < 0:
        raise ValueError, "Poisson m must be >= 0."
    return igamc(k + 1, m)
Esempio n. 5
0
def chi_high(x, df):
    """Returns right-hand tail of chi-square distribution (x to infinity).
    
    df, the degrees of freedom, ranges from 1 to infinity (assume integers).
    Typically, df is (r-1)*(c-1) for a r by c table.
    
    Result ranges from 0 to 1.
    
    See Cephes docs for details.
    """
    x = fix_rounding_error(x)
    
    if x < 0:
        raise ValueError, "chi_high: x must be >= 0 (got %s)." % x
    if df < 1:
        raise ValueError, "chi_high: df must be >= 1 (got %s)." % df
    return igamc(df/2, x/2)
Esempio n. 6
0
def chi_high(x, df):
    """Returns right-hand tail of chi-square distribution (x to infinity).
    
    df, the degrees of freedom, ranges from 1 to infinity (assume integers).
    Typically, df is (r-1)*(c-1) for a r by c table.
    
    Result ranges from 0 to 1.
    
    See Cephes docs for details.
    """
    x = fix_rounding_error(x)

    if x < 0:
        raise ValueError, "chi_high: x must be >= 0 (got %s)." % x
    if df < 1:
        raise ValueError, "chi_high: df must be >= 1 (got %s)." % df
    return igamc(df / 2, x / 2)
Esempio n. 7
0
def gdtrc(a, b, x):
    """Returns integral from x to inf of Gamma distribution with params a and b.
    """
    if x < 0.0:
        raise ZeroDivisionError, "x must be at least 0."
    return igamc(b, a * x)
Esempio n. 8
0
def gdtrc(a, b, x):
    """Returns integral from x to inf of Gamma distribution with params a and b.
    """
    if x < 0.0:
        raise ZeroDivisionError, "x must be at least 0."
    return igamc(b, a * x)