當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。