<s> from __future__ import division <EOL> import numpy as np <EOL> from nose import SkipTest <EOL> from numpy . testing import assert_array_almost_equal , assert_allclose <EOL> from scipy . spatial . distance import pdist , squareform <EOL> from megaman . utils . testing import assert_raise_message <EOL> from megaman . geometry import ( compute_adjacency_matrix , adjacency_methods , <EOL> compute_affinity_matrix , affinity_methods , <EOL> compute_laplacian_matrix , laplacian_methods ) <EOL> from megaman . geometry . geometry import Geometry , distance_error_msg <EOL> def test_compute_adjacency_matrix_args ( almost_equal_decimals = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> input_types = [ '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> params = [ { '<STR_LIT>' : <NUM_LIT:1> } , { '<STR_LIT>' : <NUM_LIT:2> } ] <EOL> for adjacency_method in adjacency_methods ( ) : <EOL> if adjacency_method == '<STR_LIT>' : <EOL> try : <EOL> import pyflann as pyf <EOL> except ImportError : <EOL> raise SkipTest ( "<STR_LIT>" ) <EOL> X = np . random . uniform ( size = ( <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> D = compute_adjacency_matrix ( X , adjacency_method , ** params [ <NUM_LIT:1> ] ) <EOL> A = compute_affinity_matrix ( D , radius = <NUM_LIT:1> ) <EOL> for init_params in params : <EOL> for kwarg_params in params : <EOL> true_params = init_params . copy ( ) <EOL> true_params . update ( kwarg_params ) <EOL> adjacency_true = compute_adjacency_matrix ( X , adjacency_method , ** true_params ) <EOL> G = Geometry ( adjacency_method = adjacency_method , adjacency_kwds = init_params ) <EOL> for input in input_types : <EOL> G = Geometry ( adjacency_kwds = init_params ) <EOL> if input in [ '<STR_LIT:data>' ] : <EOL> G . set_data_matrix ( X ) <EOL> adjacency_queried = G . compute_adjacency_matrix ( ** kwarg_params ) <EOL> assert_allclose ( adjacency_true . toarray ( ) , <EOL> adjacency_queried . toarray ( ) , rtol = <NUM_LIT> ) <EOL> else : <EOL> if input in [ '<STR_LIT>' ] : <EOL> G . set_adjacency_matrix ( D ) <EOL> else : <EOL> G . set_affinity_matrix ( A ) <EOL> msg = distance_error_msg <EOL> assert_raise_message ( ValueError , msg , G . compute_adjacency_matrix ) <EOL> def test_compute_affinity_matrix_args ( almost_equal_decimals = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> input_types = [ '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> params = [ { '<STR_LIT>' : <NUM_LIT:4> } , { '<STR_LIT>' : <NUM_LIT:5> } ] <EOL> adjacency_method = '<STR_LIT>' <EOL> for affinity_method in affinity_methods ( ) : <EOL> X = np . random . uniform ( size = ( <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> D = compute_adjacency_matrix ( X , adjacency_method , ** params [ <NUM_LIT:1> ] ) <EOL> A = compute_affinity_matrix ( D , affinity_method , ** params [ <NUM_LIT:1> ] ) <EOL> for init_params in params : <EOL> for kwarg_params in params : <EOL> true_params = init_params . copy ( ) <EOL> true_params . update ( kwarg_params ) <EOL> affinity_true = compute_affinity_matrix ( D , adjacency_method , <EOL> ** true_params ) <EOL> for input in input_types : <EOL> G = Geometry ( adjacency_method = adjacency_method , <EOL> adjacency_kwds = params [ <NUM_LIT:1> ] , <EOL> affinity_method = affinity_method , <EOL> affinity_kwds = init_params ) <EOL> if input in [ '<STR_LIT:data>' , '<STR_LIT>' ] : <EOL> if input in [ '<STR_LIT:data>' ] : <EOL> G . set_data_matrix ( X ) <EOL> else : <EOL> G . set_adjacency_matrix ( D ) <EOL> affinity_queried = G . compute_affinity_matrix ( ** kwarg_params ) <EOL> assert_array_almost_equal ( affinity_true . todense ( ) , affinity_queried . todense ( ) , almost_equal_decimals ) <EOL> else : <EOL> G . set_affinity_matrix ( A ) <EOL> msg = distance_error_msg <EOL> assert_raise_message ( ValueError , msg , G . compute_affinity_matrix ) <EOL> def test_compute_laplacian_matrix_args ( almost_equal_decimals = <NUM_LIT:5> ) : <EOL> input_types = [ '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> params = [ { } , { '<STR_LIT>' : <NUM_LIT:4> } , { '<STR_LIT>' : <NUM_LIT:5> } ] <EOL> lapl_params = [ { } , { '<STR_LIT>' : <NUM_LIT:4> } , { '<STR_LIT>' : <NUM_LIT:10> } ] <EOL> adjacency_method = '<STR_LIT>' <EOL> affinity_method = '<STR_LIT>' <EOL> for laplacian_method in laplacian_methods ( ) : <EOL> X = np . random . uniform ( size = ( <NUM_LIT:10> , <NUM_LIT:2> ) ) <EOL> D = compute_adjacency_matrix ( X , adjacency_method , ** params [ <NUM_LIT:1> ] ) <EOL> A = compute_affinity_matrix ( D , affinity_method , ** params [ <NUM_LIT:1> ] ) <EOL> for init_params in lapl_params : <EOL> for kwarg_params in lapl_params : <EOL> true_params = init_params . copy ( ) <EOL> true_params . update ( kwarg_params ) <EOL> laplacian_true = compute_laplacian_matrix ( A , laplacian_method , ** true_params ) <EOL> for input in input_types : <EOL> G = Geometry ( adjacency_method = adjacency_method , <EOL> adjacency_kwds = params [ <NUM_LIT:1> ] , <EOL> affinity_method = affinity_method , <EOL> affinity_kwds = params [ <NUM_LIT:1> ] , <EOL> laplacian_method = laplacian_method , <EOL> laplacian_kwds = lapl_params [ <NUM_LIT:0> ] ) <EOL> if input in [ '<STR_LIT:data>' ] : <EOL> G . set_data_matrix ( X ) <EOL> if input in [ '<STR_LIT>' ] : <EOL> G . set_adjacency_matrix ( D ) <EOL> else : <EOL> G . set_affinity_matrix ( A ) <EOL> laplacian_queried = G . compute_laplacian_matrix ( ** kwarg_params ) <EOL> assert_array_almost_equal ( laplacian_true . todense ( ) , laplacian_queried . todense ( ) , almost_equal_decimals ) </s>
