Package crino :: Module module :: Class Module
[hide private]
[frames] | no frames]

Class Module

source code

Known Subclasses:

A Module is a part of a neural network architecture, that may have parameters. Provided an input vector of fixed size, a module is able to compute an output vector, which size is specified at construction. According to their characteristics, several modules can be combined to build a new module.

If a criterion is given to a module, it is able to compute the partial gradients of its parameters, in order to perform a gradient descent.


Attention: This is an abstract class, it must be derived to be used.

Instance Methods [hide private]
 
__init__(self, nOutputs, nInputs=None)
Constructs a new Module object.
source code
 
linkModule(self, previous)
Links the outputs of the previous module to the inputs of the current module.
source code
 
linkInputs(self, vector, nInputs)
Sets the symbolic vector as the inputs of the current module.
source code
function
trainFunction(self, batch_size=1, lr=0.1, downcast=None, shared_x_train=None, shared_y_train=None)
Constructs and compiles a Theano function in order to train the module.
source code
function
criterionFunction(self, downcast=None, shared_x_data=None, shared_y_data=None)
Constructs and compiles a Theano function in order to compute the criterion on a given set.
source code
function
forwardFunction(self, downcast=None, shared_x_data=None)
Constructs and compiles a Theano function in order to compute the forward on a given set.
source code
function
forward(self, x_test)
Performs the forward step on the given test example.
source code
 
holdFunction(self) source code
 
restoreFunction(self) source code
 
prepare(self)
Prepares the module before learning.
source code
 
prepareGeometry(self)
Sets correctly the geometry (nInputs and nOutputs) of the potential submodules.
source code
 
prepareParams(self)
Initializes the params of the module and its potential submodules.
source code
 
prepareBackup(self)
Initializes the backupParams of the module and its potential submodules.
source code
 
prepareOutput(self)
Computes the symbolic outputs of the module in respect to its inputs.
source code
 
save(self, filename)
Saves this Module to a file.
source code
Instance Variables [hide private]
TensorVariable inputs
The symbolic inputs vector of the module, denoted x
TensorVariable outputs
The symbolic outputs vector of the module, denoted
int nInputs
The inputs size
int nOutputs
The outputs size
list params
The list of parameters
list backupParams
The list of backup parameters
bool prepared
Indicates whether the module have already been prepared
Method Details [hide private]

__init__(self, nOutputs, nInputs=None)
(Constructor)

source code 
Constructs a new Module object.
Parameters:
  • nOutputs (int) - The outputs size.
  • nInputs (int) - The inputs size.

linkModule(self, previous)

source code 
Links the outputs of the previous module to the inputs of the current module.
Parameters:
  • previous (Module) - The previous module to be linked with the current module.

linkInputs(self, vector, nInputs)

source code 
Sets the symbolic vector as the inputs of the current module.
Parameters:
  • vector (TensorVariable) - The symbolic vector that will serve as inputs.
  • nInputs (int) - The size of this inputs vector.

Attention: You can't change the module inputs size once it has been prepare()'d

trainFunction(self, batch_size=1, lr=0.1, downcast=None, shared_x_train=None, shared_y_train=None)

source code 
Constructs and compiles a Theano function in order to train the module.
Parameters:
  • batch_size (int) -
    The size of the batches to use for gradient descent :
    • 1 for stochastic gradient descent;
    • n ∈ ]1..Ntrain[ for mini-batch gradient descent (Ntrain must be a multiple of n);
    • Ntrain for batch gradient descent.

    (Ntrain is the total number of training examples)

  • lr (float) - The learning rate.
  • downcast (bool) - If true, allows the inputs data to be downcasted (e.g. from double to single precision floats for GPU use).
Returns: function
a Theano-function that performs one step of gradient descent

criterionFunction(self, downcast=None, shared_x_data=None, shared_y_data=None)

source code 
Constructs and compiles a Theano function in order to compute the criterion on a given set.
Parameters:
  • downcast (bool) - If true, allows the inputs data to be downcasted (e.g. from double to single precision floats for GPU use).
Returns: function
a Theano-function that performs one step of gradient descent

forwardFunction(self, downcast=None, shared_x_data=None)

source code 
Constructs and compiles a Theano function in order to compute the forward on a given set.
Parameters:
  • downcast (bool) - If true, allows the inputs data to be downcasted (e.g. from double to single precision floats for GPU use).
Returns: function
a Theano-function that performs one step of gradient descent

forward(self, x_test)

source code 
Performs the forward step on the given test example.
Parameters:
  • x_test (ndarray) - The test example on which the neural network will compute its outputs.
Returns: function
a Theano function that performs one step of gradient descent

prepare(self)

source code 
Prepares the module before learning.

Attention: The inputs must be linked before preparation.

prepareGeometry(self)

source code 
Sets correctly the geometry (nInputs and nOutputs) of the potential submodules.

Attention: It must be implemented in derived classes.

prepareParams(self)

source code 
Initializes the params of the module and its potential submodules.

Attention: It must be implemented in derived classes.

prepareOutput(self)

source code 
Computes the symbolic outputs of the module in respect to its inputs.

Attention: It must be implemented in derived classes.

save(self, filename)

source code 
Saves this Module to a file.
Parameters:
  • filename (str) - The path where the module is to be saved.