pub struct QuasiRandomRBFSampler<State = Untrained> {
pub gamma: Float,
pub n_components: usize,
pub sequence_type: QuasiRandomSequence,
pub random_state: Option<u64>,
/* private fields */
}Expand description
Quasi-random RBF sampler using low-discrepancy sequences
This sampler generates random Fourier features for RBF kernels using quasi-random sequences instead of pseudo-random numbers, providing better uniform coverage of the frequency space and improved approximation quality.
§Mathematical Background
For an RBF kernel k(x,y) = exp(-γ||x-y||²), the random Fourier features are: z(x) = √(2/n_components) * [cos(ω₁ᵀx + b₁), …, cos(ωₙᵀx + bₙ)]
Where ω ~ N(0, 2γI) and b ~ Uniform[0, 2π]. Using quasi-random sequences for generating ω and b provides better approximation properties.
§Examples
use sklears_kernel_approximation::{QuasiRandomRBFSampler, QuasiRandomSequence};
use sklears_core::traits::{Transform, Fit, Untrained}
use scirs2_core::ndarray::array;
let x = array![[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
let sampler = QuasiRandomRBFSampler::new(100)
.gamma(1.0)
.sequence_type(QuasiRandomSequence::Sobol);
let fitted = sampler.fit(&x, &()).unwrap();
let features = fitted.transform(&x).unwrap();
assert_eq!(features.shape(), &[3, 100]);QuasiRandomRBFSampler
Fields§
§gamma: FloatRBF kernel parameter
n_components: usizeNumber of Monte Carlo samples
sequence_type: QuasiRandomSequenceQuasi-random sequence type
random_state: Option<u64>Random seed for reproducibility
Implementations§
Source§impl QuasiRandomRBFSampler<Untrained>
impl QuasiRandomRBFSampler<Untrained>
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Create a new quasi-random RBF sampler
§Arguments
n_components- Number of Monte Carlo samples (random features)
Sourcepub fn sequence_type(self, sequence_type: QuasiRandomSequence) -> Self
pub fn sequence_type(self, sequence_type: QuasiRandomSequence) -> Self
Set the quasi-random sequence type
Sourcepub fn random_state(self, seed: u64) -> Self
pub fn random_state(self, seed: u64) -> Self
Set the random state for reproducibility
Trait Implementations§
Source§impl<State: Clone> Clone for QuasiRandomRBFSampler<State>
impl<State: Clone> Clone for QuasiRandomRBFSampler<State>
Source§fn clone(&self) -> QuasiRandomRBFSampler<State>
fn clone(&self) -> QuasiRandomRBFSampler<State>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<State: Debug> Debug for QuasiRandomRBFSampler<State>
impl<State: Debug> Debug for QuasiRandomRBFSampler<State>
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for QuasiRandomRBFSampler<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for QuasiRandomRBFSampler<Untrained>
Source§type Fitted = QuasiRandomRBFSampler<Trained>
type Fitted = QuasiRandomRBFSampler<Trained>
Source§fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
fn fit(self, x: &Array2<Float>, _y: &()) -> Result<Self::Fitted>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Auto Trait Implementations§
impl<State> Freeze for QuasiRandomRBFSampler<State>
impl<State> RefUnwindSafe for QuasiRandomRBFSampler<State>where
State: RefUnwindSafe,
impl<State> Send for QuasiRandomRBFSampler<State>where
State: Send,
impl<State> Sync for QuasiRandomRBFSampler<State>where
State: Sync,
impl<State> Unpin for QuasiRandomRBFSampler<State>where
State: Unpin,
impl<State> UnwindSafe for QuasiRandomRBFSampler<State>where
State: UnwindSafe,
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<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