Base Layers

class npdl.layers.Layer[source][source]

The Layer class represents a single layer of a neural network. It should be subclassed when implementing new types of layers.

Because each layer can keep track of the layer(s) feeding into it, a network’s output Layer instance can double as a handle to the full network.

backward(pre_grad, *args, **kwargs)[source][source]

calculate the input gradient

connect_to(prev_layer)[source][source]

Propagates the given input through this layer (and only this layer).

Parameters:
prev_layer : previous layer

The previous layer to propagate through this layer.

forward(input, *args, **kwargs)[source][source]

Calculate layer output for given input (forward propagation).

classmethod from_json(config)[source][source]

From configuration

grads[source]

Get layer parameter gradients as calculated from backward().

param_grads[source]

Layer parameters and corresponding gradients.

params[source]

Layer parameters.

Returns a list of numpy.array variables or expressions that parameterize the layer.

Returns:
list of numpy.array variables or expressions

A list of variables that parameterize the layer

Notes

For layers without any parameters, this will return an empty list.

to_json()[source][source]

To configuration