pub fn dynmsc<M, N, L>(
mat: &M,
med: &Vec<usize>,
mink: usize,
maxiter: usize
) -> (L, Vec<usize>, usize, usize, Vec<usize>, Vec<L>)
Expand description
Run the DynMSC algorithm.
We begin with a maximum number of clusters, optimize the Average Medoid Silhouette, then decrease the number of clusters by one, and repeat until we have reached a minimum number of clusters. During this process, we store the solution with the highest AMS to return later.
- 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 medoidsmink
- the minimum number of clustersmaxiter
- the maximum number of iterations allowed
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, meds, losses): (f64, _, _, _, _, _) = kmedoids::dynmsc(&data, &meds, 2, 100);
println!("Loss is: {}", loss);
println!("Best k: {}", meds.len());