[−][src]Function kmedoids::pam
pub fn pam<M, N>(
mat: &M,
k: usize,
maxiter: usize
) -> (N, Vec<usize>, Vec<usize>, usize, usize) where
N: NumAssignOps + Signed + Zero + PartialOrd + Copy + SafeAdd + Display,
M: ArrayAdapter<N>,
Implementation of the original PAM algorithm (BUILD + SWAP)
This is provided for academic reasons to see the performance difference. Quality-wise, FasterPAM is comparable to PAM, and much faster.
- type
M
- matrix data type such asndarray::Array2
orkmedoids::arrayadapter::LowerTriangle
- type
N
- number data type such asi32
orf64
(must be signed) mat
- a pairwise distance matrixk
- the number of medoids to pickmaxiter
- the maximum number of iterations allowed
returns a tuple containing:
- the final loss
- the final cluster assignment
- the final medoids
- the number of iterations needed
- the number of swaps performed
Panics
- panics when the dissimilarity matrix is not square
- panics when k is 0 or larger than N
Example
Given a dissimilarity matrix of size 4 x 4, use:
let data = ndarray::arr2(&[[0,1,2,3],[1,0,4,5],[2,4,0,6],[3,5,6,0]]); let (loss, assi, meds, n_iter, n_swap) = kmedoids::pam(&data, 2, 100); println!("Loss is: {}", loss);