pub struct CorrelationClustering { /* private fields */ }Expand description
Correlation clustering via PIVOT with optional local search refinement.
use clump::cluster::correlation::{CorrelationClustering, SignedEdge};
let edges = vec![
SignedEdge { i: 0, j: 1, weight: 1.0 },
SignedEdge { i: 0, j: 2, weight: -1.0 },
SignedEdge { i: 1, j: 2, weight: -1.0 },
];
let result = CorrelationClustering::new()
.with_seed(42)
.fit(3, &edges)
.unwrap();
assert_eq!(result.labels[0], result.labels[1]);
assert_ne!(result.labels[0], result.labels[2]);Implementations§
Source§impl CorrelationClustering
impl CorrelationClustering
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new correlation clusterer with default parameters.
Defaults: max_iter = 100, no fixed seed.
Sourcepub fn with_max_iter(self, max_iter: usize) -> Self
pub fn with_max_iter(self, max_iter: usize) -> Self
Set the maximum number of local search iterations.
Pass 0 to skip local search and return the raw PIVOT solution.
Sourcepub fn fit(
&self,
n_items: usize,
edges: &[SignedEdge],
) -> Result<CorrelationResult>
pub fn fit( &self, n_items: usize, edges: &[SignedEdge], ) -> Result<CorrelationResult>
Cluster items based on signed pairwise edges.
n_items: total number of items. Items with no edges become singletons.edges: signed pairwise relationships.
Returns Error::InvalidParameter if any edge references an item index
>= n_items.
Sourcepub fn edges_from_distances<D: DistanceMetric>(
data: &[Vec<f32>],
metric: &D,
threshold: f32,
) -> Vec<SignedEdge>
pub fn edges_from_distances<D: DistanceMetric>( data: &[Vec<f32>], metric: &D, threshold: f32, ) -> Vec<SignedEdge>
Create signed edges from a distance matrix and a threshold.
Pairs closer than threshold get positive weight = threshold - distance.
Pairs farther than threshold get negative weight = threshold - distance
(which is negative). Pairs at exactly threshold get weight 0 and are
included but contribute no cost.
Trait Implementations§
Source§impl Clone for CorrelationClustering
impl Clone for CorrelationClustering
Source§fn clone(&self) -> CorrelationClustering
fn clone(&self) -> CorrelationClustering
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CorrelationClustering
impl Debug for CorrelationClustering
Auto Trait Implementations§
impl Freeze for CorrelationClustering
impl RefUnwindSafe for CorrelationClustering
impl Send for CorrelationClustering
impl Sync for CorrelationClustering
impl Unpin for CorrelationClustering
impl UnsafeUnpin for CorrelationClustering
impl UnwindSafe for CorrelationClustering
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more