|
|
|
@ -16,20 +16,24 @@ class TestKdeTools(unittest.TestCase):
|
|
|
|
|
def test_gridcount_1d():
|
|
|
|
|
# N = 20
|
|
|
|
|
# data = np.random.rayleigh(1, size=(N,))
|
|
|
|
|
data = array([0.75355792, 0.72779194, 0.94149169, 0.07841119,
|
|
|
|
|
2.32291887, 1.10419995, 0.77055114, 0.60288273,
|
|
|
|
|
1.36883635, 1.74754326, 1.09547561, 1.01671133,
|
|
|
|
|
0.73211143, 0.61891719, 0.75903487, 1.8919469,
|
|
|
|
|
0.72433808, 1.92973094, 0.44749838, 1.36508452])
|
|
|
|
|
# print(data.tolist())
|
|
|
|
|
data = [0.6493244636902034, 0.6562823794215175, 1.0905183896319681,
|
|
|
|
|
0.42206966930980305, 3.2401808457841033, 0.4527768130472434,
|
|
|
|
|
1.2078346032213523, 0.7042615640603758, 1.1514223608901017,
|
|
|
|
|
0.9233030250922233, 1.0709559676055374, 0.7132605765584901,
|
|
|
|
|
0.6560730230166847, 0.734614714549834, 1.0404525505934663,
|
|
|
|
|
0.6750474427282895, 0.8801082165600141, 1.7235435044161305,
|
|
|
|
|
1.2660483754981589, 0.9811765136936577]
|
|
|
|
|
x = np.linspace(0, max(data) + 1, 10)
|
|
|
|
|
|
|
|
|
|
dx = x[1] - x[0]
|
|
|
|
|
c = wkg.gridcount(data, x)
|
|
|
|
|
assert_allclose(c, [0.78762626, 1.77520717, 7.99190087, 4.04054449,
|
|
|
|
|
1.67156643, 2.38228499, 1.05933195, 0.29153785, 0.,
|
|
|
|
|
0.])
|
|
|
|
|
assert_allclose(c,
|
|
|
|
|
[0.1430937435034, 5.864465648665, 9.418694957317207,
|
|
|
|
|
2.9154367000439, 0.6583089504704, 0.0,
|
|
|
|
|
0.12255097773682266, 0.8774490222631774, 0.0, 0.0])
|
|
|
|
|
t = np.trapz(c / dx / len(data), x)
|
|
|
|
|
assert_allclose(t, 0.9803093435140049)
|
|
|
|
|
assert_allclose(t, 0.9964226564124143)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def test_gridcount_2d():
|
|
|
|
|