pub struct WeightedKMeans { /* private fields */ }Expand description
A weighted clustering-problem where each center can be any point in the metric space.
Use KMeans instead if all your points have the same weight.
The metric space is the same space the weighted points live in.
The cost of a cluster, given a center, is the sum of the squared Euclidean distances between the center and each point in the cluster, multiplied by the point’s weight. The center is automatically calculated to minimise the cost, which turns out to simply be the weighted average of all point-positions in the cluster.
See the wikipedia-article on k-means-clustering for more information.
Implementations§
Source§impl WeightedKMeans
impl WeightedKMeans
Sourcepub fn new(weighted_points: &[WeightedPoint]) -> Result<Self, Error>
pub fn new(weighted_points: &[WeightedPoint]) -> Result<Self, Error>
Construct a new k-means clustering instance.
The algorithm runs significantly faster if you sort the points by weight first, merge points that have the same positions into one (adding their weights), and break symmetries by applying a small amount of noise.
TODO: Do so internally instead of at callsite. This probably requires better return-values
in the API. Afterwards, rework the get_high_kmeans_price_of_greedy_instance function in
integration-tests to not sort the points on its own.
§Examples
use ndarray::array;
use exact_clustering::WeightedKMeans;
WeightedKMeans::new(&[(1.0, array![0.0, 0.0]), (2.0, array![1.0, 2.0])]).unwrap();Trait Implementations§
Source§impl Clone for WeightedKMeans
impl Clone for WeightedKMeans
Source§fn clone(&self) -> WeightedKMeans
fn clone(&self) -> WeightedKMeans
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more