pub struct DirichletProcess {
pub alpha: f64,
pub assignments: Vec<usize>,
pub cluster_counts: Vec<usize>,
pub cluster_means: Vec<f64>,
pub cluster_ss: Vec<f64>,
pub n_assigned: usize,
}Expand description
Dirichlet Process mixture model using the Chinese Restaurant Process.
New data points are assigned to existing clusters with probability proportional to cluster size, or start a new cluster with probability α/(n+α).
Fields§
§alpha: f64Concentration parameter α.
assignments: Vec<usize>Cluster assignments for each observed data point.
cluster_counts: Vec<usize>Number of points in each cluster.
cluster_means: Vec<f64>Cluster means (updated incrementally).
cluster_ss: Vec<f64>Cluster sum of squares (for variance estimation).
n_assigned: usizeTotal number of data points assigned.
Implementations§
Source§impl DirichletProcess
impl DirichletProcess
Sourcepub fn n_clusters(&self) -> usize
pub fn n_clusters(&self) -> usize
Returns the number of clusters.
Sourcepub fn crp_assign(&mut self, x: f64) -> usize
pub fn crp_assign(&mut self, x: f64) -> usize
Assigns a new data point via Chinese Restaurant Process probabilities.
Returns the cluster index assigned (deterministic: picks highest prob).
Sourcepub fn stick_breaking_weights(&self, k: usize) -> Vec<f64>
pub fn stick_breaking_weights(&self, k: usize) -> Vec<f64>
Stick-breaking construction: samples first k mixture weights.
Returns weights (w_1, ..., w_k) where Σ w_i ≈ 1.
Uses pseudo-random beta draws based on alpha and index.
Sourcepub fn cluster_variances(&self) -> Vec<f64>
pub fn cluster_variances(&self) -> Vec<f64>
Returns cluster variance estimates (unbiased).
Sourcepub fn expected_clusters(alpha: f64, n: usize) -> f64
pub fn expected_clusters(alpha: f64, n: usize) -> f64
Returns the expected number of clusters for n observations (approximation).
E[K_n] ≈ α ln(1 + n/α)
Trait Implementations§
Source§impl Clone for DirichletProcess
impl Clone for DirichletProcess
Source§fn clone(&self) -> DirichletProcess
fn clone(&self) -> DirichletProcess
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DirichletProcess
impl RefUnwindSafe for DirichletProcess
impl Send for DirichletProcess
impl Sync for DirichletProcess
impl Unpin for DirichletProcess
impl UnsafeUnpin for DirichletProcess
impl UnwindSafe for DirichletProcess
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.