class Num::NN::Network(T)
- Num::NN::Network(T)
- Reference
- Object
Overview
A neural network can be defined as a biologically inspired computational model that consists of a network architecture composed of artificial neurons. This structure contains a set of parameters, which can be adjusted to perform specific tasks.
This class is a loose wrapper that primarily provides syntactic sugar around moving data through a network -> forward, and propogating loss <- backwards
Defined in:
nn/network.crConstructors
-
.new(context : Num::Grad::Context(T), **options, &)
Convenience method to allow for creation of a Network with as little code as possible.
Instance Method Summary
-
#forward(train : Num::Grad::Variable(T)) : Num::Grad::Variable(T)
Propogates an input through a network, returning the final prediction from the network
- #layers : Num::NN::NetworkInfo(T)
-
#loss(output : Num::Grad::Variable(T), target : T)
Uses the Network's loss function to calculate the loss based on the final output from the Network, as well as the target output
-
#optimizer
Return the Network's optimizer to allow updating the weights and biases of the network
Constructor Detail
Convenience method to allow for creation of a Network with as little code as possible. Taps an instance of a LayerArray in order to allow layers to be added to the network in a block
Examples
Network(Float32).new do
layer(2, 3, :tanh)
layer(3, 1, :sigmoid)
end
Instance Method Detail
Propogates an input through a network, returning the final prediction from the network
Arguments
- train :
Num::Grad::Variable(T)
- Training input data
Examples
a = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]].to_tensor
v = ctx.variable(a)
net.forward(v)
Uses the Network's loss function to calculate the loss based on the final output from the Network, as well as the target output
Arguments
- output :
Num::Grad::Variable(T)
- Prediction by the network - target :
T
-Tensor
containing ground truth values
Examples
epochs.times do |epoch|
y_pred = net.forward(x)
loss = net.loss(y_pred, y_actual)
end
Return the Network's optimizer to allow updating the weights and biases of the network
Examples
epochs.times do |epoch|
y_pred = net.forward(x)
loss = net.loss(y_pred, y_actual)
net.optimizer.update
end