same_input_layer

Module: missions.nodes.meta.same_input_layer

Combine several other nodes together in parallel

This is useful to be combined with the FlowNode.

Inheritance diagram for pySPACE.missions.nodes.meta.same_input_layer:

Inheritance diagram of pySPACE.missions.nodes.meta.same_input_layer

Class Summary

SameInputLayerNode(nodes[, ...]) Encapsulates a set of other nodes that are executed in parallel in the flow.
EnsembleNotFoundException Error when loading of ensembles is not possible
ClassificationFlowsLoaderNode(...[, ...]) Combine an ensemble of pretrained node chains
MultiClassLayerNode(nodes[, ...]) Wrap the one vs.

Classes

SameInputLayerNode

class pySPACE.missions.nodes.meta.same_input_layer.SameInputLayerNode(nodes, enforce_unique_names=True, store=False, **kwargs)[source]

Bases: pySPACE.missions.nodes.base_node.BaseNode

Encapsulates a set of other nodes that are executed in parallel in the flow.

This node was a thin wrapper around MDP’s SameInputLayer node but is now an own implementation.

Parameters

enforce_unique_names:
 

When combining time series channels or feature vectors, the node adds the index of the current node to the channel names or feature names as a prefix to enforce unique names.

(optional, default: True)

Exemplary Call

- 
    node : Same_Input_Layer
    parameters : 
         enforce_unique_names  : True
         nodes : 
                -
                    node : Time_Domain_Features
                    parameters :
                          moving_window_length : 1
                -
                    node : STFT_Features
                    parameters :
                          frequency_band : [2.0, 8.0]
                          frequency_resolution : 1.0
POSSIBLE NODE NAMES:
 
  • SameInputLayerNode
  • Same_Input_Layer
  • SameInputLayer
POSSIBLE INPUT TYPES:
 
  • TimeSeries

Class Components Summary

_execute(data) Process the data through the internal nodes
_inc_train(data, label) Forward data to retrainable nodes
_stop_training() Perform single training step by training the internal nodes
_train(x, \*args, \*\*kwargs) Perform single training step by training the internal nodes
add_feature_vector(data, index, ...) Concatenate feature vectors, ensuring unique names
get_output_type(input_type[, as_string]) Returns expected output from first node
input_types
is_supervised() Supervised if one subnode requires supervised training
is_trainable() Trainable if one subnode is trainable
node_from_yaml(layer_spec) Load the specs and initialize the layer nodes
register_input_node(input_node) All sub-nodes have the same input node
reset() Also reset internal nodes
set_run_number(run_number) Informs all subnodes about the number of the current run
store_state(result_dir[, index]) Stores all nodes in subdirectories of result_dir
input_types = ['TimeSeries']
__init__(nodes, enforce_unique_names=True, store=False, **kwargs)[source]
static node_from_yaml(layer_spec)[source]

Load the specs and initialize the layer nodes

reset()[source]

Also reset internal nodes

register_input_node(input_node)[source]

All sub-nodes have the same input node

_execute(data)[source]

Process the data through the internal nodes

add_feature_vector(data, index, result_array, names)[source]

Concatenate feature vectors, ensuring unique names

is_trainable()[source]

Trainable if one subnode is trainable

is_supervised()[source]

Supervised if one subnode requires supervised training

_train(x, *args, **kwargs)[source]

Perform single training step by training the internal nodes

_stop_training()[source]

Perform single training step by training the internal nodes

store_state(result_dir, index=None)[source]

Stores all nodes in subdirectories of result_dir

_inc_train(data, label)[source]

Forward data to retrainable nodes

So the single nodes do not need to buffer or present_labels does not have to be reimplemented.

set_run_number(run_number)[source]

Informs all subnodes about the number of the current run

get_output_type(input_type, as_string=True)[source]

Returns expected output from first node

Additionally the type is compared with the expected output of the other nodes to ensure consistency.

EnsembleNotFoundException

class pySPACE.missions.nodes.meta.same_input_layer.EnsembleNotFoundException[source]

Bases: exceptions.Exception

Error when loading of ensembles is not possible

__weakref__

list of weak references to the object (if defined)

ClassificationFlowsLoaderNode

class pySPACE.missions.nodes.meta.same_input_layer.ClassificationFlowsLoaderNode(ensemble_base_dir, ensemble_pattern, flow_select_list=[-1], cache_dir=None, **kwargs)[source]

Bases: pySPACE.missions.nodes.base_node.BaseNode

Combine an ensemble of pretrained node chains

This node loads all “pickled” flows whose file names match ensemble_pattern and are contained in the directory tree rooted at ensemble_base_dir. If the flow_select_list is not empty, only the flows with indices contained in flow_select_list are used. The index “-1” corresponds to “all flows”.

Parameters

ensemble_base_dir:
 

The root directory under which the stored flow objects which constitute the ensemble are stored.

ensemble_pattern:
 

Pickled flows must match the given pattern to be included into the ensemble.

flow_select_list:
 

This optional parameter allows to select only a subset of the flows that are found in ensemble_base_dir. It must be a list of indices. Only the flows with the given index are included into the ensemble. If -1 is contained in the list, all flows are automatically added to the ensemble.

Note

The order of the flows in the ensemble is potentially random or at least hard to predict. Thus, this parameter should not be used to select a specific flow. In contrast, this parameter can be used to select a certain number of flows from the available flows (where it doesn’t matter which ones). This can be useful for instance in benchmarking experiments when one is interested in the average performance of an ensemble of a certain size.

(optional, default: [-1])

cache_dir:

If this argument is given, all results of all ensembles are remembered and stored in a persistent cache file in the given cache_dir. These cached results can be later reused without actually loading and executing the ensemble.

(optional, default: None)

Exemplary Call

-
    node : Ensemble_Node
    parameters :
          ensemble_base_dir : "/tmp/" # <- insert suitable directory here
          ensemble_pattern : "flow*.pickle"
          flow_select_list : "eval(range(10))"
Author:

Jan Hendrik Metzen (jhm@informatik.uni-bremen.de)

Created:

2010/05/20

POSSIBLE NODE NAMES:
 
  • ClassificationFlowsLoader
  • Ensemble_Node
  • ClassificationFlowsLoaderNode
POSSIBLE INPUT TYPES:
 
  • PredictionVector
  • FeatureVector
  • TimeSeries

Class Components Summary

_execute(data)
_load_cache()
_load_ensemble()
_train(data, label) Trains the ensemble on the given data vector data
get_output_type(input_type[, as_string])
input_types
store_state(result_dir[, index]) Stores this node in the given directory result_dir
__init__(ensemble_base_dir, ensemble_pattern, flow_select_list=[-1], cache_dir=None, **kwargs)[source]
_load_cache()[source]
_load_ensemble()[source]
_train(data, label)[source]

Trains the ensemble on the given data vector data

_execute(data)[source]
store_state(result_dir, index=None)[source]

Stores this node in the given directory result_dir

get_output_type(input_type, as_string=True)[source]
input_types = ['PredictionVector', 'FeatureVector', 'TimeSeries']

MultiClassLayerNode

class pySPACE.missions.nodes.meta.same_input_layer.MultiClassLayerNode(nodes, enforce_unique_names=True, store=False, **kwargs)[source]

Bases: pySPACE.missions.nodes.meta.same_input_layer.SameInputLayerNode

Wrap the one vs. rest or one vs. one scheme around the given node

The given class labels are forwarded to the internal nodes. During training, data is relabeled. Everything else is the same as in the base node.

Though this scheme is most important for classification it permits other trainable algorithms to use this scheme.

Parameters
class_labels:

This is the complete list of expected class labels. It is needed to construct the necessary flows in the initialization stage.

node:

Specification of the wrapped node for the used scheme

As class labels , for the 1vsR scheme, this node has to use REST and LABEL. LABEL is replaced with the different class_labels. The other label should be REST.

For the 1vs1 scheme LABEL1 and LABEL2 have to be used.

scheme:

One of 1v1 (One vs. One) or 1vR (One vs. Rest)

Note

The one class approach is included by simply not giving ‘REST’ label to the classifier, but filtering it out.

(optional, default:‘1v1’)

Exemplary Call

- 
    node : MultiClassLayer
    parameters :
        class_labels : ["Target", "Standard","Artifact"]
        scheme : "1vR"
        node : 
            -
                node : 1SVM
                parameters :
                    class_labels : ["LABEL","REST"]
                    complexity : 1
POSSIBLE NODE NAMES:
 
  • MultiClassLayerNode
  • MultiClassLayer
POSSIBLE INPUT TYPES:
 
  • FeatureVector

Class Components Summary

input_types
node_from_yaml(layer_spec) Load the specs and initialize the layer nodes
input_types = ['FeatureVector']
static node_from_yaml(layer_spec)[source]

Load the specs and initialize the layer nodes