pub struct TSNE { /* private fields */ }Expand description
t-SNE for dimensionality reduction and visualization.
t-Distributed Stochastic Neighbor Embedding (t-SNE) is a non-linear dimensionality reduction technique optimized for visualization of high-dimensional data in 2D or 3D space.
§Algorithm
- Compute pairwise similarities in high-D using Gaussian kernel
- Compute perplexity-based conditional probabilities
- Initialize low-D embedding (random or PCA)
- Compute pairwise similarities in low-D using Student’s t-distribution
- Minimize KL divergence via gradient descent with momentum
§Example
use aprender::prelude::*;
use aprender::preprocessing::TSNE;
let data = Matrix::from_vec(
6,
4,
vec![
1.0, 2.0, 3.0, 4.0,
1.1, 2.1, 3.1, 4.1,
5.0, 6.0, 7.0, 8.0,
5.1, 6.1, 7.1, 8.1,
10.0, 11.0, 12.0, 13.0,
10.1, 11.1, 12.1, 13.1,
],
)
.expect("valid matrix dimensions");
let mut tsne = TSNE::new(2).with_perplexity(5.0).with_n_iter(250);
let embedding = tsne.fit_transform(&data).expect("fit_transform should succeed");
assert_eq!(embedding.shape(), (6, 2));Implementations§
Source§impl TSNE
impl TSNE
Sourcepub fn new(n_components: usize) -> Self
pub fn new(n_components: usize) -> Self
Create a new t-SNE with default parameters.
Default: perplexity=30.0, learning_rate=200.0, n_iter=1000
Sourcepub fn with_perplexity(self, perplexity: f32) -> Self
pub fn with_perplexity(self, perplexity: f32) -> Self
Set perplexity (balance between local and global structure).
Typical range: 5-50. Higher perplexity considers more neighbors.
Sourcepub fn with_learning_rate(self, learning_rate: f32) -> Self
pub fn with_learning_rate(self, learning_rate: f32) -> Self
Set learning rate for gradient descent.
Sourcepub fn with_n_iter(self, n_iter: usize) -> Self
pub fn with_n_iter(self, n_iter: usize) -> Self
Set number of gradient descent iterations.
Sourcepub fn with_random_state(self, seed: u64) -> Self
pub fn with_random_state(self, seed: u64) -> Self
Set random seed for reproducibility.
Sourcepub fn n_components(&self) -> usize
pub fn n_components(&self) -> usize
Get number of components.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TSNE
impl<'de> Deserialize<'de> for TSNE
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TSNE
impl RefUnwindSafe for TSNE
impl Send for TSNE
impl Sync for TSNE
impl Unpin for TSNE
impl UnwindSafe for TSNE
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 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.