Engine¶
API Documentation for the automatic differentiation engine of nanograd
Automatic differentiation engine
- class nanograd_bgriebel._core.engine.Value¶
A wrapped float which can be used in computing gradients.
- Parameters:
data (float) – Data to wrap in the Value.
- backwards(self: nanograd_bgriebel._core.engine.Value) None¶
Compute the gradients of a Value.
Uses backpropagation to calculate the dertivative of this Value with respect to any Vaues which were used to generate it.
Examples
>>> # Create some Values >>> x = Value(3) >>> y = Value(4) >>> # Perform a computation with the Values >>> z = x*y >>> # Calculate the gradient of z wrt x and y >>> z.backwards() >>> print(x.grad) 4 >>> print(y.grad) 3
- property data¶
Data wrapped by the Value.
- Type:
float
- property grad¶
The gradient associated with the Value
- Type:
float
- relu(self: nanograd_bgriebel._core.engine.Value) nanograd_bgriebel._core.engine.Value¶
Calculate the output of a ReLU on the Value.
- Returns:
The output of the ReLU operation wrapped into a Value.
- Return type:
- zero_grad(self: nanograd_bgriebel._core.engine.Value) None¶
Set the value of grad to 0.0