pub struct HdpModel {
pub n_topics_active: usize,
/* private fields */
}Expand description
Hierarchical Dirichlet Process topic model.
Fitted with collapsed Gibbs sampling over the Chinese Restaurant Franchise.
After calling fit you can:
- Query
n_topics_activefor the inferred number of topics. - Call
transformto get topic distributions for new documents. - Call
top_wordsto inspect topic–word associations. - Call
coherenceto evaluate topic quality.
Fields§
§n_topics_active: usizeNumber of active topics inferred from data.
Implementations§
Source§impl HdpModel
impl HdpModel
Sourcepub fn fit(
&mut self,
corpus: &[Vec<usize>],
vocab_size: usize,
) -> Result<HdpResult>
pub fn fit( &mut self, corpus: &[Vec<usize>], vocab_size: usize, ) -> Result<HdpResult>
Fit the HDP model to corpus.
corpus is a slice of documents; each document is a Vec<usize>
of word indices (all indices must be < vocab_size).
§Errors
Returns an error if corpus is empty, vocab_size is zero, or
any word index is out of range.
Sourcepub fn transform(&self, doc: &[usize]) -> Result<Vec<f64>>
pub fn transform(&self, doc: &[usize]) -> Result<Vec<f64>>
Infer the topic distribution for a new (unseen) document.
Uses one pass of the E-step (word-topic probability normalisation) without modifying model parameters.
§Errors
Returns an error if the model is not fitted or doc is empty.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HdpModel
impl RefUnwindSafe for HdpModel
impl Send for HdpModel
impl Sync for HdpModel
impl Unpin for HdpModel
impl UnsafeUnpin for HdpModel
impl UnwindSafe for HdpModel
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.