コード例 #1
0
ファイル: test_special.py プロジェクト: carze/clovr-base
 def test_combinations(self):
     """combinations should return expected results when int as input"""
     self.assertEqual(combinations(1,1), 1)
     self.assertEqual(combinations(2,1), 2)
     self.assertEqual(combinations(3,1), 3)
     self.assertEqual(combinations(4,1), 4)
     self.assertEqual(combinations(4,2), 6)
     self.assertEqual(combinations(4,3), 4)
     self.assertEqual(combinations(4,4), 1)
     self.assertEqual(combinations(20,4), 19*17*15)
     self.assertFloatEqual(combinations(300, 100), 4.1582514632578812e+81)
コード例 #2
0
ファイル: test_special.py プロジェクト: carze/clovr-base
 def test_combinations_float(self):
     """combinations should use gamma function when floats as input"""
     self.assertFloatEqual(combinations(1.0,1.0), 1)
     self.assertFloatEqual(combinations(2.0,1.0), 2)
     self.assertFloatEqual(combinations(3.0,1.0), 3)
     self.assertFloatEqual(combinations(4.0,1.0), 4)
     self.assertFloatEqual(combinations(4.0,2), 6)
     self.assertFloatEqual(combinations(4,3.0), 4)
     self.assertFloatEqual(combinations(4.0,4.0), 1)
     self.assertFloatEqual(combinations(20.0,4.0), 19*17*15)
     self.assertFloatEqual(combinations(300,100.0),4.1582514632578812e81)
コード例 #3
0
ファイル: test_special.py プロジェクト: cxhernandez/pycogent
 def test_combinations(self):
     """combinations should return expected results when int as input"""
     self.assertEqual(combinations(1, 1), 1)
     self.assertEqual(combinations(2, 1), 2)
     self.assertEqual(combinations(3, 1), 3)
     self.assertEqual(combinations(4, 1), 4)
     self.assertEqual(combinations(4, 2), 6)
     self.assertEqual(combinations(4, 3), 4)
     self.assertEqual(combinations(4, 4), 1)
     self.assertEqual(combinations(20, 4), 19 * 17 * 15)
     self.assertFloatEqual(combinations(300, 100), 4.1582514632578812e+81)
コード例 #4
0
ファイル: test_special.py プロジェクト: cxhernandez/pycogent
 def test_combinations_float(self):
     """combinations should use gamma function when floats as input"""
     self.assertFloatEqual(combinations(1.0, 1.0), 1)
     self.assertFloatEqual(combinations(2.0, 1.0), 2)
     self.assertFloatEqual(combinations(3.0, 1.0), 3)
     self.assertFloatEqual(combinations(4.0, 1.0), 4)
     self.assertFloatEqual(combinations(4.0, 2), 6)
     self.assertFloatEqual(combinations(4, 3.0), 4)
     self.assertFloatEqual(combinations(4.0, 4.0), 1)
     self.assertFloatEqual(combinations(20.0, 4.0), 19 * 17 * 15)
     self.assertFloatEqual(combinations(300, 100.0), 4.1582514632578812e81)
コード例 #5
0
ファイル: test_special.py プロジェクト: carze/clovr-base
 def test_combinations_range(self):
     """combinations should decrease gradually with increasing k"""
     start = 5 #combinations(10,5) = 252
     end = 6 #combinations(10,6) = 210
     step = 0.1
     lower_lim = 210
     upper_lim = 252
     previous_value = 252.00001
     while start <= end:
         obs = combinations(10,start)
         assert lower_lim <= obs <= upper_lim
         assert obs < previous_value
         previous_value = obs
         start += step
コード例 #6
0
ファイル: test_special.py プロジェクト: cxhernandez/pycogent
 def test_combinations_range(self):
     """combinations should decrease gradually with increasing k"""
     start = 5  #combinations(10,5) = 252
     end = 6  #combinations(10,6) = 210
     step = 0.1
     lower_lim = 210
     upper_lim = 252
     previous_value = 252.00001
     while start <= end:
         obs = combinations(10, start)
         assert lower_lim <= obs <= upper_lim
         assert obs < previous_value
         previous_value = obs
         start += step
コード例 #7
0
ファイル: ks.py プロジェクト: blankenberg/pycogent
def pkolmogorov1x(statistic, n):
    """Probability function for the one-sided one sample Kolmogorov statistics.
    
    Translated from R 2.4."""
    statistic = asarray(statistic)
    if statistic <= 0:
        return 0.0
    if statistic >= 1:
        return 1.0
    to = floor(n * (1 - statistic)) + 1
    j = arange(0, to)
    coeffs = asarray([log(combinations(n, i)) for i in j])
    p = sum(exp(coeffs + (n - j) * log(1 - statistic - j / n) + (j - 1) * (log(statistic + j / n))))
    return 1 - statistic * p
コード例 #8
0
def pkolmogorov1x(statistic, n):
    """Probability function for the one-sided one sample Kolmogorov statistics.
    
    Translated from R 2.4."""
    statistic = asarray(statistic)
    if statistic <= 0:
        return 0.
    if statistic >= 1:
        return 1.
    to = floor(n * (1 - statistic)) + 1
    j = arange(0, to)
    coeffs = asarray([log(combinations(n, i)) for i in j])
    p = sum(exp(coeffs + (n-j)*log(1-statistic-j/n) + \
                                            (j-1)*(log(statistic+j/n))))
    return 1 - statistic * p