pub struct MultiScaleRBFSampler<State = Untrained> {
pub n_components_per_scale: usize,
pub n_scales: usize,
pub gamma_min: Float,
pub gamma_max: Float,
pub manual_gammas: Vec<Float>,
pub bandwidth_strategy: BandwidthStrategy,
pub combination_strategy: CombinationStrategy,
pub scale_weights: Vec<Float>,
pub random_state: Option<u64>,
/* private fields */
}Expand description
Multi-scale RBF sampler that generates random Fourier features at multiple scales
This sampler generates RBF kernel approximations using multiple bandwidth parameters (gamma values) to capture patterns at different scales. Each scale captures different frequency characteristics of the data, providing a more comprehensive representation.
§Mathematical Background
For multiple scales with bandwidths γ₁, γ₂, …, γₖ, the multi-scale RBF kernel is: K(x,y) = Σᵢ wᵢ * exp(-γᵢ||x-y||²)
The random Fourier features for each scale i are: zᵢ(x) = √(2/nᵢ) * [cos(ωᵢⱼᵀx + bᵢⱼ), sin(ωᵢⱼᵀx + bᵢⱼ)] where ωᵢⱼ ~ N(0, 2γᵢI) and bᵢⱼ ~ Uniform[0, 2π]
§Examples
use sklears_kernel_approximation::{MultiScaleRBFSampler, BandwidthStrategy, CombinationStrategy};
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 = MultiScaleRBFSampler::new(100)
.n_scales(3)
.gamma_range(0.1, 10.0)
.bandwidth_strategy(BandwidthStrategy::LogarithmicSpacing)
.combination_strategy(CombinationStrategy::Concatenation);
let fitted = sampler.fit(&x, &()).unwrap();
let features = fitted.transform(&x).unwrap();MultiScaleRBFSampler
Fields§
§n_components_per_scale: usizeNumber of components per scale
n_scales: usizeNumber of scales
gamma_min: FloatMinimum gamma value
gamma_max: FloatMaximum gamma value
manual_gammas: Vec<Float>Manual gamma values (used when strategy is Manual)
bandwidth_strategy: BandwidthStrategyBandwidth selection strategy
combination_strategy: CombinationStrategyFeature combination strategy
scale_weights: Vec<Float>Scale weights for weighted combination
random_state: Option<u64>Random seed for reproducibility
Implementations§
Source§impl MultiScaleRBFSampler<Untrained>
impl MultiScaleRBFSampler<Untrained>
Sourcepub fn new(n_components_per_scale: usize) -> Self
pub fn new(n_components_per_scale: usize) -> Self
Create a new multi-scale RBF sampler
§Arguments
n_components_per_scale- Number of random features per scale
Sourcepub fn gamma_range(self, gamma_min: Float, gamma_max: Float) -> Self
pub fn gamma_range(self, gamma_min: Float, gamma_max: Float) -> Self
Set the gamma range for automatic bandwidth selection
Sourcepub fn manual_gammas(self, gammas: Vec<Float>) -> Self
pub fn manual_gammas(self, gammas: Vec<Float>) -> Self
Set manual gamma values
Sourcepub fn bandwidth_strategy(self, strategy: BandwidthStrategy) -> Self
pub fn bandwidth_strategy(self, strategy: BandwidthStrategy) -> Self
Set the bandwidth selection strategy
Sourcepub fn combination_strategy(self, strategy: CombinationStrategy) -> Self
pub fn combination_strategy(self, strategy: CombinationStrategy) -> Self
Set the feature combination strategy
Sourcepub fn scale_weights(self, weights: Vec<Float>) -> Self
pub fn scale_weights(self, weights: Vec<Float>) -> Self
Set weights for different scales (used in weighted combination)
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 MultiScaleRBFSampler<State>
impl<State: Clone> Clone for MultiScaleRBFSampler<State>
Source§fn clone(&self) -> MultiScaleRBFSampler<State>
fn clone(&self) -> MultiScaleRBFSampler<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 MultiScaleRBFSampler<State>
impl<State: Debug> Debug for MultiScaleRBFSampler<State>
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for MultiScaleRBFSampler<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ()> for MultiScaleRBFSampler<Untrained>
Source§type Fitted = MultiScaleRBFSampler<Trained>
type Fitted = MultiScaleRBFSampler<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 MultiScaleRBFSampler<State>
impl<State> RefUnwindSafe for MultiScaleRBFSampler<State>where
State: RefUnwindSafe,
impl<State> Send for MultiScaleRBFSampler<State>where
State: Send,
impl<State> Sync for MultiScaleRBFSampler<State>where
State: Sync,
impl<State> Unpin for MultiScaleRBFSampler<State>where
State: Unpin,
impl<State> UnwindSafe for MultiScaleRBFSampler<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