Function kmedoids::pam_build

source ·
pub fn pam_build<M, N, L>(mat: &M, k: usize) -> (L, Vec<usize>, Vec<usize>)
where N: Zero + PartialOrd + Copy, L: AddAssign + Signed + Zero + PartialOrd + Copy + From<N>, M: ArrayAdapter<N>,
Expand description

Run the original PAM BUILD algorithm.

This is provided for academic reasons to see the performance difference. Quality-wise, FasterPAM yields better results than just BUILD.

  • type M - matrix data type such as ndarray::Array2 or kmedoids::arrayadapter::LowerTriangle
  • type N - number data type such as u32 or f64
  • type L - number data type such as i64 or f64 for the loss (must be signed)
  • mat - a pairwise distance matrix
  • k - the number of medoids to pick

returns a tuple containing:

  • the initial loss
  • the initial cluster assignment
  • the initial medoids

§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): (f64, _, _) = kmedoids::pam_build(&data, 2);
println!("Loss is: {}", loss);