pub struct GraphModularity {
pub k: usize,
}Expand description
Modularity of the category assignment on the k-NN graph of projected positions on S².
Modularity measures how well a partition (here: categories) aligns
with the community structure of a graph. Formally for a graph with
m edges, each node i with degree kᵢ, and community assignment
cᵢ:
Q = Σ_c [ (L_c / m) − (D_c / 2m)² ]where L_c is the number of edges inside community c and D_c is
the total degree of its members. Raw Q lies in [-0.5, 1.0]. We
clamp to [0, 1] since negative modularity (anti-structured
partition) is strictly worse than random assignment and shouldn’t be
rewarded differentially by the tuner.
This metric is connectivity-native — it evaluates “are same-category
points close in the neighbor graph” rather than “are same-category
points close in raw angular distance”. That makes it an honest
objective for connectivity-preserving projections like
LaplacianEigenmapProjection,
which otherwise get discounted by variance-centric metrics
(ClusterSilhouette) that reward PCA’s spread.
Edge construction is exact (all-pairs) below
[MODULARITY_ANN_THRESHOLD] items and ANN-backed above it, keeping
the metric usable inside tuner loops on 100k–500k corpora.
Fields§
§k: usizeNumber of nearest neighbors per node in the k-NN graph.
Larger k smooths local structure and blurs category boundaries;
smaller k is more sensitive to noise but resolves tighter
communities. Default 15.
Implementations§
Trait Implementations§
Source§impl Default for GraphModularity
impl Default for GraphModularity
Source§impl QualityMetric for GraphModularity
impl QualityMetric for GraphModularity
Source§fn score(&self, pipeline: &SphereQLPipeline) -> f64
fn score(&self, pipeline: &SphereQLPipeline) -> f64
[0, 1].Source§fn score_with_components(
&self,
pipeline: &SphereQLPipeline,
) -> (f64, Vec<(String, f64, f64)>)
fn score_with_components( &self, pipeline: &SphereQLPipeline, ) -> (f64, Vec<(String, f64, f64)>)
(score, components) where each
component is (name, weight, component_score). Read moreAuto Trait Implementations§
impl Freeze for GraphModularity
impl RefUnwindSafe for GraphModularity
impl Send for GraphModularity
impl Sync for GraphModularity
impl Unpin for GraphModularity
impl UnsafeUnpin for GraphModularity
impl UnwindSafe for GraphModularity
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
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 more