pub struct KMedian { /* private fields */ }Expand description
A clustering-problem where each center must be one of the points that are to be clustered.
The cost is supplied using a distance-function between points. The cost of a cluster, given a center, is the sum of the distances between the center and all points in the cluster. The cost of a cluster will always be calculated by choosing the center yielding the smallest cost.
Implementations§
Source§impl KMedian
impl KMedian
Sourcepub fn l2_squared(points: &[Point]) -> Result<Self, Error>
pub fn l2_squared(points: &[Point]) -> Result<Self, Error>
Create a k-median clustering instance using the squared L2-norm.
§Examples
use ndarray::array;
use exact_clustering::KMedian;
KMedian::l2_squared(&[array![0.0, 0.0], array![1.0, 2.0]]).unwrap();Sourcepub fn l2(points: &[Point]) -> Result<Self, Error>
pub fn l2(points: &[Point]) -> Result<Self, Error>
Create a k-median clustering instance using the L2-norm.
§Examples
use ndarray::array;
use exact_clustering::KMedian;
KMedian::l2(&[array![0.0, 0.0], array![1.0, 2.0]]).unwrap();TODO: This is uncovered by tests.
Sourcepub fn l1(points: &[Point]) -> Result<Self, Error>
pub fn l1(points: &[Point]) -> Result<Self, Error>
Create a k-median clustering instance using the L1-norm.
§Examples
use ndarray::array;
use exact_clustering::KMedian;
KMedian::l1(&[array![0.0, 0.0], array![1.0, 2.0]]).unwrap();Sourcepub fn weighted_l2_squared(
weighted_points: &[WeightedPoint],
) -> Result<Self, Error>
pub fn weighted_l2_squared( weighted_points: &[WeightedPoint], ) -> Result<Self, Error>
Create a k-median clustering instance using the squared L2-norm.
Use KMedian::l2_squared instead if all your points have the same weight.
The distance between a weighted point (w, p) and the center (v, c) is the
squared euclidean-distance between c and p,
multiplied by w.
For instance, the center of the cluster {(1, [0,0]), (2, [3,0])} will be (2, [3,0]), because the cost
of choosing that center is 9, whereas the cost of choosing (1, [0,0]) as a center is 18.
§Examples
use ndarray::array;
use exact_clustering::KMedian;
KMedian::weighted_l2_squared(&[(1.0, array![0.0, 0.0]), (2.0, array![1.0, 2.0])]).unwrap();Sourcepub fn weighted_l2(weighted_points: &[WeightedPoint]) -> Result<Self, Error>
pub fn weighted_l2(weighted_points: &[WeightedPoint]) -> Result<Self, Error>
Create a k-median clustering instance using the L2-norm.
Use KMedian::l2 instead if all your points have the same weight.
The distance between a weighted point (w, p) and the center (v, c) is the
euclidean-distance between c and p,
multiplied by w.
§Examples
use ndarray::array;
use exact_clustering::KMedian;
KMedian::weighted_l2(&[(1.0, array![0.0, 0.0]), (2.0, array![1.0, 2.0])]).unwrap();TODO: This is uncovered by tests.
Sourcepub fn weighted_l1(weighted_points: &[WeightedPoint]) -> Result<Self, Error>
pub fn weighted_l1(weighted_points: &[WeightedPoint]) -> Result<Self, Error>
Create a k-median clustering instance using the L1-norm.
Use KMedian::l1 instead if all your points have the same weight.
The distance between a weighted point (w, p) and the center (v, c) is the
taxicab-distance between c and p, multiplied by w.
For instance, the center of the cluster {(1, [0,0]), (2, [3,0])} will be (2, [3,0]), because the cost
of choosing that center is 3, whereas the cost of choosing (1, [0,0]) as a center is 6.
§Examples
use ndarray::array;
use exact_clustering::KMedian;
KMedian::weighted_l1(&[(1.0, array![0.0, 0.0]), (2.0, array![1.0, 2.0])]).unwrap();