Function kmedoids::par_fasterpam
source · pub fn par_fasterpam<M, N, L>(
mat: &M,
med: &mut Vec<usize>,
maxiter: usize,
rng: &mut impl Rng
) -> (L, Vec<usize>, usize, usize)
Expand description
Run the FasterPAM algorithm (parallel version).
For small data sets (n<1000) it is usually faster to use the non-parallel version.
- type
M
- matrix data type such asndarray::Array2
orkmedoids::arrayadapter::LowerTriangle
- type
N
- number data type such asu32
orf64
- type
L
- number data type such asi64
orf64
for the loss (must be signed) mat
- a pairwise distance matrixmed
- the list of medoidsmaxiter
- the maximum number of iterations allowedrng
- random number generator for shuffling the input data
returns a tuple containing:
- the final loss
- the final cluster assignment
- 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 mut meds = kmedoids::random_initialization(4, 2, &mut rand::thread_rng());
let (loss, assi, n_iter, n_swap): (f64, _, _, _) = kmedoids::par_fasterpam(&data, &mut meds, 100, &mut rand::thread_rng());
println!("Loss is: {}", loss);