pub struct EmbeddingClusterAnalyzer {
pub config: EcaAnalyzerConfig,
pub points: Vec<EcaClusterPoint>,
pub clusters: Vec<ClusterDescriptor>,
pub total_analyses: u64,
/* private fields */
}Expand description
Comprehensive cluster analysis system for embedding spaces.
Tracks points and their cluster assignments, computes quality metrics, detects outliers, estimates local density, and identifies cluster drift relative to a previous snapshot.
Fields§
§config: EcaAnalyzerConfigAnalyzer configuration.
points: Vec<EcaClusterPoint>All points currently held by the analyzer.
clusters: Vec<ClusterDescriptor>Registered cluster descriptors.
total_analyses: u64Cumulative number of compute_cluster_quality calls.
Implementations§
Source§impl EmbeddingClusterAnalyzer
impl EmbeddingClusterAnalyzer
Sourcepub fn new(config: EcaAnalyzerConfig) -> Self
pub fn new(config: EcaAnalyzerConfig) -> Self
Create a new analyzer with the given configuration.
Sourcepub fn add_point(
&mut self,
id: String,
embedding: Vec<f64>,
cluster: Option<ClusterId>,
)
pub fn add_point( &mut self, id: String, embedding: Vec<f64>, cluster: Option<ClusterId>, )
Add an embedding point to the analyzer.
distance_to_centroid starts at 0.0; call set_clusters or
recompute_distances to update it.
Sourcepub fn set_clusters(&mut self, descriptors: Vec<ClusterDescriptor>)
pub fn set_clusters(&mut self, descriptors: Vec<ClusterDescriptor>)
Replace the cluster descriptors and re-assign / recompute distances.
For each point whose cluster field is None, the nearest cluster
(by cosine distance to centroid) is assigned. Then distance_to_centroid
is recomputed for every point using L2 distance to its centroid.
Sourcepub fn l2_distance(a: &[f64], b: &[f64]) -> f64
pub fn l2_distance(a: &[f64], b: &[f64]) -> f64
Euclidean (L2) distance between two vectors.
Returns 0.0 if either slice is empty.
Sourcepub fn cosine_distance(a: &[f64], b: &[f64]) -> f64
pub fn cosine_distance(a: &[f64], b: &[f64]) -> f64
Cosine distance (1 − cosine similarity) between two vectors.
Returns 1.0 if either vector has zero norm.
Sourcepub fn compute_cluster_quality(&mut self) -> ClusterQuality
pub fn compute_cluster_quality(&mut self) -> ClusterQuality
Compute comprehensive cluster quality metrics.
Increments total_analyses on each call.
Sourcepub fn detect_outliers(&mut self) -> Vec<OutlierScore>
pub fn detect_outliers(&mut self) -> Vec<OutlierScore>
Detect outlier points using three strategies:
- FarFromCentroid — per-cluster z-score of
distance_to_centroid>threshold_sigma - IsolatedPoint — member of a cluster with fewer than
min_cluster_sizepoints
Results are capped at max_outlier_fraction × total_points, ordered by
descending outlier score.
Sourcepub fn local_density(&self, point_idx: usize) -> f64
pub fn local_density(&self, point_idx: usize) -> f64
Estimate the local density around a point (by index).
Counts how many other points lie within density_radius (L2).
Returns 0.0 for invalid indices.
Sourcepub fn cluster_evolution(&self, prev: &EmbeddingClusterAnalyzer) -> Vec<String>
pub fn cluster_evolution(&self, prev: &EmbeddingClusterAnalyzer) -> Vec<String>
Compare cluster centroids between self (current) and prev (snapshot).
For each cluster in self, finds the closest cluster in prev by L2
centroid distance. If the distance exceeds 0.1, a message is appended:
"cluster {id} shifted by {dist:.3}".
Sourcepub fn top_k_by_cluster(
&self,
cluster: ClusterId,
k: usize,
) -> Vec<&EcaClusterPoint>
pub fn top_k_by_cluster( &self, cluster: ClusterId, k: usize, ) -> Vec<&EcaClusterPoint>
Return the k points in cluster that are closest to the centroid.
Points are ordered by ascending distance_to_centroid.
Returns an empty Vec if the cluster does not exist.
Sourcepub fn analyzer_stats(&self) -> EcaAnalyzerStats
pub fn analyzer_stats(&self) -> EcaAnalyzerStats
Return a summary of the current analyzer state.
Auto Trait Implementations§
impl Freeze for EmbeddingClusterAnalyzer
impl RefUnwindSafe for EmbeddingClusterAnalyzer
impl Send for EmbeddingClusterAnalyzer
impl Sync for EmbeddingClusterAnalyzer
impl Unpin for EmbeddingClusterAnalyzer
impl UnsafeUnpin for EmbeddingClusterAnalyzer
impl UnwindSafe for EmbeddingClusterAnalyzer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.