Package mdp :: Package nodes :: Class GeneralExpansionNode
[hide private]
[frames] | no frames]

Class GeneralExpansionNode


Expands the input samples by applying to them one or more functions provided.

The functions to be applied are specified by a list [f_0, ..., f_k], where f_i, for 0 <= i <= k, denotes a particular function. The input data given to these functions is a two-dimensional array and the output is another two-dimensional array. The dimensionality of the output should depend only on the dimensionality of the input. Given a two-dimensional input array x, the output of the node is then [f_0(x), ..., f_k(x)], that is, the concatenation of each one of the computed arrays f_i(x).

This node has been designed to facilitate nonlinear, fixed but arbitrary transformations of the data samples within MDP flows.

Example:

>>> import mdp
>>> from mdp import numx

>>> def identity(x): return x

>>> def u3(x): return numx.absolute(x)**3 #A simple nonlinear transformation

>>> def norm2(x): #Computes the norm of each sample returning an Nx1 array
>>>     return ((x**2).sum(axis=1)**0.5).reshape((-1,1))

>>> x = numx.array([[-2., 2.], [0.2, 0.3], [0.6, 1.2]])
>>> gen = mdp.nodes.GeneralExpansionNode(funcs=[identity, u3, norm2])
>>> print(gen.execute(x))
>>> [[-2.          2.          8.          8.          2.82842712]
>>>  [ 0.2         0.3         0.008       0.027       0.36055513]
>>>  [ 0.6         1.2         0.216       1.728       1.34164079]]

Original code contributed by Alberto Escalante.

Instance Methods [hide private]
 
__init__(self, funcs, input_dim=None, dtype=None)
Short argument description:
 
_execute(self, x)
 
execute(self, x)
Process the data contained in x.
 
expanded_dim(self, n)
The expanded dim is computed by directly applying the expansion functions f_i to a zero input of dimension n.
 
output_sizes(self, n)
Return the individual output sizes of each expansion function when the input has lenght n.
 
pseudo_inverse(self, x, use_hint=None)
Calculate a pseudo inverse of the expansion using scipy.optimize.

Inherited from unreachable._ExpansionNode (private): _set_input_dim, _set_output_dim

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

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

    Inherited from Node
 
__add__(self, other)
 
__call__(self, x, *args, **kwargs)
Calling an instance of Node is equivalent to calling its execute method.
 
__repr__(self)
repr(x)
 
__str__(self)
str(x)
 
_check_input(self, x)
 
_check_output(self, y)
 
_check_train_args(self, x, *args, **kwargs)
 
_get_supported_dtypes(self)
Return the list of dtypes supported by this node.
 
_get_train_seq(self)
 
_if_training_stop_training(self)
 
_inverse(self, x)
 
_pre_execution_checks(self, x)
This method contains all pre-execution checks.
 
_pre_inversion_checks(self, y)
This method contains all pre-inversion checks.
 
_refcast(self, x)
Helper function to cast arrays to the internal dtype.
 
_set_dtype(self, t)
 
_stop_training(self, *args, **kwargs)
 
_train(self, x)
 
copy(self, protocol=None)
Return a deep copy of the node.
 
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 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. If filename is None, return a string.
 
set_dtype(self, t)
Set internal structures' dtype.
 
set_input_dim(self, n)
Set input dimensions.
 
set_output_dim(self, n)
Set output dimensions.
 
stop_training(self, *args, **kwargs)
Stop the training phase.
 
train(self, x, *args, **kwargs)
Update the internal structures according to the input data x.
Static Methods [hide private]
 
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]

Inherited from object: __class__

    Inherited from Node
  _train_seq
List of tuples:
  dtype
dtype
  input_dim
Input dimensions
  output_dim
Output dimensions
  supported_dtypes
Supported dtypes
Method Details [hide private]

__init__(self, funcs, input_dim=None, dtype=None)
(Constructor)

 

Short argument description:

funcs
list of functions f_i that realize the expansion.
Overrides: object.__init__

_execute(self, x)

 
Overrides: Node._execute

execute(self, x)

 

Process the data contained in x.

If the object is still in the training phase, the function stop_training will be called. x is a matrix having different variables on different columns and observations on the rows.

By default, subclasses should overwrite _execute to implement their execution phase. The docstring of the _execute method overwrites this docstring.

Overrides: Node.execute

expanded_dim(self, n)

 
The expanded dim is computed by directly applying the expansion functions f_i to a zero input of dimension n.
Overrides: unreachable._ExpansionNode.expanded_dim

is_invertible()
Static Method

 
Return True if the node can be inverted, False otherwise.
Overrides: Node.is_invertible
(inherited documentation)

is_trainable()
Static Method

 
Return True if the node can be trained, False otherwise.
Overrides: Node.is_trainable
(inherited documentation)

output_sizes(self, n)

 
Return the individual output sizes of each expansion function when the input has lenght n.

pseudo_inverse(self, x, use_hint=None)

 

Calculate a pseudo inverse of the expansion using scipy.optimize.

use_hint
when calculating a pseudo inverse of the expansion, the hint determines the starting point for the approximation. For details on this parameter see the function invert_exp_funcs2 in mdp.utils.routines.py.

This method requires scipy.