Struct drug::Graph

source ·
pub struct Graph {
    pub optimizer: Optimizer,
    pub named_idxs: BTreeMap<String, Idx>,
    /* private fields */
}
Expand description

A differentiable computation graph. Use this struct to hold your differentiable program which is a directed acyclic graph of Nodes, their associated values and losses (gradients). The graph computes values moving forward in insertion order (see forward method) and propagates losses backwards in reverse insertion order (see backward method). The default graph comes with an xavier initializer and a vanilla stochastic gradient descent optimizer.

Fields§

§optimizer: Optimizer§named_idxs: BTreeMap<String, Idx>

Implementations§

Consider using Graph::default() if you don’t want to choose your own optimizer and initializer.

Inserts the node into the graph and returns the index

Registers a parameter of the given shape and initializes the value using the graph’s initializer.

Registers an input node which advances the iterator it each forward pass.

Registers an operation and its inputs

Registers a constant, sets its value to c, then returns the idx

Computes values for each node in insertion order. Parameters are unaffected. Inputs will set their value to the next output of their iterator, Operations will compute a new value based on the values of its inputs.

Propagates gradients in reverse insertion order. Parameters will apply gradients with the graph’s optimizer. Inputs are unaffected Operations will compute gradient given values from their inputs and gradients from its outputs

Updates value and resets losses for node with Idx i.

Back propagates losses for node with Idx i.

Remove the node at idx as well as its associated value and loss.

This op removes every node from the graph that is not a parameter. This is useful for dynamic graphs and recurrent neural networks when you want to rebuild everything each forward and backward pass of the network.

Replace an Input node’s iterator or converts Constant nodes into Input with this iterator. Note that Input node iterators are not saved when serialized with serde.

Registers a convolution operation node and returns the index

Registers a pooling operation takes a Batch * Height * Width * Channels image and reduces it to a Batch * Channels vector.

Registers a Relu operation which takes the elementwise maximum of the input array and 0.

Registers a new sigmoid activation operation, an elementwise application of $\frac{ 1 }{1 - e^{-x}}$.

Registers a Tanh operation.

Registers a matrix multiplication of vectors v by matrix mat.

Registers an embedding later that converts A0 to vector representation

Trait Implementations§

Formats the value using the given formatter. Read more

xavier initializer and normal gradient descent

Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.