pub struct Optimizer { /* private fields */ }Expand description
Active optimization state for UMAP embedding.
This contains all the state needed to run and resume stochastic gradient
descent optimization. It’s large and mutable, meant to be used during
training and then converted to a lightweight FittedUmap when done.
The optimizer can be serialized mid-training to enable fault-tolerant training with checkpoints.
Implementations§
Source§impl Optimizer
impl Optimizer
Sourcepub fn new(
manifold: LearnedManifold,
init: Array2<f32>,
total_epochs: usize,
opt_params: &UmapConfig,
metric_type: MetricType,
) -> Self
pub fn new( manifold: LearnedManifold, init: Array2<f32>, total_epochs: usize, opt_params: &UmapConfig, metric_type: MetricType, ) -> Self
Create a new optimizer from a learned manifold.
This performs preprocessing:
- Filters weak edges from the graph
- Extracts head/tail edge lists
- Computes epoch sampling schedules
- Normalizes the initial embedding to [0, 10]
§Arguments
manifold- The learned manifold structureinit- Initial embedding (will be normalized)total_epochs- Total number of epochs to runopt_params- Optimization parameters (learning rate, negative sampling, etc.)metric_type- Type of distance metric being used
Sourcepub fn step_epochs(&mut self, n: usize, output_metric: &dyn Metric)
pub fn step_epochs(&mut self, n: usize, output_metric: &dyn Metric)
Run n more epochs of stochastic gradient descent.
§Panics
Panics if this would exceed total_epochs. Check remaining_epochs() first.
Sourcepub fn current_epoch(&self) -> usize
pub fn current_epoch(&self) -> usize
Get the current epoch number.
Sourcepub fn total_epochs(&self) -> usize
pub fn total_epochs(&self) -> usize
Get the total epochs this optimizer is configured for.
Sourcepub fn remaining_epochs(&self) -> usize
pub fn remaining_epochs(&self) -> usize
Get the number of remaining epochs.
Sourcepub fn embedding(&self) -> ArrayView2<'_, f32>
pub fn embedding(&self) -> ArrayView2<'_, f32>
Get a view of the current embedding.
Sourcepub fn manifold(&self) -> &LearnedManifold
pub fn manifold(&self) -> &LearnedManifold
Get a reference to the learned manifold.
Sourcepub fn into_fitted(self, config: UmapConfig) -> FittedUmap
pub fn into_fitted(self, config: UmapConfig) -> FittedUmap
Consume the optimizer and return a lightweight fitted model.
This drops all the optimization state (epoch counters, preprocessed arrays) and keeps only the manifold and final embedding.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Optimizer
impl<'de> Deserialize<'de> for Optimizer
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>,
Auto Trait Implementations§
impl Freeze for Optimizer
impl RefUnwindSafe for Optimizer
impl Send for Optimizer
impl Sync for Optimizer
impl Unpin for Optimizer
impl UnwindSafe for Optimizer
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> 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>
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§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.