NN

Documentation for the nerual network API of nanograd-bgriebel

Neural Network Classes

class nanograd_bgriebel._core.nn.Layer

Bases: pybind11_object

A Layer of Neurons in a neural network.

Parameters:
  • nin (int) – Number of inputs to the Layer.

  • nouts (int) – Number of outputs from the Layer.

  • nonlinear (bool) – Whether the output of the Layer should be nonlinear (fed through a ReLU).

get_parameters(self: nanograd_bgriebel._core.nn.Layer) list[nanograd_bgriebel._core.engine.Value]

Get a list of all parameters associated with the Layer.

Returns:

The parameters of the Layer, specifically

the weights and biases of all associated Neurons.

Return type:

list[Value]

zero_grad(self: nanograd_bgriebel._core.nn.Layer) None

Set the gradient of all Layer parameters to 0.

class nanograd_bgriebel._core.nn.Module

Bases: pybind11_object

Base class for neural network classes.

get_parameters(self: nanograd_bgriebel._core.nn.Module) list[nanograd_bgriebel._core.engine.Value]

Get a list of all parameters associated with Module.

zero_grad(self: nanograd_bgriebel._core.nn.Module) None

Zero the gradients of all parameters associated with Module.

class nanograd_bgriebel._core.nn.MultiLayerPerceptron

Bases: pybind11_object

A Multi-Layer Perceptron.

Parameters:
  • nin (int) – Number of inputs to the MultiLayerPerceptron.

  • nouts (list[int]) – Sizes of the Layers in the MultiLayerPerceptron, the last of which is the number of outputs form the MultiLayerPerceptron.

get_parameters(self: nanograd_bgriebel._core.nn.MultiLayerPerceptron) list[nanograd_bgriebel._core.engine.Value]

Get a list of all parameters associated with the MultiLayerPerceptron.

Returns:

The parameters of the MultiLayerPerceptron, specifically

the weights and biases of all associated Neurons in each Layer.

Return type:

list[Value]

zero_grad(self: nanograd_bgriebel._core.nn.MultiLayerPerceptron) None

Set the gradient of all MultiLayerPerceptron parameters to 0.

class nanograd_bgriebel._core.nn.Neuron

Bases: pybind11_object

A single neuron, with randomly initialized weights and bias, as well as an activation function.

Parameters:
  • nin (int) – Number of inputs to the Neuron.

  • nonlinear (bool) – Whether the activation function should be non-linear (fed through a ReLU).

get_parameters(self: nanograd_bgriebel._core.nn.Neuron) list[nanograd_bgriebel._core.engine.Value]

Get a list of all parameters associated with the Neuron.

Returns:

The parameters of the Neuron, specifically the weights and bias.

Return type:

list[Value]

zero_grad(self: nanograd_bgriebel._core.nn.Neuron) None

Set the gradient of all Neuron parameters to 0.