fuzzyclust.ensemble.coassociation_matrix#
- fuzzyclust.ensemble.coassociation_matrix(memberships, similarity='cosine')[source]#
Soft co-association (similarity) matrix of a library of fuzzy partitions.
For partition \(q\) with membership vectors \(\boldsymbol{\mu}^{(q)}_k=[\mu^{(q)}_{1k},\dots,\mu^{(q)}_{c_qk}]^T\) the similarity of two objects is the cosine of their membership vectors (
similarity="cosine") or their plain inner product ("product"), and the co-association is the average over the library,\[s_{kl} = \frac{1}{Q}\sum_{q=1}^{Q} \frac{\langle\boldsymbol{\mu}^{(q)}_k,\boldsymbol{\mu}^{(q)}_l\rangle} {\|\boldsymbol{\mu}^{(q)}_k\|\,\|\boldsymbol{\mu}^{(q)}_l\|} \quad\text{or}\quad s_{kl} = \frac{1}{Q}\sum_{q=1}^{Q}\sum_{i=1}^{c_q}\mu^{(q)}_{ik}\mu^{(q)}_{il} .\]For crisp partitions both are the fraction of partitions that put \(k\) and \(l\) into the same cluster – the evidence accumulation matrix of Fred and Jain. For soft partitions the inner product is the probability that two independent draws from the membership vectors fall into the same cluster; it is below one even on the diagonal (an object at the border of two clusters is only “half” together with itself). The cosine normalizes every partition’s similarity so that an object is fully co-associated with itself and with every object that has the same membership vector, which keeps the scale of the matrix independent of the fuzziness and of the number of clusters of the members.
- Parameters:
- membershipssequence
ofarray_likeofshape(n_samples,c_q) - similarity{“cosine”, “product”}, default=”cosine”
- membershipssequence
- Returns:
- S
ndarrayofshape(n_samples,n_samples) Symmetric, entries in \([0,1]\); unit diagonal for
"cosine".
- S
Examples
>>> import numpy as np >>> from fuzzyclust.ensemble import coassociation_matrix >>> U1 = np.eye(2)[[0, 0, 1, 1]] >>> U2 = np.eye(2)[[0, 1, 1, 1]] >>> coassociation_matrix([U1, U2]).round(2) array([[1. , 0.5, 0. , 0. ], [0.5, 1. , 0.5, 0.5], [0. , 0.5, 1. , 1. ], [0. , 0.5, 1. , 1. ]])