pub struct GaussianRandomProjection<F> { /* private fields */ }Expand description
Gaussian random projection transformer.
Projects data into a lower-dimensional space using a random matrix drawn
from N(0, 1/n_components).
§Examples
use ferrolearn_preprocess::random_projection::GaussianRandomProjection;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::Array2;
let x = Array2::<f64>::ones((10, 50));
let proj = GaussianRandomProjection::<f64>::new(5);
let fitted = proj.fit(&x, &()).unwrap();
let out = fitted.transform(&x).unwrap();
assert_eq!(out.shape(), &[10, 5]);Implementations§
Source§impl<F: Float + Send + Sync + 'static> GaussianRandomProjection<F>
impl<F: Float + Send + Sync + 'static> GaussianRandomProjection<F>
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Create a new Gaussian random projection with an explicit n_components
number of output dimensions (NComponents::Fixed).
Sourcepub fn new_auto() -> Self
pub fn new_auto() -> Self
Create a new Gaussian random projection with n_components='auto'
(sklearn default): the target dimension is resolved at fit time from the
Johnson-Lindenstrauss bound for the configured eps
(random_projection.py:388-391).
Sourcepub fn eps(self, eps: f64) -> Self
pub fn eps(self, eps: f64) -> Self
Set the distortion-rate eps used by the Auto JL bound
(sklearn eps, random_projection.py:328).
Sourcepub fn random_state(self, seed: u64) -> Self
pub fn random_state(self, seed: u64) -> Self
Set the random seed for reproducibility.
Trait Implementations§
Source§impl<F: Clone> Clone for GaussianRandomProjection<F>
impl<F: Clone> Clone for GaussianRandomProjection<F>
Source§fn clone(&self) -> GaussianRandomProjection<F>
fn clone(&self) -> GaussianRandomProjection<F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for GaussianRandomProjection<F>
impl<F: Debug> Debug for GaussianRandomProjection<F>
Source§impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for GaussianRandomProjection<F>
impl<F: Float + Send + Sync + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ()> for GaussianRandomProjection<F>
Source§fn fit(
&self,
x: &Array2<F>,
_y: &(),
) -> Result<FittedGaussianRandomProjection<F>, FerroError>
fn fit( &self, x: &Array2<F>, _y: &(), ) -> Result<FittedGaussianRandomProjection<F>, FerroError>
Fit the projection by generating a random matrix R ~ N(0, 1/n_components).
When n_components is NComponents::Auto the target dimension is
resolved from the Johnson-Lindenstrauss bound for eps
(random_projection.py:388-391).
§Errors
Returns FerroError::InvalidParameter if the resolved n_components
is 0 (explicit, or the JL bound resolving to <= 0,
random_projection.py:393-397), or if eps is outside (0, 1) for the
Auto path. Returns FerroError::InsufficientSamples if x has zero
rows.
Source§type Fitted = FittedGaussianRandomProjection<F>
type Fitted = FittedGaussianRandomProjection<F>
fit.Source§type Error = FerroError
type Error = FerroError
fit.Source§impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for GaussianRandomProjection<F>
impl<F: Float + Send + Sync + 'static> FitTransform<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for GaussianRandomProjection<F>
Source§fn fit_transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
fn fit_transform(&self, x: &Array2<F>) -> Result<Array2<F>, FerroError>
Fit and transform in one step.
Source§type FitError = FerroError
type FitError = FerroError
Source§impl<F: Float + Send + Sync + 'static> PipelineTransformer<F> for GaussianRandomProjection<F>
impl<F: Float + Send + Sync + 'static> PipelineTransformer<F> for GaussianRandomProjection<F>
Source§fn fit_pipeline(
&self,
x: &Array2<F>,
_y: &Array1<F>,
) -> Result<Box<dyn FittedPipelineTransformer<F>>, FerroError>
fn fit_pipeline( &self, x: &Array2<F>, _y: &Array1<F>, ) -> Result<Box<dyn FittedPipelineTransformer<F>>, FerroError>
Auto Trait Implementations§
impl<F> Freeze for GaussianRandomProjection<F>
impl<F> RefUnwindSafe for GaussianRandomProjection<F>where
F: RefUnwindSafe,
impl<F> Send for GaussianRandomProjection<F>where
F: Send,
impl<F> Sync for GaussianRandomProjection<F>where
F: Sync,
impl<F> Unpin for GaussianRandomProjection<F>where
F: Unpin,
impl<F> UnsafeUnpin for GaussianRandomProjection<F>
impl<F> UnwindSafe for GaussianRandomProjection<F>where
F: 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> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
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 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>
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.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§unsafe fn to_subset_unchecked(&self) -> SS
unsafe 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.