當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.histogramdd方法代碼示例

本文整理匯總了Python中numpy.histogramdd方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.histogramdd方法的具體用法?Python numpy.histogramdd怎麽用?Python numpy.histogramdd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.histogramdd方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_rightmost_binedge

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_rightmost_binedge(self):
        # Test event very close to rightmost binedge. See Github issue #4266
        x = [0.9999999995]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 1.)
        x = [1.0]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 1.)
        x = [1.0000000001]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 0.0)
        x = [1.0001]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 0.0) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_histograms.py

示例2: calc_tvd

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def calc_tvd(sess,Generator,Data,N=50000,nbins=10):
    Xd=sess.run(Data.X,{Data.N:N})
    step,Xg=sess.run([Generator.step,Generator.X],{Generator.N:N})

    p_gen,_ = np.histogramdd(Xg,bins=nbins,range=[[0,1],[0,1],[0,1]],normed=True)
    p_dat,_ = np.histogramdd(Xd,bins=nbins,range=[[0,1],[0,1],[0,1]],normed=True)
    p_gen/=nbins**3
    p_dat/=nbins**3
    tvd=0.5*np.sum(np.abs( p_gen-p_dat ))
    mvd=np.max(np.abs( p_gen-p_dat ))

    return step,tvd, mvd

    s_tvd=make_summary(Data.name+'_tvd',tvd)
    s_mvd=make_summary(Data.name+'_mvd',mvd)

    return step,s_tvd,s_mvd
    #return make_summary('tvd/'+Generator.name,tvd) 
開發者ID:mkocaoglu,項目名稱:CausalGAN,代碼行數:20,代碼來源:utils.py

示例3: test_rightmost_binedge

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_rightmost_binedge(self):
        # Test event very close to rightmost binedge. See Github issue #4266
        x = [0.9999999995]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 1.)
        x = [1.0]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 1.)
        x = [1.0000000001]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 1.)
        x = [1.0001]
        bins = [[0., 0.5, 1.0]]
        hist, _ = histogramdd(x, bins=bins)
        assert_(hist[0] == 0.0)
        assert_(hist[1] == 0.0) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:test_function_base.py

示例4: test_no_params

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_no_params(self):
        a = np.array([1, 2, 3, 4, 5])
        with self.assertWarns(PrivacyLeakWarning):
            res = histogramdd(a)
        self.assertIsNotNone(res) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:7,代碼來源:test_histogramdd.py

示例5: test_no_range

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_no_range(self):
        a = np.array([1, 2, 3, 4, 5])
        with self.assertWarns(PrivacyLeakWarning):
            res = histogramdd(a, epsilon=2)
        self.assertIsNotNone(res) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:7,代碼來源:test_histogramdd.py

示例6: test_same_edges

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_same_edges(self):
        a = np.array([1, 2, 3, 4, 5])
        _, edges = np.histogramdd(a, bins=3, range=[(0, 10)])
        _, dp_edges = histogramdd(a, epsilon=1, bins=3, range=[(0, 10)])

        for i in range(len(edges)):
            self.assertTrue((edges[i] == dp_edges[i]).all()) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:9,代碼來源:test_histogramdd.py

示例7: test_different_result

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_different_result(self):
        global_seed(3141592653)
        a = np.array([1, 2, 3, 4, 5])
        hist, _ = np.histogramdd(a, bins=3, range=[(0, 10)])
        dp_hist, _ = histogramdd(a, epsilon=0.1, bins=3, range=[(0, 10)])

        # print("Non-private histogram: %s" % hist)
        # print("Private histogram: %s" % dp_hist)
        self.assertTrue((hist != dp_hist).any()) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:11,代碼來源:test_histogramdd.py

示例8: test_density_1d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_density_1d(self):
        global_seed(3141592653)
        a = np.array([1, 2, 3, 4, 5])
        dp_hist, _ = histogramdd(a, epsilon=1, bins=3, range=[(0, 10)], density=True)

        # print(dp_hist.sum())

        self.assertAlmostEqual(dp_hist.sum(), 1.0 * 3 / 10) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:10,代碼來源:test_histogramdd.py

示例9: test_accountant

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_accountant(self):
        acc = BudgetAccountant(1.5, 0)

        a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]).T
        histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True, accountant=acc)

        with self.assertRaises(BudgetError):
            histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True, accountant=acc) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:10,代碼來源:test_histogramdd.py

示例10: test_default_accountant

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_default_accountant(self):
        BudgetAccountant.pop_default()

        a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]).T
        histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)], density=True)
        acc = BudgetAccountant.pop_default()
        self.assertEqual((1, 0), acc.total())
        self.assertEqual(acc.epsilon, float("inf"))
        self.assertEqual(acc.delta, 1.0)

        histogramdd(a, epsilon=1, bins=3, range=[(0, 10), (0, 10)])

        self.assertEqual((1, 0), acc.total()) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:15,代碼來源:test_histogramdd.py

示例11: test_histogramdd_too_many_bins

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_histogramdd_too_many_bins(self):
        # Ticket 928.
        assert_raises(ValueError, np.histogramdd, np.ones((1, 10)), bins=2**10) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:test_regression.py

示例12: test_simple

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_simple(self):
        x = np.array([[-.5, .5, 1.5], [-.5, 1.5, 2.5], [-.5, 2.5, .5],
                      [.5,  .5, 1.5], [.5,  1.5, 2.5], [.5,  2.5, 2.5]])
        H, edges = histogramdd(x, (2, 3, 3),
                               range=[[-1, 1], [0, 3], [0, 3]])
        answer = np.array([[[0, 1, 0], [0, 0, 1], [1, 0, 0]],
                           [[0, 1, 0], [0, 0, 1], [0, 0, 1]]])
        assert_array_equal(H, answer)

        # Check normalization
        ed = [[-2, 0, 2], [0, 1, 2, 3], [0, 1, 2, 3]]
        H, edges = histogramdd(x, bins=ed, density=True)
        assert_(np.all(H == answer / 12.))

        # Check that H has the correct shape.
        H, edges = histogramdd(x, (2, 3, 4),
                               range=[[-1, 1], [0, 3], [0, 4]],
                               density=True)
        answer = np.array([[[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0]],
                           [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]]])
        assert_array_almost_equal(H, answer / 6., 4)
        # Check that a sequence of arrays is accepted and H has the correct
        # shape.
        z = [np.squeeze(y) for y in np.split(x, 3, axis=1)]
        H, edges = histogramdd(
            z, bins=(4, 3, 2), range=[[-2, 2], [0, 3], [0, 2]])
        answer = np.array([[[0, 0], [0, 0], [0, 0]],
                           [[0, 1], [0, 0], [1, 0]],
                           [[0, 1], [0, 0], [0, 0]],
                           [[0, 0], [0, 0], [0, 0]]])
        assert_array_equal(H, answer)

        Z = np.zeros((5, 5, 5))
        Z[list(range(5)), list(range(5)), list(range(5))] = 1.
        H, edges = histogramdd([np.arange(5), np.arange(5), np.arange(5)], 5)
        assert_array_equal(H, Z) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:38,代碼來源:test_histograms.py

示例13: test_shape_3d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_shape_3d(self):
        # All possible permutations for bins of different lengths in 3D.
        bins = ((5, 4, 6), (6, 4, 5), (5, 6, 4), (4, 6, 5), (6, 5, 4),
                (4, 5, 6))
        r = np.random.rand(10, 3)
        for b in bins:
            H, edges = histogramdd(r, b)
            assert_(H.shape == b) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_histograms.py

示例14: test_shape_4d

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_shape_4d(self):
        # All possible permutations for bins of different lengths in 4D.
        bins = ((7, 4, 5, 6), (4, 5, 7, 6), (5, 6, 4, 7), (7, 6, 5, 4),
                (5, 7, 6, 4), (4, 6, 7, 5), (6, 5, 7, 4), (7, 5, 4, 6),
                (7, 4, 6, 5), (6, 4, 7, 5), (6, 7, 5, 4), (4, 6, 5, 7),
                (4, 7, 5, 6), (5, 4, 6, 7), (5, 7, 4, 6), (6, 7, 4, 5),
                (6, 5, 4, 7), (4, 7, 6, 5), (4, 5, 6, 7), (7, 6, 4, 5),
                (5, 4, 7, 6), (5, 6, 7, 4), (6, 4, 5, 7), (7, 5, 6, 4))

        r = np.random.rand(10, 4)
        for b in bins:
            H, edges = histogramdd(r, b)
            assert_(H.shape == b) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_histograms.py

示例15: test_weights

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import histogramdd [as 別名]
def test_weights(self):
        v = np.random.rand(100, 2)
        hist, edges = histogramdd(v)
        n_hist, edges = histogramdd(v, density=True)
        w_hist, edges = histogramdd(v, weights=np.ones(100))
        assert_array_equal(w_hist, hist)
        w_hist, edges = histogramdd(v, weights=np.ones(100) * 2, density=True)
        assert_array_equal(w_hist, n_hist)
        w_hist, edges = histogramdd(v, weights=np.ones(100, int) * 2)
        assert_array_equal(w_hist, 2 * hist) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_histograms.py


注:本文中的numpy.histogramdd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。