Esempio n. 1
0
def test_discrepancy():
    corners = [[0.5, 0.5], [6.5, 6.5]]
    space_1 = Space(corners)
    space_2 = Space(corners)

    space_1 += [[1, 3], [2, 6], [3, 2], [4, 5], [5, 1], [6, 4]]
    space_2 += [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 6]]

    assert Space.discrepancy(space_1, space_1.corners) == pytest.approx(0.0081, abs=1e-4)
    assert Space.discrepancy(space_2, space_2.corners) == pytest.approx(0.0105, abs=1e-4)

    space_1 = (2.0 * space_1.values - 1.0) / (2.0 * 6.0)
    assert Space.discrepancy(space_1) == pytest.approx(0.0081, abs=1e-4)

    space = np.array([[2, 1, 1, 2, 2, 2],
                      [1, 2, 2, 2, 2, 2],
                      [2, 1, 1, 1, 1, 1],
                      [1, 1, 1, 1, 2, 2],
                      [1, 2, 2, 2, 1, 1],
                      [2, 2, 2, 2, 1, 1],
                      [2, 2, 2, 1, 2, 2]])
    space = (2.0 * space - 1.0) / (2.0 * 2.0)

    assert Space.discrepancy(space, method='MD') == pytest.approx(2.5000, abs=1e-4)
    assert Space.discrepancy(space, method='WD') == pytest.approx(1.3680, abs=1e-4)
    assert Space.discrepancy(space, method='CD') == pytest.approx(0.3172, abs=1e-4)
Esempio n. 2
0
           np.array(sample_kde)[-1, 1],
           c='b',
           marker='D',
           s=60)

ticks = np.linspace(0, 1, num=5)
plt.colorbar(contour, ticks=ticks)
plt.show()

# WD plot
fig = plt.figure()
ax = fig.gca()
ax.set_xlim(mini, maxi)
ax.set_ylim(mini, maxi)
f_ = np.array([
    Space.discrepancy(np.vstack([np.array(sample_kde)[:-1], s]), method='WD')
    for s in positions.T
])[:, None]
f_ = np.reshape(f_, xx.shape)
contour = ax.contourf(xx, yy, f_)
ax.scatter(np.array(sample_kde)[:-1, 0],
           np.array(sample_kde)[:-1, 1],
           c='k',
           marker='o')
plt.colorbar(contour)
plt.show()

# 1D line at y=0.5
# fig = plt.figure()
# x = np.linspace(0, 1, 100)[:, None]
# x = np.concatenate([x, np.ones((100, 1)) * 0.5], axis=1)