Exemple #1
0
 def testLgamma(self):
     items = (
         (0.1, 2.25271265),
         (0.2, 1.52406382),
         (0.3, 1.09579799),
         (0.4, 0.79667782),
         (0.5, 0.57236494),
         (0.6, 0.39823386),
         (0.7, 0.26086725),
         (0.8, 0.15205968),
         (0.9, 0.06637624),
         (1.0, 0.00000000),
         (1.1, -0.04987244),
         (1.2, -0.08537409),
         (1.3, -0.10817481),
         (1.4, -0.11961291),
         (1.5, -0.12078224),
         (1.6, -0.11259177),
         (1.7, -0.09580770),
         (1.8, -0.07108387),
         (1.9, -0.03898428),
         (2.0, 0.00000000),
         (2.1, 0.04543774),
         (2.2, 0.09694747),
         (2.3, 0.15418945),
         (2.4, 0.21685932),
         (2.5, 0.28468287),
         (2.6, 0.35741186),
         (2.7, 0.43482055),
         (2.8, 0.51670279),
         (2.9, 0.60286961),
         (3.0, 0.69314718),
     )
     for v, lg in items:
         print(v, lg, lgamma(v))
         self.assertLessEqual(
             abs(lgamma(v) - lg), 1.0e-8,
             "log Gamma(%f) = %f; lgamma(%f) -> %f" % (v, lg, v, lgamma(v)))
Exemple #2
0
 def testLgamma(self):
   items = (
     (0.1,  2.25271265),
     (0.2,  1.52406382),
     (0.3,  1.09579799),
     (0.4,  0.79667782),
     (0.5,  0.57236494),
     (0.6,  0.39823386),
     (0.7,  0.26086725),
     (0.8,  0.15205968),
     (0.9,  0.06637624),
     (1.0,  0.00000000),
     (1.1, -0.04987244),
     (1.2, -0.08537409),
     (1.3, -0.10817481),
     (1.4, -0.11961291),
     (1.5, -0.12078224),
     (1.6, -0.11259177),
     (1.7, -0.09580770),
     (1.8, -0.07108387),
     (1.9, -0.03898428),
     (2.0,  0.00000000),
     (2.1,  0.04543774),
     (2.2,  0.09694747),
     (2.3,  0.15418945),
     (2.4,  0.21685932),
     (2.5,  0.28468287),
     (2.6,  0.35741186),
     (2.7,  0.43482055),
     (2.8,  0.51670279),
     (2.9,  0.60286961),
     (3.0,  0.69314718),
   )
   for v, lg in items:
     print v, lg, lgamma(v)
     self.assertLessEqual(abs(lgamma(v) - lg), 1.0e-8,
                          "log Gamma(%f) = %f; lgamma(%f) -> %f" % (
                              v, lg, v, lgamma(v)))
Exemple #3
0
    def __init__(self, shape, scale=None, beta=None):
        self.alpha = shape
        if scale is not None:
            self.scale = scale
            self.beta = 1.0 / scale
            assert beta is None, "Specify exactly one of 'scale' or 'beta'."
        elif beta is not None:
            self.scale = 1.0 / beta
            self.beta = beta
        else:
            assert beta is None, "Specify exactly one of 'scale' or 'beta'."

        self.lgammaAlpha = lgamma(shape)
        self.logBeta = -numpy.log(scale)
Exemple #4
0
  def __init__(self, shape, scale=None, beta=None):
    self.alpha = shape
    if scale is not None:
      self.scale = scale
      self.beta = 1.0 / scale
      assert beta is None, "Specify exactly one of 'scale' or 'beta'."
    elif beta is not None:
      self.scale = 1.0 / beta
      self.beta = beta
    else:
      assert beta is None, "Specify exactly one of 'scale' or 'beta'."

    self.lgammaAlpha = lgamma(shape)
    self.logBeta = -numpy.log(scale)
Exemple #5
0
def logFactorial(x):
    """Approximation to the log of the factorial function."""
    return lgamma(x + 1.0)
Exemple #6
0
def logBeta(alpha):
    alpha = numpy.asarray(alpha)
    return numpy.sum([lgamma(a) for a in alpha]) - lgamma(alpha.sum())
Exemple #7
0
def logFactorial(x):
  """Approximation to the log of the factorial function."""
  return lgamma(x + 1.0)
Exemple #8
0
def logBeta(alpha):
  alpha = numpy.asarray(alpha)
  return numpy.sum([lgamma(a) for a in alpha]) - lgamma(alpha.sum())