pub struct GnnOptimizer<T: Float + Debug + Send + Sync + 'static> { /* private fields */ }Expand description
A learned optimizer driven by a message-passing GNN with a GRU node update.
Implements AdvancedOptimizer. The learned weights are fixed; the per-node
EMAs and GRU hidden vectors are persistent state that evolves across steps.
Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> GnnOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> GnnOptimizer<T>
Sourcepub fn weight_vector(&self) -> Vec<f64>
pub fn weight_vector(&self) -> Vec<f64>
Every learned weight, flattened in a stable order.
The layout is an implementation detail, but it is stable across calls on
the same architecture, which is what a meta-training loop needs:
set_weight_vector(&weight_vector()) is the identity.
Sourcepub fn weight_count(&self) -> usize
pub fn weight_count(&self) -> usize
Number of learned weights.
Sourcepub fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
pub fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
Overwrite every learned weight from a vector laid out like
Self::weight_vector’s output.
§Errors
Returns crate::error::OptimError::InvalidConfig if flat is not
exactly the right length for this architecture — a silent partial load
would leave the network in a state no caller could reason about.
Sourcepub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Clear the persistent optimization state (per-node EMAs, GRU hidden vectors, step count, graph layout) while keeping the learned weights.
Meta-training evaluates the same weights on several tasks, and a rollout must not inherit momentum from the previous one. The graph layout is discarded too because it is derived from the parameter length, which differs between tasks; it is rebuilt lazily on the next step.
Source§impl<T: Float + Debug + Send + Sync + 'static> GnnOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> GnnOptimizer<T>
Sourcepub fn new(config: GnnOptimizerConfig) -> Result<Self>
pub fn new(config: GnnOptimizerConfig) -> Result<Self>
Construct a new optimizer from a configuration.
The learned weights are initialised deterministically from config.seed.
Graph-dependent state is created lazily on the first AdvancedOptimizer::step
once the parameter length is known.
§Errors
Returns OptimError::InvalidConfig if a hyper-parameter is out of range.
Sourcepub fn num_nodes(&self) -> usize
pub fn num_nodes(&self) -> usize
The actual number of graph nodes (after clamping to the parameter count).
Returns 0 before the first step, when the parameter length is unknown.
The GRU hidden / message dimension.
Trait Implementations§
Source§impl<T: Float + Debug + Send + Sync + 'static> AdvancedOptimizer<T> for GnnOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> AdvancedOptimizer<T> for GnnOptimizer<T>
Source§fn step(
&mut self,
params: &Array1<T>,
gradients: &Array1<T>,
) -> Result<Array1<T>>
fn step( &mut self, params: &Array1<T>, gradients: &Array1<T>, ) -> Result<Array1<T>>
Source§fn get_learning_rate(&self) -> T
fn get_learning_rate(&self) -> T
Source§fn set_learning_rate(&mut self, lr: T)
fn set_learning_rate(&mut self, lr: T)
Source§fn get_state(&self) -> OptimizerStateInfo<T>
fn get_state(&self) -> OptimizerStateInfo<T>
Source§impl<T: Float + Debug + Send + Sync + 'static> MetaTrainable<T> for GnnOptimizer<T>
impl<T: Float + Debug + Send + Sync + 'static> MetaTrainable<T> for GnnOptimizer<T>
Source§fn weight_vector(&self) -> Vec<f64>
fn weight_vector(&self) -> Vec<f64>
set_weight_vector(&weight_vector()) is the identity.Source§fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
fn set_weight_vector(&mut self, flat: &[f64]) -> Result<()>
Self::weight_vector’s output. Read moreSource§fn reset_state(&mut self)
fn reset_state(&mut self)
Source§fn weight_count(&self) -> usize
fn weight_count(&self) -> usize
Auto Trait Implementations§
impl<T> Freeze for GnnOptimizer<T>
impl<T> RefUnwindSafe for GnnOptimizer<T>where
T: RefUnwindSafe,
GnnWeights<T>: RefUnwindSafe,
ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: RefUnwindSafe,
Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: RefUnwindSafe,
impl<T> Send for GnnOptimizer<T>
impl<T> Sync for GnnOptimizer<T>
impl<T> Unpin for GnnOptimizer<T>
impl<T> UnsafeUnpin for GnnOptimizer<T>where
T: UnsafeUnpin,
GnnWeights<T>: UnsafeUnpin,
ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: UnsafeUnpin,
Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: UnsafeUnpin,
impl<T> UnwindSafe for GnnOptimizer<T>where
T: UnwindSafe,
GnnWeights<T>: UnwindSafe,
ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>: UnwindSafe,
Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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.