pub struct Variable {
pub id: VariableId,
pub value: f64,
pub gradient: f64,
pub node: Option<Arc<ComputationNode>>,
}Expand description
Variable for reverse-mode automatic differentiation
Fields§
§id: VariableIdUnique variable identifier
value: f64Current value
gradient: f64Gradient (populated during backpropagation)
node: Option<Arc<ComputationNode>>Computation graph node
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn with_graph(value: f64, tape: Arc<Mutex<ComputationTape>>) -> Self
pub fn with_graph(value: f64, tape: Arc<Mutex<ComputationTape>>) -> Self
Create a variable with computation graph tracking
Sourcepub fn set_gradient(&mut self, gradient: f64)
pub fn set_gradient(&mut self, gradient: f64)
Set gradient value
Sourcepub fn add_gradient(&mut self, gradient: f64)
pub fn add_gradient(&mut self, gradient: f64)
Add to gradient (for accumulation)
Sourcepub fn zero_gradient(&mut self)
pub fn zero_gradient(&mut self)
Reset gradient to zero
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Variable
impl !RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl !UnwindSafe for Variable
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 more