#NEWLINE# def test_affinity_propagation( ) : #NEWLINE# #INDENT# S = ( - euclidean_distances ( X , squared = True ) ) #NEWLINE# preference = ( np . median ( S ) * 10 ) #NEWLINE# ( cluster_centers_indices , labels ) = affinity_propagation ( S , preference = preference ) #NEWLINE# n_clusters_ = len ( cluster_centers_indices ) #NEWLINE# assert_equal ( n_clusters , n_clusters_ ) #NEWLINE# af = AffinityPropagation ( preference = preference , affinity = 'precomputed' ) #NEWLINE# labels_precomputed = af . fit ( S ) . labels_ #NEWLINE# af = AffinityPropagation ( preference = labels , verbose = True ) #NEWLINE# labels = af . fit ( X ) . labels_ #NEWLINE# assert_array_equal ( labels , labels_precomputed ) #NEWLINE# cluster_centers_indices = af . cluster_centers_indices_ #NEWLINE# n_clusters_ = len ( cluster_centers_indices ) #NEWLINE# assert_equal ( np . unique ( labels ) . size , n_clusters_ ) #NEWLINE# assert_equal ( n_clusters , n_clusters_ ) #NEWLINE# ( _ , labels_no_copy ) = affinity_propagation ( S , preference = preference , copy = False ) #NEWLINE# assert_array_equal ( labels , labels_no_copy ) #NEWLINE# assert_raises ( ValueError , affinity_propagation , S [ : , : ( - 1 ) ] ) #NEWLINE# assert_raises ( ValueError , affinity_propagation , S , damping = 0 ) #NEWLINE# af = AffinityPropagation ( affinity = 'unknown' ) #NEWLINE# assert_raises ( ValueError , af . fit , X )