I try to use precomputed affinity matrix for clustering, but it doesnt work even for simple cases. I tried different dumping parameters and different values for diagonal with no success.
Below is the example.
affinities =
[[ 0. -1. -2. -6. -7.]
[-1. 0. -1. -7. -8.]
[-2. -1. 0. -8. -9.]
[-6. -7. -8. 0. -1.]
[-7. -8. -9. -1. 0.]]
I try to cluster the matrix using fit(..) method of sklearn Affinity Propagation module:
import sklearn.cluster
clusterer = sklearn.cluster.AffinityPropagation(affinity='precomputed', damping=0.9, verbose=True)
result = clusterer.fit(affinities)
from pprint import pprint
pprint(vars(result))
But no clusters are found (please note that result obviously should be [0,0,0,1,1]):
Converged after 23 iterations.
{'affinity': 'precomputed',
'affinity_matrix_': array([[ 0., -1., -2., -6., -7.],
[-1., 0., -1., -7., -8.],
[-2., -1., 0., -8., -9.],
[-6., -7., -8., 0., -1.],
[-7., -8., -9., -1., 0.]]),
'cluster_centers_indices_': array([0]),
'convergence_iter': 15,
'copy': True,
'damping': 0.9,
'labels_': array([0, 0, 0, 0, 0]),
'max_iter': 200,
'n_iter_': 24,
'preference': None,
'verbose': True}