Exemplo n.º 1
0
def test_affinity_mat_poly(data):

    v1_data = data['fit_data'][0]

    distances = cdist(v1_data, v1_data)
    gamma = 1 / (2 * np.median(distances)**2)
    true_kernel = polynomial_kernel(v1_data, gamma=gamma)
    spectral = MultiviewSpectralClustering(random_state=RANDOM_STATE,
                                           affinity='poly')
    p_kernel = spectral._affinity_mat(v1_data)

    assert (p_kernel.shape[0] == data['n_fit'])
    assert (p_kernel.shape[1] == data['n_fit'])

    for ind1 in range(p_kernel.shape[0]):
        for ind2 in range(p_kernel.shape[1]):
            assert np.abs(true_kernel[ind1][ind2] -
                          p_kernel[ind1][ind2]) < 0.000001
Exemplo n.º 2
0
def test_affinity_neighbors(data):

    v1_data = data['fit_data'][0]
    n_neighbors = 10
    neighbors = NearestNeighbors(n_neighbors=n_neighbors)
    neighbors.fit(v1_data)
    true_kernel = neighbors.kneighbors_graph(v1_data).toarray()
    spectral = MultiviewSpectralClustering(random_state=RANDOM_STATE,
                                           affinity='nearest_neighbors',
                                           n_neighbors=10)
    n_kernel = spectral._affinity_mat(v1_data)
    assert (n_kernel.shape[0] == data['n_fit'])
    assert (n_kernel.shape[1] == data['n_fit'])

    for ind1 in range(n_kernel.shape[0]):
        for ind2 in range(n_kernel.shape[1]):
            assert np.abs(true_kernel[ind1][ind2] -
                          n_kernel[ind1][ind2]) < 0.000001
Exemplo n.º 3
0
def test_affinity_mat_rbf2(data):

    v1_data = data['fit_data'][0]
    gamma = 1
    spectral = MultiviewSpectralClustering(random_state=RANDOM_STATE,
                                           gamma=gamma)
    distances = cdist(v1_data, v1_data)
    gamma = 1 / (2 * np.median(distances)**2)
    true_kernel = rbf_kernel(v1_data, gamma=1)
    g_kernel = spectral._affinity_mat(v1_data)

    assert (g_kernel.shape[0] == data['n_fit'])
    assert (g_kernel.shape[1] == data['n_fit'])

    for ind1 in range(g_kernel.shape[0]):
        for ind2 in range(g_kernel.shape[1]):
            assert np.abs(true_kernel[ind1][ind2] -
                          g_kernel[ind1][ind2]) < 0.000001