Struct wyrm::Variable [−][src]
pub struct Variable<T> where
T: Node, { /* fields omitted */ }
Handle to a node in the computation graph. The underlying nodes are reference counted, so the handles can be freely cloned to use the nodes multiple times in the same graph.
Methods
impl<T> Variable<T> where
T: Node,
[src]
impl<T> Variable<T> where
T: Node,
pub fn value(&self) -> Bor<T::Value>
[src]
pub fn value(&self) -> Bor<T::Value>
Get the value of the node.
pub fn forward(&self)
[src]
pub fn forward(&self)
Run the forward pass through the subgraph terminating at this node, recursing through the ancestor nodes.
pub fn clear(&self)
[src]
pub fn clear(&self)
Clear the graph caches. Must be called whenever inputs change and [backward] is not called.
pub fn zero_gradient(&self)
[src]
pub fn zero_gradient(&self)
Zero the accumulated gradients for the parameter nodes in this graph.
pub fn parameters(&self) -> &[Variable<ParameterNode>]
[src]
pub fn parameters(&self) -> &[Variable<ParameterNode>]
Return the parameters of the graph.
pub fn parameters_mut(&mut self) -> &mut [Variable<ParameterNode>]
[src]
pub fn parameters_mut(&mut self) -> &mut [Variable<ParameterNode>]
Mutably return the parameters of the graph.
impl<T> Variable<T> where
T: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<T> Variable<T> where
T: Node<Value = Arr, InputGradient = Arr>,
pub fn boxed(&self) -> Variable<Rc<Node<Value = Arr, InputGradient = Arr>>>
[src]
pub fn boxed(&self) -> Variable<Rc<Node<Value = Arr, InputGradient = Arr>>>
Box the variable, erasing its specific type. Use to manage the complexity of variable types in deep computation graphs.
pub fn backward(&mut self, weight: f32)
[src]
pub fn backward(&mut self, weight: f32)
Run the backward pass through the subgraph terminating at this node. The weight parameter scales the gradients.
pub fn clip(&self, min: f32, max: f32)
[src]
pub fn clip(&self, min: f32, max: f32)
Clip the value. Useful for clipping losses.
pub fn square(&self) -> Variable<SquareNode<T>>
[src]
pub fn square(&self) -> Variable<SquareNode<T>>
Square this variable.
pub fn scalar_sum(&self) -> Variable<SumNode<T>>
[src]
pub fn scalar_sum(&self) -> Variable<SumNode<T>>
Sum this variable.
pub fn ln(&self) -> Variable<LogNode<T>>
[src]
pub fn ln(&self) -> Variable<LogNode<T>>
Take the natural logarithm of this variable.
pub fn tanh(&self) -> Variable<TanhNode<T>>
[src]
pub fn tanh(&self) -> Variable<TanhNode<T>>
Take the tanh of this variable.
pub fn t(&self) -> Variable<TransposeNode<T>>
[src]
pub fn t(&self) -> Variable<TransposeNode<T>>
Transpose this variable.
pub fn exp(&self) -> Variable<ExpNode<T>>
[src]
pub fn exp(&self) -> Variable<ExpNode<T>>
Exponentiate this variable.
pub fn softmax(&self) -> Variable<SoftmaxNode<T>>
[src]
pub fn softmax(&self) -> Variable<SoftmaxNode<T>>
Compute the softmax of this variable.
pub fn log_softmax(&self) -> Variable<LogSoftmaxNode<T>>
[src]
pub fn log_softmax(&self) -> Variable<LogSoftmaxNode<T>>
Compute the log-softmax of this variable.
pub fn sigmoid(&self) -> Variable<SigmoidNode<T>>
[src]
pub fn sigmoid(&self) -> Variable<SigmoidNode<T>>
Compute the sigmoid of this variable.
pub fn relu(&self) -> Variable<ReluNode<T>>
[src]
pub fn relu(&self) -> Variable<ReluNode<T>>
Compute the ReLU of this variable.
pub fn vector_dot<S>(
&self,
other: &Variable<S>
) -> Variable<VectorDotNode<T, S>> where
S: Node<Value = Arr, InputGradient = Arr>,
[src]
pub fn vector_dot<S>(
&self,
other: &Variable<S>
) -> Variable<VectorDotNode<T, S>> where
S: Node<Value = Arr, InputGradient = Arr>,
Compute the row-wise vector dot product of LHS and RHS.
pub fn dot<S>(&self, other: &Variable<S>) -> Variable<DotNode<T, S>> where
S: Node<Value = Arr, InputGradient = Arr>,
[src]
pub fn dot<S>(&self, other: &Variable<S>) -> Variable<DotNode<T, S>> where
S: Node<Value = Arr, InputGradient = Arr>,
Compute the matrix multiplication of LHS and RHS.
pub fn stack<S>(
&self,
other: &Variable<S>,
axis: Axis
) -> Variable<ConcatenateNode<T, S>> where
S: Node<Value = Arr, InputGradient = Arr>,
[src]
pub fn stack<S>(
&self,
other: &Variable<S>,
axis: Axis
) -> Variable<ConcatenateNode<T, S>> where
S: Node<Value = Arr, InputGradient = Arr>,
Stack/concatenate LHS and RHS, either row-wise (ndarray::Axis(0)
) or
column-wise (ndarray::Axis(1)
).
pub fn slice(
&self,
slice: &SliceInfo<[SliceOrIndex; 2], Ix2>
) -> Variable<SliceNode<T>>
[src]
pub fn slice(
&self,
slice: &SliceInfo<[SliceOrIndex; 2], Ix2>
) -> Variable<SliceNode<T>>
Slice the node according to the ndarray
slice syntax.
impl Variable<ParameterNode>
[src]
impl Variable<ParameterNode>
pub fn gradient(&self) -> Arr
[src]
pub fn gradient(&self) -> Arr
Return the (dense) gradient value of this node.
pub fn index(
&self,
index: &Variable<IndexInputNode>
) -> Variable<IndexNode<ParameterNode>>
[src]
pub fn index(
&self,
index: &Variable<IndexInputNode>
) -> Variable<IndexNode<ParameterNode>>
Row-wise indexing of this parameter node. Primiarily used to implement embedding layers.
impl<T> Variable<SparseCategoricalCrossentropyNode<T>> where
T: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<T> Variable<SparseCategoricalCrossentropyNode<T>> where
T: Node<Value = Arr, InputGradient = Arr>,
pub fn predictions(&self) -> Bor<Arr>
[src]
pub fn predictions(&self) -> Bor<Arr>
Return the log-softmax predictions from a sparse categorical cross-entropy node.
Calling .value()
on the node returns the value of the loss;
this function allows getting the predictins with low overhead.
Trait Implementations
impl<T: Debug> Debug for Variable<T> where
T: Node,
[src]
impl<T: Debug> Debug for Variable<T> where
T: Node,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: Node> Clone for Variable<T>
[src]
impl<T: Node> Clone for Variable<T>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'value> DataInput<&'value Arr> for Variable<ParameterNode>
[src]
impl<'value> DataInput<&'value Arr> for Variable<ParameterNode>
impl<'value> DataInput<&'value Arr> for Variable<InputNode>
[src]
impl<'value> DataInput<&'value Arr> for Variable<InputNode>
impl DataInput<f32> for Variable<InputNode>
[src]
impl DataInput<f32> for Variable<InputNode>
impl<'value> DataInput<&'value [usize]> for Variable<IndexInputNode>
[src]
impl<'value> DataInput<&'value [usize]> for Variable<IndexInputNode>
impl DataInput<usize> for Variable<IndexInputNode>
[src]
impl DataInput<usize> for Variable<IndexInputNode>
impl<LHS, RHS> Add<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS, RHS> Add<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
type Output = Variable<AddNode<LHS, RHS>>
The resulting type after applying the +
operator.
fn add(self, other: Variable<RHS>) -> Self::Output
[src]
fn add(self, other: Variable<RHS>) -> Self::Output
Performs the +
operation.
impl<LHS> Add<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS> Add<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the LHS.
type Output = Variable<AddNode<LHS, InputNode>>
The resulting type after applying the +
operator.
fn add(self, other: f32) -> Self::Output
[src]
fn add(self, other: f32) -> Self::Output
Performs the +
operation.
impl<RHS> Add<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<RHS> Add<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the RHS.
type Output = Variable<AddNode<InputNode, RHS>>
The resulting type after applying the +
operator.
fn add(self, other: Variable<RHS>) -> Self::Output
[src]
fn add(self, other: Variable<RHS>) -> Self::Output
Performs the +
operation.
impl<LHS, RHS> Sub<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS, RHS> Sub<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
type Output = Variable<SubNode<LHS, RHS>>
The resulting type after applying the -
operator.
fn sub(self, other: Variable<RHS>) -> Self::Output
[src]
fn sub(self, other: Variable<RHS>) -> Self::Output
Performs the -
operation.
impl<LHS> Sub<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS> Sub<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the LHS.
type Output = Variable<SubNode<LHS, InputNode>>
The resulting type after applying the -
operator.
fn sub(self, other: f32) -> Self::Output
[src]
fn sub(self, other: f32) -> Self::Output
Performs the -
operation.
impl<RHS> Sub<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<RHS> Sub<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the RHS.
type Output = Variable<SubNode<InputNode, RHS>>
The resulting type after applying the -
operator.
fn sub(self, other: Variable<RHS>) -> Self::Output
[src]
fn sub(self, other: Variable<RHS>) -> Self::Output
Performs the -
operation.
impl<LHS, RHS> Mul<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS, RHS> Mul<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
type Output = Variable<MulNode<LHS, RHS>>
The resulting type after applying the *
operator.
fn mul(self, other: Variable<RHS>) -> Self::Output
[src]
fn mul(self, other: Variable<RHS>) -> Self::Output
Performs the *
operation.
impl<LHS> Mul<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS> Mul<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the LHS.
type Output = Variable<MulNode<LHS, InputNode>>
The resulting type after applying the *
operator.
fn mul(self, other: f32) -> Self::Output
[src]
fn mul(self, other: f32) -> Self::Output
Performs the *
operation.
impl<RHS> Mul<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<RHS> Mul<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the RHS.
type Output = Variable<MulNode<InputNode, RHS>>
The resulting type after applying the *
operator.
fn mul(self, other: Variable<RHS>) -> Self::Output
[src]
fn mul(self, other: Variable<RHS>) -> Self::Output
Performs the *
operation.
impl<LHS, RHS> Div<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS, RHS> Div<Variable<RHS>> for Variable<LHS> where
RHS: Node<Value = Arr, InputGradient = Arr>,
LHS: Node<Value = Arr, InputGradient = Arr>,
type Output = Variable<DivNode<LHS, RHS>>
The resulting type after applying the /
operator.
fn div(self, other: Variable<RHS>) -> Self::Output
[src]
fn div(self, other: Variable<RHS>) -> Self::Output
Performs the /
operation.
impl<LHS> Div<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<LHS> Div<f32> for Variable<LHS> where
LHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the LHS.
type Output = Variable<DivNode<LHS, InputNode>>
The resulting type after applying the /
operator.
fn div(self, other: f32) -> Self::Output
[src]
fn div(self, other: f32) -> Self::Output
Performs the /
operation.
impl<RHS> Div<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<RHS> Div<Variable<RHS>> for f32 where
RHS: Node<Value = Arr, InputGradient = Arr>,
The constant will be broadcast to have the same shape as the RHS.
type Output = Variable<DivNode<InputNode, RHS>>
The resulting type after applying the /
operator.
fn div(self, other: Variable<RHS>) -> Self::Output
[src]
fn div(self, other: Variable<RHS>) -> Self::Output
Performs the /
operation.
impl<T> Neg for Variable<T> where
T: Node<Value = Arr, InputGradient = Arr>,
[src]
impl<T> Neg for Variable<T> where
T: Node<Value = Arr, InputGradient = Arr>,