pub struct NUTSSampler { /* private fields */ }Expand description
No-U-Turn Sampler for Bayesian Mixture Models
NUTS is an adaptive variant of Hamiltonian Monte Carlo that automatically determines the number of leapfrog steps by continuing until the trajectory starts to “turn around” and move back towards its starting point. This makes it highly efficient for exploring complex posterior distributions without requiring manual tuning of the trajectory length.
§Parameters
n_components- Number of mixture componentsn_samples- Number of MCMC samples to drawn_warmup- Number of warmup samples for adaptationstep_size- Initial step size for leapfrog integrationtarget_accept_rate- Target acceptance rate for step size adaptationmax_tree_depth- Maximum tree depth to prevent infinite loopsadapt_step_size- Whether to adapt step size during warmupadapt_mass_matrix- Whether to adapt the mass matrix during warmuprandom_state- Random state for reproducibility
§Examples
use sklears_mixture::{NUTSSampler, CovarianceType};
use scirs2_core::ndarray::array;
let X = array![[0.0, 0.0], [1.0, 1.0], [2.0, 2.0], [10.0, 10.0], [11.0, 11.0], [12.0, 12.0]];
let nuts = NUTSSampler::new()
.n_components(2)
.n_samples(1000)
.n_warmup(500)
.target_accept_rate(0.8)
.max_tree_depth(10);
let result = nuts.sample(&X.view()).unwrap();Implementations§
Source§impl NUTSSampler
impl NUTSSampler
Sourcepub fn builder() -> Self
pub fn builder() -> Self
Create a new NUTSSampler instance using builder pattern (alias for new)
Sourcepub fn n_components(self, n_components: usize) -> Self
pub fn n_components(self, n_components: usize) -> Self
Set the number of components
Sourcepub fn target_accept_rate(self, rate: f64) -> Self
pub fn target_accept_rate(self, rate: f64) -> Self
Set the target acceptance rate
Sourcepub fn max_tree_depth(self, depth: usize) -> Self
pub fn max_tree_depth(self, depth: usize) -> Self
Set the maximum tree depth
Sourcepub fn adapt_step_size(self, adapt: bool) -> Self
pub fn adapt_step_size(self, adapt: bool) -> Self
Set whether to adapt step size
Sourcepub fn adapt_mass_matrix(self, adapt: bool) -> Self
pub fn adapt_mass_matrix(self, adapt: bool) -> Self
Set whether to adapt mass matrix
Sourcepub fn random_state(self, random_state: u64) -> Self
pub fn random_state(self, random_state: u64) -> Self
Set the random state
Sourcepub fn sample(&self, X: &ArrayView2<'_, Float>) -> SklResult<NUTSResult>
pub fn sample(&self, X: &ArrayView2<'_, Float>) -> SklResult<NUTSResult>
Sample from the posterior distribution of a Gaussian mixture model
Trait Implementations§
Source§impl Clone for NUTSSampler
impl Clone for NUTSSampler
Source§fn clone(&self) -> NUTSSampler
fn clone(&self) -> NUTSSampler
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 NUTSSampler
impl Debug for NUTSSampler
Auto Trait Implementations§
impl Freeze for NUTSSampler
impl RefUnwindSafe for NUTSSampler
impl Send for NUTSSampler
impl Sync for NUTSSampler
impl Unpin for NUTSSampler
impl UnwindSafe for NUTSSampler
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