예제 #1
0
def test_hk_shape(pts, dims):
    n_bins = 10
    x = get_input(pts, dims)

    hk = HeatKernel(sigma=1, n_bins=n_bins)
    num_dimensions = len(np.unique(dims))
    x_t = hk.fit(x).transform(x)

    assert x_t.shape == (x.shape[0], num_dimensions, n_bins, n_bins)
예제 #2
0
def test_hk_big_sigma(pts, dims):
    """ We expect that with a huge sigma, the diagrams are so diluted that
    they are almost 0. Effectively, verifies that the smoothing is applied."""
    n_bins = 10
    x = get_input(pts, dims)

    hk = HeatKernel(sigma=100*np.max(np.abs(x)), n_bins=n_bins)
    x_t = hk.fit(x).transform(x)

    assert np.all(np.abs(x_t) <= 1e-4)
예제 #3
0
def test_hk_positive(pts, dims):
    """ We expect the points above the PD-diagonal to be non-negative,
    (up to a numerical error)"""
    n_bins = 10
    hk = HeatKernel(sigma=1, n_bins=n_bins)

    x = get_input(pts, dims)
    x_t = hk.fit(x).transform(x)

    assert np.all((np.tril(x_t[:, :, ::-1, :]) + 1e-13) >= 0.)
def test_hk_with_diag_points(pts):
    """Add points on the diagonal, and verify that we have the same results
    (on the same fitted values)."""
    n_bins = 10
    hk = HeatKernel(sigma=1, n_bins=n_bins)

    X = get_input(pts, np.zeros((pts.shape[0], pts.shape[1], 1)))
    diag_points = np.array([[[2, 2, 0], [3, 3, 0], [7, 7, 0]]])
    X_with_diag_points = np.concatenate([X, diag_points], axis=1)

    hk = hk.fit(X_with_diag_points)

    X_t, X_with_diag_points_t = [hk.transform(X_)
                                 for X_ in [X, X_with_diag_points]]

    assert_almost_equal(X_with_diag_points_t, X_t, decimal=13)
예제 #5
0
def test_all_pts_the_same():
    X = np.zeros((1, 4, 3))
    hk = HeatKernel(sigma=1)
    with pytest.raises(IndexError):
        _ = hk.fit(X).transform(X)