NeuralNet

Neural-network abstraction.

Members

Functions

add
NeuralNet add(string name_, NeuralLayer layer, Optimizer opt = null)

Name and add a layer to the net, without wiring it.

add
NeuralNet add(NeuralLayer layer, Optimizer opt = null)

Add a layer to the net, without wiring it.

add_root
NeuralNet add_root(string name_, InputLayer layer)

Name and add a root to the net.

add_root
NeuralNet add_root(InputLayer root_)

Add a root to the net.

clear_opt
void clear_opt()

Remove any optimizer defined on layers of the net.

dup
NeuralNet dup(bool topology_only = false)

Return a copy of the net.

initialize
void initialize(double rand_scale)

Initialize at random all the parameters of the net.

learn
void learn(D data, S delegate(R net_out, ref T ex, ref V[] grad) grad_f, O opt, bool verbose = false, uint num_cores = 1)

Train neural network on some data, using specified gradient callback and optimizer.

learn
void learn(D data, string loss, O opt, bool verbose = false, uint num_cores = 1, bool monitor_loss = true)

Train neural network on a dataset, using a predefined loss.

learn
void learn(D data, float delegate(R net_out, ref T ex, ref V[] grad) grad_f, bool verbose = false, uint num_cores = 1)

Train neural network on some data, using a gradient callback.

learn
void learn(D data, string loss, bool verbose = false, uint num_cores = 1)

Train neural network on some data, using a predefined loss.

predict
float[] predict(T v)

Compute the prediction of the net for $(PARAM v). Runs forward-propagation and outputs the predicted vector.

predict
float[] predict(T args)

Compute the prediction of the net when passing the arguments to the root(s) of the net.

reset
void reset()

Reset any internal state variables of the net.

serialize
void serialize(string path)

Dump the neural net (topology and weight values) to the specified path.

share_params
void share_params(NeuralNet net)

Discard local weights and use those of the target net instead. However, the net keeps its own internal state. Useful for hogwild SGD implementation.

stack
NeuralNet stack(NeuralLayer layer, Optimizer opt = null)

Stack a layer on top of the former leaf of the net.

stack
NeuralNet stack(string name_, NeuralLayer layer, Optimizer opt = null)

Stack a layer on top of the former leaf of the net.

wire
void wire(string parent, string child, bool with_alloc = true)

Create a directed edge between parent and child nodes.

wire
void wire(NeuralLayer parent, NeuralLayer child, bool with_alloc = true)

Create a directed edge between parent and child nodes.

Properties

num_params
ulong num_params [@property getter]

Return the total number of learnable parameters in the net.

out_layer
NeuralLayer out_layer [@property getter]

reference to the leaf of the net

output
float[] output [@property getter]

Return a reference to the dense output vector of the leaf of the net.

Static functions

deserialize
NeuralNet deserialize(string path)

Deserialize the neural net from the specified path.

Variables

edges
string[][string] edges;

edges of the graph: src -> [dst1, ..., dstk]

layers
NeuralLayer[] layers;

all nodes of the computational graph

layers_map
NeuralLayer[string] layers_map;

map: name --> layer

leaves
NeuralLayer[] leaves;

array of all the leaves

roots
InputLayer[] roots;

array of all the roots

Examples

1 auto nn = NeuralNet()
2     .stack(DenseData(400))
3     .stack(Linear(10));
4 // nn is a network working on 400-dimensions dense vectors and predicting
5 // a 10-dimensions vector

Meta