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


Python stats.laplace方法代码示例

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


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

示例1: testLaplaceLogPDF

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceLogPDF(self):
    with self.test_session():
      batch_size = 6
      loc = tf.constant([2.0] * batch_size)
      scale = tf.constant([3.0] * batch_size)
      loc_v = 2.0
      scale_v = 3.0
      x = np.array([2.5, 2.5, 4.0, 0.1, 1.0, 2.0], dtype=np.float32)
      laplace = tf.contrib.distributions.Laplace(loc=loc, scale=scale)
      expected_log_pdf = stats.laplace.logpdf(x, loc_v, scale=scale_v)
      log_pdf = laplace.log_pdf(x)
      self.assertEqual(log_pdf.get_shape(), (6,))
      self.assertAllClose(log_pdf.eval(), expected_log_pdf)

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

示例2: testLaplaceLogPDFMultidimensional

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceLogPDFMultidimensional(self):
    with self.test_session():
      batch_size = 6
      loc = tf.constant([[2.0, 4.0]] * batch_size)
      scale = tf.constant([[3.0, 4.0]] * batch_size)
      loc_v = np.array([2.0, 4.0])
      scale_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
      laplace = tf.contrib.distributions.Laplace(loc=loc, scale=scale)
      expected_log_pdf = stats.laplace.logpdf(x, loc_v, scale=scale_v)
      log_pdf = laplace.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 = laplace.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,代码来源:laplace_test.py

示例3: testLaplaceLogPDFMultidimensionalBroadcasting

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceLogPDFMultidimensionalBroadcasting(self):
    with self.test_session():
      batch_size = 6
      loc = tf.constant([[2.0, 4.0]] * batch_size)
      scale = tf.constant(3.0)
      loc_v = np.array([2.0, 4.0])
      scale_v = 3.0
      x = np.array([[2.5, 2.5, 4.0, 0.1, 1.0, 2.0]], dtype=np.float32).T
      laplace = tf.contrib.distributions.Laplace(loc=loc, scale=scale)
      expected_log_pdf = stats.laplace.logpdf(x, loc_v, scale=scale_v)
      log_pdf = laplace.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 = laplace.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,代码来源:laplace_test.py

示例4: testLaplaceSample

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceSample(self):
    with tf.Session():
      loc_v = 4.0
      scale_v = 3.0
      loc = tf.constant(loc_v)
      scale = tf.constant(scale_v)
      n = 100000
      laplace = tf.contrib.distributions.Laplace(loc=loc, scale=scale)
      samples = laplace.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.laplace.mean(loc_v, scale=scale_v),
                          rtol=0.05, atol=0.)
      self.assertAllClose(sample_values.var(),
                          stats.laplace.var(loc_v, scale=scale_v),
                          rtol=0.05, atol=0.)
      self.assertTrue(self._kstest(loc_v, scale_v, sample_values)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:21,代码来源:laplace_test.py

示例5: testLaplacePdfOfSampleMultiDims

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplacePdfOfSampleMultiDims(self):
    with tf.Session() as sess:
      laplace = tf.contrib.distributions.Laplace(
          loc=[7., 11.], scale=[[5.], [6.]])
      num = 50000
      samples = laplace.sample(num, seed=137)
      pdfs = laplace.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.laplace.mean([[7., 11.], [7., 11.]],
                             scale=np.array([[5., 5.], [6., 6.]])),
          sample_vals.mean(axis=0),
          rtol=0.05, atol=0.)
      self.assertAllClose(
          stats.laplace.var([[7., 11.], [7., 11.]],
                            scale=np.array([[5., 5.], [6., 6.]])),
          sample_vals.var(axis=0),
          rtol=0.05, atol=0.)
      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,代码行数:26,代码来源:laplace_test.py

示例6: __init__

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def __init__(self, loc, scale):
        loc.shape == scale.shape or _raise(ValueError())
        #
        self._loc     = loc
        self._scale   = scale
        # expose methods from laplace object
        _laplace      = laplace(loc=self._loc,scale=self._scale)
        self.rvs      = _laplace.rvs
        self.pdf      = _laplace.pdf
        self.logpdf   = _laplace.logpdf
        self.cdf      = _laplace.cdf
        self.logcdf   = _laplace.logcdf
        self.sf       = _laplace.sf
        self.logsf    = _laplace.logsf
        self.ppf      = _laplace.ppf
        self.isf      = _laplace.isf
        self.moment   = _laplace.moment
        self.stats    = _laplace.stats
        self.entropy  = _laplace.entropy
        self.expect   = _laplace.expect
        self.median   = _laplace.median
        self.mean     = _laplace.mean
        self.var      = _laplace.var
        self.std      = _laplace.std
        self.interval = _laplace.interval 
开发者ID:CSBDeep,项目名称:CSBDeep,代码行数:27,代码来源:probability.py

示例7: test_loglaplace

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def test_loglaplace():
    #if x is laplace then y = exp(x) is loglaplace
    #parameters are tricky
    #the stats.loglaplace parameter is the inverse scale of x
    loglaplaceexpg = ExpTransf_gen(stats.laplace)

    cdfst = stats.loglaplace.cdf(3,3)
    #0.98148148148148151
    #the parameters are shape, loc and scale of underlying laplace
    cdftr = loglaplaceexpg._cdf(3,0,1./3)
    assert_almost_equal(cdfst, cdftr, 14) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:ex_transf2.py

示例8: setUp_configure

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

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

        loc = utils.force_array(
            numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
        scale = utils.force_array(numpy.exp(
            numpy.random.uniform(-1, 1, self.shape)).astype(numpy.float32))
        self.params = {'loc': loc, 'scale': scale}
        self.scipy_params = {'loc': loc, 'scale': scale} 
开发者ID:chainer,项目名称:chainer,代码行数:17,代码来源:test_laplace.py

示例9: check_backward

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def check_backward(self, x_data, y_grad):
        gradient_check.check_backward(
            distributions.laplace._laplace_cdf,
            x_data, y_grad, **self.backward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_laplace.py

示例10: check_forward

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def check_forward(self, x_data):
        y = distributions.laplace._laplace_icdf(x_data)
        cdf = distributions.laplace._laplace_cdf(y)
        testing.assert_allclose(cdf.array, x_data) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_laplace.py

示例11: testLaplaceShape

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceShape(self):
    with self.test_session():
      loc = tf.constant([3.0] * 5)
      scale = tf.constant(11.0)
      laplace = tf.contrib.distributions.Laplace(loc=loc, scale=scale)

      self.assertEqual(laplace.batch_shape().eval(), (5,))
      self.assertEqual(laplace.get_batch_shape(), tf.TensorShape([5]))
      self.assertAllEqual(laplace.event_shape().eval(), [])
      self.assertEqual(laplace.get_event_shape(), tf.TensorShape([])) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:12,代码来源:laplace_test.py

示例12: testLaplaceCDF

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceCDF(self):
    with self.test_session():
      batch_size = 6
      loc = tf.constant([2.0] * batch_size)
      scale = tf.constant([3.0] * batch_size)
      loc_v = 2.0
      scale_v = 3.0
      x = np.array([2.5, 2.5, 4.0, 0.1, 1.0, 2.0], dtype=np.float32)

      laplace = tf.contrib.distributions.Laplace(loc=loc, scale=scale)
      expected_cdf = stats.laplace.cdf(x, loc_v, scale=scale_v)

      cdf = laplace.cdf(x)
      self.assertEqual(cdf.get_shape(), (6,))
      self.assertAllClose(cdf.eval(), expected_cdf) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:17,代码来源:laplace_test.py

示例13: testLaplaceMode

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceMode(self):
    with self.test_session():
      loc_v = np.array([0.5, 3.0, 2.5])
      scale_v = np.array([1.0, 4.0, 5.0])
      laplace = tf.contrib.distributions.Laplace(loc=loc_v, scale=scale_v)
      self.assertEqual(laplace.mode().get_shape(), (3,))
      self.assertAllClose(laplace.mode().eval(), loc_v) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:9,代码来源:laplace_test.py

示例14: testLaplaceVariance

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceVariance(self):
    with self.test_session():
      loc_v = np.array([1.0, 3.0, 2.5])
      scale_v = np.array([1.0, 4.0, 5.0])
      laplace = tf.contrib.distributions.Laplace(loc=loc_v, scale=scale_v)
      expected_variances = stats.laplace.var(loc_v, scale=scale_v)
      self.assertEqual(laplace.variance().get_shape(), (3,))
      self.assertAllClose(laplace.variance().eval(), expected_variances) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:10,代码来源:laplace_test.py

示例15: testLaplaceStd

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import laplace [as 别名]
def testLaplaceStd(self):
    with self.test_session():
      loc_v = np.array([1.0, 3.0, 2.5])
      scale_v = np.array([1.0, 4.0, 5.0])
      laplace = tf.contrib.distributions.Laplace(loc=loc_v, scale=scale_v)
      expected_std = stats.laplace.std(loc_v, scale=scale_v)
      self.assertEqual(laplace.std().get_shape(), (3,))
      self.assertAllClose(laplace.std().eval(), expected_std) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:10,代码来源:laplace_test.py


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