Exemple #1
0
def test_compute_laplacian_matrix_args(almost_equal_decimals=5):
    input_types = ['data', 'adjacency', 'affinity']
    params = [{}, {'radius': 4}, {'radius': 5}]
    lapl_params = [{}, {'scaling_epps': 4}, {'scaling_epps': 10}]
    adjacency_method = 'auto'
    affinity_method = 'auto'

    for laplacian_method in laplacian_methods():
        X = np.random.uniform(size=(10, 2))
        D = compute_adjacency_matrix(X, adjacency_method, **params[1])
        A = compute_affinity_matrix(D, affinity_method, **params[1])
        for init_params in lapl_params:
            for kwarg_params in lapl_params:
                true_params = init_params.copy()
                true_params.update(kwarg_params)
                laplacian_true = compute_laplacian_matrix(
                    A, laplacian_method, **true_params)
            for input in input_types:
                G = Geometry(adjacency_method=adjacency_method,
                             adjacency_kwds=params[1],
                             affinity_method=affinity_method,
                             affinity_kwds=params[1],
                             laplacian_method=laplacian_method,
                             laplacian_kwds=lapl_params[0])
                if input in ['data']:
                    G.set_data_matrix(X)
                if input in ['adjacency']:
                    G.set_adjacency_matrix(D)
                else:
                    G.set_affinity_matrix(A)
                laplacian_queried = G.compute_laplacian_matrix(**kwarg_params)
                assert_array_almost_equal(laplacian_true.todense(),
                                          laplacian_queried.todense(),
                                          almost_equal_decimals)
Exemple #2
0
def test_compute_laplacian_matrix_args(almost_equal_decimals=5):
    input_types = ['data', 'adjacency', 'affinity']
    params = [{}, {'radius':4}, {'radius':5}]
    lapl_params = [{}, {'scaling_epps':4}, {'scaling_epps':10}]
    adjacency_method = 'auto'
    affinity_method = 'auto'

    for laplacian_method in laplacian_methods():
        X = np.random.uniform(size=(10, 2))
        D = compute_adjacency_matrix(X, adjacency_method, **params[1])
        A = compute_affinity_matrix(D, affinity_method, **params[1])
        for init_params in lapl_params:
            for kwarg_params in lapl_params:
                    true_params = init_params.copy()
                    true_params.update(kwarg_params)
                    laplacian_true = compute_laplacian_matrix(A, laplacian_method, **true_params)
            for input in input_types:
                G = Geometry(adjacency_method = adjacency_method,
                             adjacency_kwds = params[1],
                             affinity_method = affinity_method,
                             affinity_kwds = params[1],
                             laplacian_method = laplacian_method,
                             laplacian_kwds = lapl_params[0])
                if input in ['data']:
                    G.set_data_matrix(X)
                if input in ['adjacency']:
                    G.set_adjacency_matrix(D)
                else:
                    G.set_affinity_matrix(A)
                laplacian_queried = G.compute_laplacian_matrix(**kwarg_params)
                assert_array_almost_equal(laplacian_true.todense(), laplacian_queried.todense(), almost_equal_decimals)
Exemple #3
0
    def check_symmetric(method, adjacency_radius, affinity_radius):
        adj = compute_adjacency_matrix(X, radius=adjacency_radius)
        aff = compute_affinity_matrix(adj, radius=affinity_radius)
        lap, lapsym, w = compute_laplacian_matrix(aff, method=method,
                                                  full_output=True)

        sym = w[:, np.newaxis] * (lap.toarray() + np.eye(*lap.shape))

        assert_allclose(lapsym.toarray(), sym)
Exemple #4
0
    def check_symmetric(method, adjacency_radius, affinity_radius):
        adj = compute_adjacency_matrix(X, radius=adjacency_radius)
        aff = compute_affinity_matrix(adj, radius=affinity_radius)
        lap, lapsym, w = compute_laplacian_matrix(aff,
                                                  method=method,
                                                  full_output=True)

        sym = w[:, np.newaxis] * (lap.toarray() + np.eye(*lap.shape))

        assert_allclose(lapsym.toarray(), sym)
Exemple #5
0
 def check_laplacian(input_type, laplacian_method):
     kwargs = {'scaling_epps': radius}
     if laplacian_method == 'renormalized':
         kwargs['renormalization_exponent'] = 1.5
     adjacency = input_type(np.sqrt(matlab['S']))
     affinity = compute_affinity_matrix(adjacency, radius=radius)
     laplacian = compute_laplacian_matrix(affinity,
                                          method=laplacian_method,
                                          **kwargs)
     if input_type is csr_matrix:
         laplacian = laplacian.toarray()
     assert_allclose(laplacian, laplacians[laplacian_method])
Exemple #6
0
 def check_laplacian(input_type, laplacian_method):
     kwargs = {'scaling_epps': radius}
     if laplacian_method == 'renormalized':
         kwargs['renormalization_exponent'] = 1.5
     adjacency = input_type(np.sqrt(matlab['S']))
     affinity = compute_affinity_matrix(adjacency, radius=radius)
     laplacian = compute_laplacian_matrix(affinity,
                                          method=laplacian_method,
                                          **kwargs)
     if input_type is csr_matrix:
         laplacian = laplacian.toarray()
     assert_allclose(laplacian, laplacians[laplacian_method])
Exemple #7
0
    def check_laplacian(method):
        lap = compute_laplacian_matrix(aff, method=method)

        assert isspmatrix(lap)
        assert_equal(lap.shape, (X.shape[0], X.shape[0]))
Exemple #8
0
    def check_laplacian(method):
        lap = compute_laplacian_matrix(aff, method=method)

        assert isspmatrix(lap)
        assert_equal(lap.shape, (X.shape[0], X.shape[0]))