Skip to content

Panic when asking for more clusters than there are distinct values #5

@Apanatshka

Description

@Apanatshka

The panic is:

thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.5.6/src/distributions/mod.rs:525:9:
WeightedChoice::new called with a total weight of 0
stack backtrace:
   0: std::panicking::begin_panic
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:693:12
   1: rand::distributions::WeightedChoice<T>::new
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.5.6/src/distributions/mod.rs:525:9
   2: rkm::initialize_plusplus
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rkm-0.8.1/src/lib.rs:214:23
   3: rkm::kmeans_lloyd_with_config
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rkm-0.8.1/src/lib.rs:370:25
   4: rkm::kmeans_lloyd
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rkm-0.8.1/src/lib.rs:394:5

A simple example program that have this behaviour:

    let data = Array2::from_shape_vec((3, 1), vec![2365.0_f64, 2365.0_f64, 2365.0_f64]).unwrap();
    rkm::kmeans_lloyd(&data.view(), 2);

Or:

    let data = Array2::from_shape_vec((3, 1), vec![2365.0_f64, 2365.0_f64, 4589.0_f64]).unwrap();
    rkm::kmeans_lloyd(&data.view(), 3);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions