Package mdp :: Class OnlineNode
[hide private]
[frames] | no frames]

NodeMetaclass OnlineNode

Known Subclasses:

An online Node (OnlineNode) is the basic building block of
an online MDP application.

It represents a data processing element, for example a learning
algorithm, a data filter, or a visualization step.
Each node has a training phase (optional), during which the
internal structures are updated incrementally (or in batches)
from training data (e.g. the weights of a neural network are adapted).

Each node can also be executed at any point in time, where new
data can be processed forwards (or backwards by applying the inverse
of the transformation computed by the node if defined).

Unlike a Node, an OnlineNode's execute (or inverse) call __does not__ end the
training phase of the node. The training phase can only be stopped through
an explicit 'stop_training' call. Once stopped, an OnlineNode becomes
functionally equivalent to a trained Node.

OnlineNode also supports multiple training phases. However, all
the training_phases are active for each data point. See _train_seq
documentation for more information.

The training type of an OnlineNode can be set either to 'incremental'
or 'batch'. When set to 'incremental', the input data array is passed for
training sample by sample, while for 'batch' the entire data array is passed.

An `OnlineNode` inherits all the Node's utility methods, for example
`copy` and `save`, that returns an exact copy of a node and saves it
in a file, respectively. Additional methods may be present, depending
on the algorithm.

OnlineNodes also support using a pre-seeded random number generator
through a 'numx_rng' argument. This can be useful to replicate
results.

`OnlineNode` subclasses should take care of overwriting (if necessary)
the functions `_train`, `_stop_training`, `_execute`, 'is_trainable',
`is_invertible`, `_inverse`, `_get_supported_dtypes` and '_get_supported_training_types'.
If you need to overwrite the getters and setters of the
node's properties refer to the docstring of `get_input_dim`/`set_input_dim`,
`get_output_dim`/`set_output_dim`, `get_dtype`/`set_dtype`, 'get_numx_rng'/'set_numx_rng'.

Instance Methods [hide private]
 
__add__(self, other)
 
__init__(self, input_dim=None, output_dim=None, dtype=None, numx_rng=None)
If the input dimension and the output dimension are unspecified, they will be set when the `train` or `execute` method is called for the first time.
 
__repr__(self)
 
_check_input(self, x)
 
_check_params(self, x)
 
_get_supported_training_types(self)
Return the list of training types supported by this node.
 
_get_train_seq(self)
 
_pre_execution_checks(self, x)
This method contains all pre-execution checks.
 
_pre_inversion_checks(self, y)
This method contains all pre-inversion checks.
 
_set_numx_rng(self, rng)
 
get_current_train_iteration(self)
Return the index of the current training iteration.
 
get_numx_rng(self)
Return input dimensions.
 
set_numx_rng(self, rng)
Set numx random number generator.
 
set_training_type(self, training_type)
Sets the training type...
 
stop_training(self, *args, **kwargs)
Stop the training phase.
 
train(self, x, *args, **kwargs)
Update the internal structures according to the input data `x`.

Inherited from unreachable.newobject: __long__, __native__, __nonzero__, __unicode__, next

    Inherited from Node
 
__call__(self, x, *args, **kwargs)
Calling an instance of `Node` is equivalent to calling its `execute` method.
 
__str__(self)
 
_check_output(self, y)
 
_check_train_args(self, x, *args, **kwargs)
 
_execute(self, x)
 
_get_supported_dtypes(self)
Return the list of dtypes supported by this node.
 
_if_training_stop_training(self)
 
_inverse(self, x)
 
_refcast(self, x)
Helper function to cast arrays to the internal dtype.
 
_set_dtype(self, t)
 
_set_input_dim(self, n)
 
_set_output_dim(self, n)
 
_stop_training(self, *args, **kwargs)
 
_train(self, x)
 
copy(self, protocol=None)
Return a deep copy of the node.
 
execute(self, x, *args, **kwargs)
Process the data contained in `x`.
 
get_current_train_phase(self)
Return the index of the current training phase.
 
get_dtype(self)
Return dtype.
 
get_input_dim(self)
Return input dimensions.
 
get_output_dim(self)
Return output dimensions.
 
get_remaining_train_phase(self)
Return the number of training phases still to accomplish.
 
get_supported_dtypes(self)
Return dtypes supported by the node as a list of :numpy:`dtype` objects.
 
has_multiple_training_phases(self)
Return True if the node has multiple training phases.
 
inverse(self, y, *args, **kwargs)
Invert `y`.
 
is_training(self)
Return True if the node is in the training phase, False otherwise.
 
save(self, filename, protocol=-1)
Save a pickled serialization of the node to `filename`.
 
set_dtype(self, t)
Set internal structures' dtype.
 
set_input_dim(self, n)
Set input dimensions.
 
set_output_dim(self, n)
Set output dimensions.
Static Methods [hide private]
    Inherited from Node
 
is_invertible()
Return True if the node can be inverted, False otherwise.
 
is_trainable()
Return True if the node can be trained, False otherwise.
Properties [hide private]
  _train_seq
List of tuples::
  numx_rng
Numpy seeded random number generator
  training_type
Training type (Read only)
    Inherited from Node
  dtype
dtype
  input_dim
Input dimensions
  output_dim
Output dimensions
  supported_dtypes
Supported dtypes
Method Details [hide private]

__add__(self, other)
(Addition operator)

 
Overrides: Node.__add__

__init__(self, input_dim=None, output_dim=None, dtype=None, numx_rng=None)
(Constructor)

 
If the input dimension and the output dimension are
unspecified, they will be set when the `train` or `execute`
method is called for the first time.
If dtype is unspecified, it will be inherited from the data
it receives at the first call of `train` or `execute`.
Every subclass must take care of up- or down-casting the internal
structures to match this argument (use `_refcast` private
method when possible).
If numx_rng is unspecified, it will be set to a random number generator
with a random seed.

Overrides: Node.__init__

__repr__(self)
(Representation operator)

 
Overrides: Node.__repr__

_check_input(self, x)

 
Overrides: Node._check_input

_check_params(self, x)

 

_get_supported_training_types(self)

 
Return the list of training types supported by this node.
        

_get_train_seq(self)

 
Overrides: Node._get_train_seq

_pre_execution_checks(self, x)

 
This method contains all pre-execution checks.
It can be used when a subclass defines multiple execution methods.

Overrides: Node._pre_execution_checks

_pre_inversion_checks(self, y)

 
This method contains all pre-inversion checks.

It can be used when a subclass defines multiple inversion methods.

Overrides: Node._pre_inversion_checks

_set_numx_rng(self, rng)

 

get_current_train_iteration(self)

 
Return the index of the current training iteration.

get_numx_rng(self)

 
Return input dimensions.

set_numx_rng(self, rng)

 
Set numx random number generator.
Note that subclasses should overwrite `self._set_numx_rng` when needed.

set_training_type(self, training_type)

 
Sets the training type
        

stop_training(self, *args, **kwargs)

 
Stop the training phase.

By default, subclasses should overwrite `_stop_training` to implement
this functionality. The docstring of the `_stop_training` method
overwrites this docstring.

Overrides: Node.stop_training

train(self, x, *args, **kwargs)

 
Update the internal structures according to the input data `x`.

`x` is a matrix having different variables on different columns
and observations on the rows.

By default, subclasses should overwrite `_train` to implement their
training phase. The docstring of the `_train` method overwrites this
docstring.

Note: a subclass supporting multiple training phases should implement
the *same* signature for all the training phases and document the
meaning of the arguments in the `_train` method doc-string. Having
consistent signatures is a requirement to use the node in a flow.

Overrides: Node.train

Property Details [hide private]

_train_seq

List of tuples::

  [(training-phase1, stop-training-phase1, execution-phase1),
   (training-phase2, stop_training-phase2, execution-phase2),
   ...]

By default::

  _train_seq = [(self._train, self._stop_training, Identity-function)]

numx_rng

Numpy seeded random number generator

Get Method:
get_numx_rng(self) - Return input dimensions.
Set Method:
set_numx_rng(self, rng) - Set numx random number generator.

training_type

Training type (Read only)