pub struct SparseAutoencoder {
pub encoder_w: Vec<Vec<f32>>,
pub encoder_b: Vec<f32>,
pub decoder_w: Vec<Vec<f32>>,
pub decoder_b: Vec<f32>,
}Expand description
Sparse autoencoder with k-winner-takes-all activation.
Fields§
§encoder_w: Vec<Vec<f32>>Encoder weight matrix (hidden_dim × input_dim).
encoder_b: Vec<f32>Encoder bias vector.
decoder_w: Vec<Vec<f32>>Decoder weight matrix (input_dim × hidden_dim).
decoder_b: Vec<f32>Decoder bias vector.
Implementations§
Source§impl SparseAutoencoder
impl SparseAutoencoder
Sourcepub fn new(config: &SaeConfig, rng: &mut impl Rng) -> Self
pub fn new(config: &SaeConfig, rng: &mut impl Rng) -> Self
Create a new sparse autoencoder with Xavier initialization.
Sourcepub fn decode(&self, z: &[f32]) -> Vec<f32>
pub fn decode(&self, z: &[f32]) -> Vec<f32>
Decode the latent representation back to the input space.
Sourcepub fn reconstruction_loss(&self, x: &[f32]) -> f32
pub fn reconstruction_loss(&self, x: &[f32]) -> f32
Mean squared reconstruction error.
Sourcepub fn sparsity_loss(&self, z: &[f32]) -> f32
pub fn sparsity_loss(&self, z: &[f32]) -> f32
KL-divergence sparsity penalty on hidden activations.
Sourcepub fn total_loss(&self, x: &[f32], config: &SaeConfig) -> f32
pub fn total_loss(&self, x: &[f32], config: &SaeConfig) -> f32
Total loss = reconstruction + sparsity_weight * sparsity.
Sourcepub fn kl_divergence_bernoulli(rho: f32, rho_hat: f32) -> f32
pub fn kl_divergence_bernoulli(rho: f32, rho_hat: f32) -> f32
KL divergence between Bernoulli(rho) and Bernoulli(rho_hat).
Trait Implementations§
Source§impl Clone for SparseAutoencoder
impl Clone for SparseAutoencoder
Source§fn clone(&self) -> SparseAutoencoder
fn clone(&self) -> SparseAutoencoder
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 moreAuto Trait Implementations§
impl Freeze for SparseAutoencoder
impl RefUnwindSafe for SparseAutoencoder
impl Send for SparseAutoencoder
impl Sync for SparseAutoencoder
impl Unpin for SparseAutoencoder
impl UnsafeUnpin for SparseAutoencoder
impl UnwindSafe for SparseAutoencoder
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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