#NEWLINE# def test_cosine_distances( ) : #NEWLINE# #INDENT# ' Check that the pairwise Cosine distances computation' #NEWLINE# X = [ [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] ] #NEWLINE# D = cosine_distances ( X , X ) #NEWLINE# assert_array_almost_equal ( D , [ [ 1.0 ] ] ) #NEWLINE# X = [ [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] ] #NEWLINE# Y = [ [ ] ] #NEWLINE# assert_raises ( ValueError , pearson_correlation , X , Y ) #NEWLINE# X = [ [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] ] #NEWLINE# Y = [ [ 3.0 , 3.5 , 1.5 , 5.0 , 3.5 , 3.0 ] ] #NEWLINE# D = cosine_distances ( X , Y ) #NEWLINE# assert_array_almost_equal ( D , [ [ 0.960646301 ] ] ) #NEWLINE# X = [ [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] , [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] ] #NEWLINE# Y = [ [ 3.0 , 3.5 , 1.5 , 5.0 , 3.5 , 3.0 ] ] #NEWLINE# D = cosine_distances ( X , Y ) #NEWLINE# assert_array_almost_equal ( D , [ [ 0.960646301 ] , [ 0.960646301 ] ] ) #NEWLINE# X = [ [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] , [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] ] #NEWLINE# Y = [ [ 3.0 , 3.5 , 1.5 , 5.0 , 3.5 , 3.0 ] , [ 2.5 , 3.5 , 3.0 , 3.5 , 2.5 , 3.0 ] ] #NEWLINE# D = cosine_distances ( X , Y ) #NEWLINE# assert_array_almost_equal ( D , [ [ 0.960646301 , 1.0 ] , [ 0.960646301 , 1.0 ] ] ) #NEWLINE# X = [ [ 0 , 1 ] , [ 1 , 1 ] ] #NEWLINE# D = cosine_distances ( X , X ) #NEWLINE# assert_array_almost_equal ( D , [ [ 1.0 , 0.70710678 ] , [ 0.70710678 , 1.0 ] ] ) #NEWLINE# X = [ [ 0 , 1 ] , [ 1 , 1 ] ] #NEWLINE# Y = [ [ 0 , 0 ] ] #NEWLINE# D = cosine_distances ( X , Y ) #NEWLINE# assert_array_almost_equal ( D , [ [ np . nan ] , [ np . nan ] ] )