当前位置: 首页>>代码示例>>Python>>正文


Python stats.gamma方法代码示例

本文整理汇总了Python中scipy.stats.gamma方法的典型用法代码示例。如果您正苦于以下问题:Python stats.gamma方法的具体用法?Python stats.gamma怎么用?Python stats.gamma使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.gamma方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def __init__(self,
                 basis=LinearBasis(),
                 var=Parameter(gamma(1.), Positive()),
                 tol=1e-8,
                 maxiter=1000,
                 nstarts=100,
                 random_state=None
                 ):
        """See class docstring."""
        self.basis = basis
        self.var = var
        self.tol = tol
        self.maxiter = maxiter
        self.nstarts = nstarts
        self.random_state = random_state
        self.random_ = check_random_state(random_state) 
开发者ID:NICTA,项目名称:revrand,代码行数:18,代码来源:slm.py

示例2: __init__

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def __init__(self,
                 nbases,
                 Xdim,
                 mean=Parameter(norm_dist(), Bound()),
                 lenscale=Parameter(gamma(1.), Positive()),
                 regularizer=None,
                 random_state=None
                 ):
        """See this class's docstring."""
        self.random_state = random_state  # for repr
        self._random = check_random_state(random_state)
        self._init_dims(nbases, Xdim)
        self._params = [self._init_param(mean),
                        self._init_param(lenscale)]
        self._init_matrices()
        super(_LengthScaleBasis, self).__init__(regularizer) 
开发者ID:NICTA,项目名称:revrand,代码行数:18,代码来源:basis_functions.py

示例3: test_grad_concat

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def test_grad_concat(make_gaus_data):

    X, _, _, _ = make_gaus_data
    N, d = X.shape

    base = bs.LinearBasis(onescol=False) + bs.LinearBasis(onescol=False)

    assert list(base.grad(X)) == []

    base += bs.RadialBasis(centres=X)

    G = base.grad(X, 1.)

    assert list(G)[0].shape == (N, N + 2 * d)

    D = 200
    base += bs.RandomRBF(nbases=D, Xdim=d,
                         lenscale=Parameter(gamma(1), Positive(), shape=(d,)))
    G = base.grad(X, 1., np.ones(d))
    dims = [(N, N + (D + d) * 2), (N, N + (D + d) * 2, d)]

    for g, d in zip(G, dims):
        assert g.shape == d 
开发者ID:NICTA,项目名称:revrand,代码行数:25,代码来源:test_bases.py

示例4: test_logstruc_params

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def test_logstruc_params(make_quadratic, make_random):

    random = make_random
    a, b, c, data, _ = make_quadratic

    w0 = [Parameter(random.gamma(2, size=(2,)), Positive()),
          Parameter(random.randn(), Bound())
          ]

    qobj_struc = lambda w12, w3, data: q_struc(w12, w3, data, qobj)
    assert_opt = lambda Eab, Ec: \
        np.allclose((a, b, c), (Eab[0], Eab[1], Ec), atol=1e-3, rtol=0)

    nmin = structured_minimizer(logtrick_minimizer(minimize))
    res = nmin(qobj_struc, w0, args=(data,), jac=True, method='L-BFGS-B')
    assert_opt(*res.x)

    nsgd = structured_sgd(logtrick_sgd(sgd))
    res = nsgd(qobj_struc, w0, data, eval_obj=True, random_state=make_random)
    assert_opt(*res.x)

    qf_struc = lambda w12, w3, data: q_struc(w12, w3, data, qfun)
    qg_struc = lambda w12, w3, data: q_struc(w12, w3, data, qgrad)
    res = nmin(qf_struc, w0, args=(data,), jac=qg_struc, method='L-BFGS-B')
    assert_opt(*res.x) 
开发者ID:NICTA,项目名称:revrand,代码行数:27,代码来源:test_optimize.py

示例5: setUp_configure

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def setUp_configure(self):
        from scipy import stats
        self.dist = distributions.Gamma
        self.scipy_dist = stats.gamma

        self.test_targets = set(
            ['batch_shape', 'entropy', 'event_shape', 'log_prob', 'mean',
             'sample', 'support', 'variance'])

        k = utils.force_array(
            numpy.random.uniform(0, 5, self.shape).astype(numpy.float32))
        theta = utils.force_array(
            numpy.random.uniform(0, 5, self.shape).astype(numpy.float32))
        self.params = {'k': k, 'theta': theta}
        self.scipy_params = {'a': k, 'scale': theta}

        self.support = 'positive' 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:test_gamma.py

示例6: test_expect

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def test_expect(self):
        # smoke test the expect method of the frozen distribution
        # only take a gamma w/loc and scale and poisson with loc specified
        def func(x):
            return x

        gm = stats.gamma(a=2, loc=3, scale=4)
        gm_val = gm.expect(func, lb=1, ub=2, conditional=True)
        gamma_val = stats.gamma.expect(func, args=(2,), loc=3, scale=4,
                                       lb=1, ub=2, conditional=True)
        assert_allclose(gm_val, gamma_val)

        p = stats.poisson(3, loc=4)
        p_val = p.expect(func)
        poisson_val = stats.poisson.expect(func, args=(3,), loc=4)
        assert_allclose(p_val, poisson_val) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:test_distributions.py

示例7: test_erlang_runtimewarning

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def test_erlang_runtimewarning(self):
        # erlang should generate a RuntimeWarning if a non-integer
        # shape parameter is used.
        with warnings.catch_warnings():
            warnings.simplefilter("error", RuntimeWarning)

            # The non-integer shape parameter 1.3 should trigger a
            # RuntimeWarning
            assert_raises(RuntimeWarning,
                          stats.erlang.rvs, 1.3, loc=0, scale=1, size=4)

            # Calling the fit method with `f0` set to an integer should
            # *not* trigger a RuntimeWarning.  It should return the same
            # values as gamma.fit(...).
            data = [0.5, 1.0, 2.0, 4.0]
            result_erlang = stats.erlang.fit(data, f0=1)
            result_gamma = stats.gamma.fit(data, f0=1)
            assert_allclose(result_erlang, result_gamma, rtol=1e-3) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:test_distributions.py

示例8: testGammaLogPDF

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def testGammaLogPDF(self):
    with self.test_session():
      batch_size = 6
      alpha = tf.constant([2.0] * batch_size)
      beta = tf.constant([3.0] * batch_size)
      alpha_v = 2.0
      beta_v = 3.0
      x = np.array([2.5, 2.5, 4.0, 0.1, 1.0, 2.0], dtype=np.float32)
      gamma = tf.contrib.distributions.Gamma(alpha=alpha, beta=beta)
      expected_log_pdf = stats.gamma.logpdf(x, alpha_v, scale=1 / beta_v)
      log_pdf = gamma.log_pdf(x)
      self.assertEqual(log_pdf.get_shape(), (6,))
      self.assertAllClose(log_pdf.eval(), expected_log_pdf)

      pdf = gamma.pdf(x)
      self.assertEqual(pdf.get_shape(), (6,))
      self.assertAllClose(pdf.eval(), np.exp(expected_log_pdf)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:gamma_test.py

示例9: testGammaLogPDFMultidimensional

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def testGammaLogPDFMultidimensional(self):
    with self.test_session():
      batch_size = 6
      alpha = tf.constant([[2.0, 4.0]] * batch_size)
      beta = tf.constant([[3.0, 4.0]] * batch_size)
      alpha_v = np.array([2.0, 4.0])
      beta_v = np.array([3.0, 4.0])
      x = np.array([[2.5, 2.5, 4.0, 0.1, 1.0, 2.0]], dtype=np.float32).T
      gamma = tf.contrib.distributions.Gamma(alpha=alpha, beta=beta)
      expected_log_pdf = stats.gamma.logpdf(x, alpha_v, scale=1 / beta_v)
      log_pdf = gamma.log_pdf(x)
      log_pdf_values = log_pdf.eval()
      self.assertEqual(log_pdf.get_shape(), (6, 2))
      self.assertAllClose(log_pdf_values, expected_log_pdf)

      pdf = gamma.pdf(x)
      pdf_values = pdf.eval()
      self.assertEqual(pdf.get_shape(), (6, 2))
      self.assertAllClose(pdf_values, np.exp(expected_log_pdf)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:gamma_test.py

示例10: testGammaLogPDFMultidimensionalBroadcasting

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def testGammaLogPDFMultidimensionalBroadcasting(self):
    with self.test_session():
      batch_size = 6
      alpha = tf.constant([[2.0, 4.0]] * batch_size)
      beta = tf.constant(3.0)
      alpha_v = np.array([2.0, 4.0])
      beta_v = 3.0
      x = np.array([[2.5, 2.5, 4.0, 0.1, 1.0, 2.0]], dtype=np.float32).T
      gamma = tf.contrib.distributions.Gamma(alpha=alpha, beta=beta)
      expected_log_pdf = stats.gamma.logpdf(x, alpha_v, scale=1 / beta_v)
      log_pdf = gamma.log_pdf(x)
      log_pdf_values = log_pdf.eval()
      self.assertEqual(log_pdf.get_shape(), (6, 2))
      self.assertAllClose(log_pdf_values, expected_log_pdf)

      pdf = gamma.pdf(x)
      pdf_values = pdf.eval()
      self.assertEqual(pdf.get_shape(), (6, 2))
      self.assertAllClose(pdf_values, np.exp(expected_log_pdf)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:gamma_test.py

示例11: testGammaSampleSmallAlpha

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def testGammaSampleSmallAlpha(self):
    with tf.Session():
      alpha_v = 0.05
      beta_v = 1.0
      alpha = tf.constant(alpha_v)
      beta = tf.constant(beta_v)
      n = 100000
      gamma = tf.contrib.distributions.Gamma(alpha=alpha, beta=beta)
      samples = gamma.sample(n, seed=137)
      sample_values = samples.eval()
      self.assertEqual(samples.get_shape(), (n,))
      self.assertEqual(sample_values.shape, (n,))
      self.assertAllClose(
          sample_values.mean(),
          stats.gamma.mean(
              alpha_v, scale=1 / beta_v),
          atol=.01)
      self.assertAllClose(
          sample_values.var(),
          stats.gamma.var(alpha_v, scale=1 / beta_v),
          atol=.15)
      self.assertTrue(self._kstest(alpha_v, beta_v, sample_values)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:gamma_test.py

示例12: testGammaSample

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def testGammaSample(self):
    with tf.Session():
      alpha_v = 4.0
      beta_v = 3.0
      alpha = tf.constant(alpha_v)
      beta = tf.constant(beta_v)
      n = 100000
      gamma = tf.contrib.distributions.Gamma(alpha=alpha, beta=beta)
      samples = gamma.sample(n, seed=137)
      sample_values = samples.eval()
      self.assertEqual(samples.get_shape(), (n,))
      self.assertEqual(sample_values.shape, (n,))
      self.assertAllClose(
          sample_values.mean(),
          stats.gamma.mean(
              alpha_v, scale=1 / beta_v),
          atol=.01)
      self.assertAllClose(sample_values.var(),
                          stats.gamma.var(alpha_v, scale=1 / beta_v),
                          atol=.15)
      self.assertTrue(self._kstest(alpha_v, beta_v, sample_values)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:gamma_test.py

示例13: testGammaPdfOfSampleMultiDims

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def testGammaPdfOfSampleMultiDims(self):
    with tf.Session() as sess:
      gamma = tf.contrib.distributions.Gamma(alpha=[7., 11.], beta=[[5.], [6.]])
      num = 50000
      samples = gamma.sample(num, seed=137)
      pdfs = gamma.pdf(samples)
      sample_vals, pdf_vals = sess.run([samples, pdfs])
      self.assertEqual(samples.get_shape(), (num, 2, 2))
      self.assertEqual(pdfs.get_shape(), (num, 2, 2))
      self.assertAllClose(
          stats.gamma.mean([[7., 11.], [7., 11.]],
                           scale=1 / np.array([[5., 5.], [6., 6.]])),
          sample_vals.mean(axis=0),
          atol=.1)
      self.assertAllClose(
          stats.gamma.var([[7., 11.], [7., 11.]],
                          scale=1 / np.array([[5., 5.], [6., 6.]])),
          sample_vals.var(axis=0),
          atol=.1)
      self._assertIntegral(sample_vals[:, 0, 0], pdf_vals[:, 0, 0], err=0.02)
      self._assertIntegral(sample_vals[:, 0, 1], pdf_vals[:, 0, 1], err=0.02)
      self._assertIntegral(sample_vals[:, 1, 0], pdf_vals[:, 1, 0], err=0.02)
      self._assertIntegral(sample_vals[:, 1, 1], pdf_vals[:, 1, 1], err=0.02) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:25,代码来源:gamma_test.py

示例14: get_pdf

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def get_pdf(self, points=None):
        """
        A gamma probability density function.

        :param Gamma self:
            An instance of the Gamma class.
        :param matrix points:
            Matrix of points for defining the probability density function.
        :return:
            An array of N equidistant values over the support of the distribution.
        :return:
            Probability density values along the support of the Gamma distribution.
        """
        if points is not None:
            return self.parent.pdf(points)
        else:
            raise ValueError( 'Please digit an input for getPDF method') 
开发者ID:Effective-Quadratures,项目名称:Effective-Quadratures,代码行数:19,代码来源:gamma.py

示例15: get_cdf

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import gamma [as 别名]
def get_cdf(self, points=None):
        """
        A gamma cumulative density function.

        :param Gamma self:
            An instance of the Gamma class.
        :param matrix points:
            Matrix of points for defining the gamma cumulative density function.
        :return:
            An array of N equidistant values over the support of the gamma distribution.
        :return:
            Cumulative density values along the support of the gamma distribution.
        """
        if points is not None:
            return self.parent.cdf(points)
        else:
            raise ValueError( 'Please digit an input for getCDF method') 
开发者ID:Effective-Quadratures,项目名称:Effective-Quadratures,代码行数:19,代码来源:gamma.py


注:本文中的scipy.stats.gamma方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。