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

Class CircularOnlineFlow


A 'CircularOnlineFlow' is a cyclic sequence of online/non-trainable nodes that are trained and executed together to form a more complex algorithm. This type of flow is useful when one needs to train the nodes internally for several iterations using stored inputs before training with the next external input.

input=x(i) -> [node1, node2, node3] -> output=y' ----External input training---- (1 iteration)

input=y' -> [node1, node2, node3] -> output=y' ---- Internal ... input (n-1 iterations) input=y' -> [node1, node2, node3] -> output=y(i) training----

This type of processing is especially useful for implementing control algorithms, reinforcement learning, etc.

The input and the output nodes of the flow can be changed at any time using the functions "set_input_node" and "set_output_node".

Examples:

If input node and output node are set equal to node1 :

Input -> [node1] -> output
/ [node3] <- [node2]

If input node = node1 and output node is equal to node2

Input -> [node1] -> [node2] -> output
/

[node3]

CircularOnlineFlow also supports training nodes while ignoring external input data at all times. In this case, the flow iterates everytime using the previously stored output as the input. Input data can be arbitrary (with same input_dim and dtype) and is only used as a clock signal to trigger flow processing. See the docstring of the train method for more information about different training types.

Crash recovery is optionally available: in case of failure the current state of the flow is saved for later inspection.

CircularOnlineFlow objects are Python containers. Most of the builtin 'list' methods are available. CircularOnlineFlow can be saved or copied using the corresponding 'save' and 'copy' methods.

Instance Methods [hide private]
 
__add__(self, other)
 
__delitem__(self, key)
 
__getitem__(self, key)
 
__iadd__(self, other)
 
__init__(self, flow, crash_recovery=False, verbose=False)
flow - a list of nodes.
 
__setitem__(self, key, value)
 
_check_compatibility(self, flow)
 
_inverse_seq(self, x)
 
_train_nodes(self, data_iterables)
 
append(flow, node)
append node to flow end
 
execute(self, iterable, nodenr=None)
Process the data through all nodes between input and the output node. This is functionally similar to the execute method of an OnlineFlow.
 
extend(flow, iterable)
extend flow by appending elements from the iterable
 
get_stored_input(self)
return the current stored input
 
ignore_input(self, flag)
CircularOnlineFlow also supports training nodes while ignoring external input data at all times. This mode is enabled/disabled using this method. See train method docstring for information on different training modes.
 
insert(flow, index, node)
insert node before index
 
reset_output_node(self)
Resets the output node to the last node of the provided node sequence
 
set_flow_iterations(self, n)
This method sets the number of total flow iterations: If self._ignore_input is False, then the total flow iterations = 1 external + (n-1) internal iterations. If self._ignore input is True, then the total flow iterations = n internal iterations. See train method docstring for information on different training modes.
 
set_input_node(self, node_idx)
Set the input node of the flow
 
set_output_node(self, node_idx)
Set the output node of the flow
 
set_stored_input(self, x)
CircularOnlineFlow also supports training nodes while ignoring external input data at all times. In this case, the flow iterates every time using an initially stored input that can be set using this method.
 
train(self, data_iterables)
Train all trainable-nodes in the flow.

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 OnlineFlow
 
_check_value_type_is_online_or_nontrainable_node(self, value)
 
_get_required_train_args_from_flow(self, flow)
 
_train_check_iterables(self, data_iterables)
Return the data iterable after some checks and sanitizing.
 
_train_node(self, data_iterable, nodenr)
Train a single node in the flow.
    Inherited from Flow
 
__call__(self, iterable, nodenr=None)
Calling an instance is equivalent to call its 'execute' method.
 
__contains__(self, item)
 
__iter__(self)
 
__len__(self)
 
__repr__(self)
repr(x)
 
__str__(self)
str(x)
 
_check_dimension_consistency(self, out, inp)
Raise ValueError when both dimensions are set and different.
 
_check_nodes_consistency(self, flow=None)
Check the dimension consistency of a list of nodes.
 
_check_value_type_isnode(self, value)
 
_close_last_node(self)
 
_execute_seq(self, x, nodenr=None)
 
_propagate_exception(self, except_, nodenr)
 
_stop_training_hook(self)
Hook method that is called before stop_training is called.
 
copy(self, protocol=None)
Return a deep copy of the flow.
 
inverse(self, iterable)
Process the data through all nodes in the flow backwards (starting from the last node up to the first node) by calling the inverse function of each node. Of course, all nodes in the flow must be invertible.
node
pop(flow, index=...)
remove and return node at index (default last)
 
save(self, filename, protocol=-1)
Save a pickled serialization of the flow to 'filename'. If 'filename' is None, return a string.
 
set_crash_recovery(self, state=True)
Set crash recovery capabilities.
Static Methods [hide private]
    Inherited from Flow
 
_get_required_train_args(node)
Return arguments in addition to self and x for node.train.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__add__(self, other)
(Addition operator)

 
Overrides: Flow.__add__

__delitem__(self, key)
(Index deletion operator)

 
Overrides: Flow.__delitem__

__getitem__(self, key)
(Indexing operator)

 
Overrides: Flow.__getitem__

__iadd__(self, other)

 
Overrides: Flow.__iadd__

__init__(self, flow, crash_recovery=False, verbose=False)
(Constructor)

 
flow - a list of nodes.
Overrides: object.__init__

__setitem__(self, key, value)
(Index assignment operator)

 
Overrides: Flow.__setitem__

_check_compatibility(self, flow)

 
Overrides: OnlineFlow._check_compatibility

_inverse_seq(self, x)

 
Overrides: Flow._inverse_seq

_train_nodes(self, data_iterables)

 
Overrides: OnlineFlow._train_nodes

append(flow, node)

 
append node to flow end
Overrides: Flow.append

execute(self, iterable, nodenr=None)

 

Process the data through all nodes between input and the output node. This is functionally similar to the execute method of an OnlineFlow.

'iterable' is an iterable or iterator (note that a list is also an iterable), which returns data arrays that are used as input to the flow. Alternatively, one can specify one data array as input.

Overrides: Flow.execute

extend(flow, iterable)

 
extend flow by appending elements from the iterable
Overrides: Flow.extend

get_stored_input(self)

 
return the current stored input

ignore_input(self, flag)

 
CircularOnlineFlow also supports training nodes while ignoring external input data at all times. This mode is enabled/disabled using this method. See train method docstring for information on different training modes.

insert(flow, index, node)

 
insert node before index
Overrides: Flow.insert

reset_output_node(self)

 
Resets the output node to the last node of the provided node sequence

set_flow_iterations(self, n)

 
This method sets the number of total flow iterations: If self._ignore_input is False, then the total flow iterations = 1 external + (n-1) internal iterations. If self._ignore input is True, then the total flow iterations = n internal iterations. See train method docstring for information on different training modes.

set_input_node(self, node_idx)

 
Set the input node of the flow

set_output_node(self, node_idx)

 
Set the output node of the flow

set_stored_input(self, x)

 
CircularOnlineFlow also supports training nodes while ignoring external input data at all times. In this case, the flow iterates every time using an initially stored input that can be set using this method.

train(self, data_iterables)

 

Train all trainable-nodes in the flow.

'data_iterables' is a single iterable (including generator-type iterators) that must return data arrays to train nodes (so the data arrays are the 'x' for the nodes). Note that the data arrays are processed by the nodes which are in front of the node that gets trained, so the data dimension must match the input dimension of the first node.

'data_iterables' can also be a 2D or a 3D numpy array. A 2D array trains all the nodes incrementally, while a 3D array supports online training in batches (=shape[1]).

Circular flow does not support passing training arguments.

There are three ways that the training can proceed based on the values of self._ignore_input (default=False, can be set via 'ignore_input' method) and self._flow_iterations argument (default=1, can be set via 'set_flow_iterations' method).

  1. self._ignore_input = False, self._flow_iterations = 1 (default case)

    This is functionally similar to the standard OnlineFlow. Each data array returned by the data_iterables is used to train the nodes simultaneously.

  2. self._ignore_input = False, self._flow_iterations > 1

    For each data_array returned by the data_iterables, the flow trains 1 loop with the data_array and 'self._flow_iterations-1' loops with the updating stored inputs.

  3. self._ignore_input = True, self._flow_iterations > 1

    The data_arrays returned by the data_iterables are ignored, however, for each data_array, the flow trains 'self._flow_iterations' loops with the updating stored inputs.

Overrides: Flow.train