synapse-0.1.0.0: Synapse is a machine learning library written in pure Haskell.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Synapse.NN.Layers.Layer

Description

This module provides nessesary abstraction over layers of neural networks.

AbstractLayer typeclass defines interface of all layers of neural network model. Its implementation is probably the most low-leveled abstraction of the Synapse library. Notes on how to correctly implement that typeclass are in the docs for it.

Layer is the existential datatype that wraps any AbstractLayer instance. That is the building block of any neural network.

Synopsis

AbstractLayer typeclass

class AbstractLayer l where Source #

AbstractLayer typeclass defines basic interface of all layers of neural network model.

Every layer should be able to pass SymbolMat through itself to produce new SymbolMat (make prediction based on its parameters) using symbolicForward function, which allows for gradients to be calculated after predictions, which in turn makes training possible.

nParameters, getParameters and updateParameters functions allow training of parameters of the layer. Their implementations should match - that is getParameters function should return list of length nParameters and updateParameters should expect a list of the same length with the matrices in the same order as were they in getParameters.

Synapse manages gradients and parameters for layers with erased type information using prefix system. SymbolIdentifier is a prefix for name of symbolic parameters that are used in calculation. Every used parameter should have unique name to be recognised by the autograd - it must start with given prefix and end with the numerical index of said parameter. For example 3rd layer with 2 parameters (weights and bias) should name its weights symbol "ml3w1" and name its bias symbol "ml3w2" ("ml3w" prefix will be supplied).

Important: this typeclass correct implementation is very important (as it is the 'heart' of Synapse library) for work of the neural network and training, read the docs thoroughly to ensure that all the invariants are met.

Methods

inputSize :: l a -> Maybe Int Source #

Returns the size of the input that is supported for forward and symbolicForward functions. Nothing means size independence (activation functions are the example).

outputSize :: l a -> Maybe Int Source #

Returns the size of the output that is supported for forward and symbolicForward functions. Nothing means size independence (activation functions are the example).

nParameters :: l a -> Int Source #

Returns the number of parameters of this layer.

getParameters :: SymbolIdentifier -> l a -> [SymbolMat a] Source #

Returns a list of all parameters (those must be of the exact same order as they are named by the layer (check symbolicForward docs)).

updateParameters :: l a -> [Mat a] -> l a Source #

Updates parameters based on supplied list (length of that list, the order and the form of parameters is EXACTLY the same as those from getParameters)

symbolicForward :: (Symbolic a, Floating a, Ord a) => SymbolIdentifier -> SymbolMat a -> l a -> (SymbolMat a, SymbolMat a) Source #

Passes symbolic matrix through to produce new symbolic matrix, while retaining gradients graph. Second matrix is a result of application of regularizer on a layer.

Instances

Instances details
AbstractLayer Activation Source # 
Instance details

Defined in Synapse.NN.Layers.Activations

AbstractLayer Dense Source # 
Instance details

Defined in Synapse.NN.Layers.Dense

AbstractLayer Layer Source # 
Instance details

Defined in Synapse.NN.Layers.Layer

AbstractLayer SequentialModel Source # 
Instance details

Defined in Synapse.NN.Models

forward :: (AbstractLayer l, Symbolic a, Floating a, Ord a) => Mat a -> l a -> Mat a Source #

Passes matrix through to produce new matrix.

Layer existential datatype

data Layer a Source #

Layer existential datatype wraps anything that implements AbstractLayer.

Constructors

forall l.AbstractLayer l => Layer (l a) 

Instances

Instances details
AbstractLayer Layer Source # 
Instance details

Defined in Synapse.NN.Layers.Layer

type DType (Layer a) Source # 
Instance details

Defined in Synapse.NN.Layers.Layer

type DType (Layer a) = a

LayerConfiguration type alias

type LayerConfiguration l Source #

Arguments

 = Int

Output size of previous layer.

-> l

Resulting layer.

LayerConfiguration type alias represents functions that are able to build layers.