Input Bricks

class fugu.bricks.input_bricks.InputSource

Bases: object

Base class for handling various input sources/streams. .. rubric:: Example

Converted output (as a stream of 0’s and 1’s) from a DVI camera

abstract connect(graph, metadata, source)

Abstract method that tells the scaffold how it should connect the source to the circuit. This is accomplished by using a “source” dictionary argument when you create neurons/synapses. The “source” dictionary will contain whatever information the backends will need. :param graph: networkx graph to define connections of the computational graph

  • If the graph has edge weights, this brick will solve the single source shortest paths problem

Parameters:

metadata (dict) – dictionary to define the shapes and parameters of the brick

Example 1:

Suppose the source was a motion detector (connected to hardware by a usb). Everytime there is movement detected, we want a specific neuron to fire. Then connect might look something like:

connect():
scaffold.graph.add_node(

“Sensor”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘usb’, ‘device_name’: ‘camera’, ‘device_id’: ‘00:07.0’,

},

)

scaffold.graph.add_edge(

“Sensor”, some_other_neuron, weight=1.0, delay=1, )

Example 2:

Suppose the source was a network port receiving TCP packets We want to fire specific neurons based on which flag bits are set Then connect might look something like:

connect():
scaffold.graph.add_node(

“TCPPortA”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘tcp_port’, ‘device_id’: ‘20’, ‘flag_bit_id’: 1, # Look at flag bit #1 ‘flag_fire_value’: 0, # Fire if flag bit #1 is a 0

},

)

scaffold.graph.add_edge(

“TCPPortA”, some_other_neuron, weight=1.0, delay=1, )

scaffold.graph.add_node(

“TCPPortB”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘tcp_port’, ‘device_id’: ‘20’, ‘flag_bit_id’: 3, # Look at flag bit #3 ‘flag_fire_value’: 1, # Fire if flag bit #3 is a 1

},

)

scaffold.graph.add_edge(

“TCPPortB”, some_other_neuron, weight=1.0, delay=1, )

scaffold.graph.add_node(

“TCPPortC”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘tcp_port’, ‘device_id’: ‘20’, ‘flag_bit_id’: 7, # Look at flag bit #7 ‘flag_fire_value’: 0, # Fire if flag bit #7 is a 0

},

)

scaffold.graph.add_edge(

“TCPPortC”, some_other_neuron, weight=1.0, delay=1, )

class fugu.bricks.input_bricks.Vector_Input(spikes, time_dimension=False, coding='Undefined', batchable=True, name='VectorInput')

Bases: InputBrick

Class to handle a vector of spiking input. Inherits from InputBrick Construtor for this brick.

Args:

spikes (array): A numpy array of which neurons should spike at which times time_dimension: Time dimesion is included as dimension -1 coding: Coding type to be represented. batchable: True if input should represent static data; currently True is the only supported mode. name (str): Name of the brick. If not specified, a default will be used. Name should be unique.

next()
set_properties(properties={})

Returns an updated version of the graph based on the property values passed.

get_input_value(t=None)

Abstract method to get input values. InputBricks must implement this method

Parameters:

t – type of input (Default: None)

classmethod input_ports() dict[str, PortSpec]

Describes the ports on which this brick will take in data from other bricks. Returns a dictionary of PortSpec objects. The key is the name of the input port as known to this brick. See scaffold.py for the definition of PortSpec. A return value of {} indicate that this brick does not take inputs. Effectively, that flags this as an input brick, in the sense that all values originate from here.

classmethod output_ports() dict[str, PortSpec]

Describes the ports on which this brick will output data to other bricks. Returns a dictionary of PortSpec objects. The key is the name of the output port as known to this brick. See scaffold.py for the definition of PortSpec. A return value of {} indicates that this brick does not produce outputs. This can happen if the brick does some form of direct I/O.

build2(graph, inputs: dict[str, PortData] = {})

Build spike input brick.

Parameters:
  • graph – networkx graph to define connections of the computational graph

  • metadata – dictionary to define the shapes and parameters of the brick

  • control_nodes

    list of dictionary of auxillary nodes. Expected keys:

    ’complete’ - A list of neurons that fire when the brick is done

  • input_lists – list of nodes that will contain input

  • input_coding – list of input coding formats

Returns:

graph of a computational elements and connections output_shape, output_coding, layer, D: dictionary of output parameters (shape, coding, layers, depth, etc) complete_node, begin_node: list of dictionary of control nodes (‘complete’) output_lists (list): list of output output_codings (list): list of coding formats of output

Return type:

graph

class fugu.bricks.input_bricks.BaseP_Input(array, p=2, bits=8, collapse_binary=True, time_dimension=False, coding='Undefined', name='BasePInput', flatten=0)

Bases: Vector_Input

Class to handle converting a numpy array to a “Base p” encoding. Inherits from Vector_Input.

By “Base p” we mean that an array is converted so that the numbers are represented by spikes using a particular base.

The case where p=2 corresponds to binary. (Note that binary has a specific collapse_binary described below.)

For now, the brick supports converting non-negative integer values only.

Here are some examples of how values are converted.

x = 222 p=7 bits=3 -> [5, 3, 4] as 222 = 5*7^0 + 3*7^1 + 4*7^2 x = 222 p=3 bits=5 -> [0,2,0,2,2] as 222 = 0*3^0 + 2*3^1 + 0*3^2 + 2*3^3 + 2*3^4

The resulting values are unary coded, with the first entry corresponding to 0. Neurons that correspond to the factor will spike. (p=7) [5, 3, 4] = [[0,0,0,0,0,1,0], [0,0,0,1,0,0,0], [0,0,0,0,1,0,0]] (p=3) [0, 2, 0, 2, 2] = [[1,0,0], [0,0,1], [1,0,0], [0,0,1], [0,0,1]]

Note that the input space will require N*p*bits input neurons (where N is the number of values in the array).

In this configuration, there will be N*p spikes.

In general, the array becomes formatted as (…, p, bits).

For p=2 (that is, binary), we have the option of collapse_binary, which removes one axis of redundant information.

In this case, we map the last axis as [1,0] -> 0 [0, 1] -> 1

and our array has shape (…, p).

Lastly, we allow for a time_dimension. If time_dimension is True, then the last dimension of the input array is treated as a time index. This is the same behavior as in the base Vector_Input.

If time_dimension=False, then all the spikes delivered at the same time (first timestep).

If time_dimension=True, then the last dimension is treated as a time dimension and each slice creates spikes at that timestep.

In this case, the last dimension is preserved as a time dimension.

Examples:

Input is (2,4), p=3, bits=5, time_dimension=False. Output will be (2, 4, 3, 5) all of which are delivered at the first timestep. Input is (2,4), p=3, bits=5, time_dimension=True. Output will be (2,3,5) and there will be 4 timesteps of input spikes.

Construtor for this brick.
Args:

array (ndarray): A numpy array of values. Currently supported values are non-negative integers. p (int): Base to use bits (int): Number of ‘bits’ or factors to use collapse_binary (boolean): If true, binary arrays are collapsed to a single dim. time_dimension: Time dimesion is included as dimension -1 coding: Coding type to be represented. name (str): Name of the brick. If not specified, a default will be used. Name should be unique.

set_properties(properties={})

Returns an updated version of the graph based on the property values passed.

class fugu.bricks.input_bricks.InputSource

Bases: object

Base class for handling various input sources/streams. .. rubric:: Example

Converted output (as a stream of 0’s and 1’s) from a DVI camera

abstract connect(graph, metadata, source)

Abstract method that tells the scaffold how it should connect the source to the circuit. This is accomplished by using a “source” dictionary argument when you create neurons/synapses. The “source” dictionary will contain whatever information the backends will need. :param graph: networkx graph to define connections of the computational graph

  • If the graph has edge weights, this brick will solve the single source shortest paths problem

Parameters:

metadata (dict) – dictionary to define the shapes and parameters of the brick

Example 1:

Suppose the source was a motion detector (connected to hardware by a usb). Everytime there is movement detected, we want a specific neuron to fire. Then connect might look something like:

connect():
scaffold.graph.add_node(

“Sensor”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘usb’, ‘device_name’: ‘camera’, ‘device_id’: ‘00:07.0’,

},

)

scaffold.graph.add_edge(

“Sensor”, some_other_neuron, weight=1.0, delay=1, )

Example 2:

Suppose the source was a network port receiving TCP packets We want to fire specific neurons based on which flag bits are set Then connect might look something like:

connect():
scaffold.graph.add_node(

“TCPPortA”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘tcp_port’, ‘device_id’: ‘20’, ‘flag_bit_id’: 1, # Look at flag bit #1 ‘flag_fire_value’: 0, # Fire if flag bit #1 is a 0

},

)

scaffold.graph.add_edge(

“TCPPortA”, some_other_neuron, weight=1.0, delay=1, )

scaffold.graph.add_node(

“TCPPortB”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘tcp_port’, ‘device_id’: ‘20’, ‘flag_bit_id’: 3, # Look at flag bit #3 ‘flag_fire_value’: 1, # Fire if flag bit #3 is a 1

},

)

scaffold.graph.add_edge(

“TCPPortB”, some_other_neuron, weight=1.0, delay=1, )

scaffold.graph.add_node(

“TCPPortC”, threshold=1.0, decay=1.0, potential=0.0, source={

‘device_type’: ‘tcp_port’, ‘device_id’: ‘20’, ‘flag_bit_id’: 7, # Look at flag bit #7 ‘flag_fire_value’: 0, # Fire if flag bit #7 is a 0

},

)

scaffold.graph.add_edge(

“TCPPortC”, some_other_neuron, weight=1.0, delay=1, )

class fugu.bricks.input_bricks.Vector_Input(spikes, time_dimension=False, coding='Undefined', batchable=True, name='VectorInput')

Bases: InputBrick

Class to handle a vector of spiking input. Inherits from InputBrick Construtor for this brick.

Args:

spikes (array): A numpy array of which neurons should spike at which times time_dimension: Time dimesion is included as dimension -1 coding: Coding type to be represented. batchable: True if input should represent static data; currently True is the only supported mode. name (str): Name of the brick. If not specified, a default will be used. Name should be unique.

next()
set_properties(properties={})

Returns an updated version of the graph based on the property values passed.

get_input_value(t=None)

Abstract method to get input values. InputBricks must implement this method

Parameters:

t – type of input (Default: None)

classmethod input_ports() dict[str, PortSpec]

Describes the ports on which this brick will take in data from other bricks. Returns a dictionary of PortSpec objects. The key is the name of the input port as known to this brick. See scaffold.py for the definition of PortSpec. A return value of {} indicate that this brick does not take inputs. Effectively, that flags this as an input brick, in the sense that all values originate from here.

classmethod output_ports() dict[str, PortSpec]

Describes the ports on which this brick will output data to other bricks. Returns a dictionary of PortSpec objects. The key is the name of the output port as known to this brick. See scaffold.py for the definition of PortSpec. A return value of {} indicates that this brick does not produce outputs. This can happen if the brick does some form of direct I/O.

build2(graph, inputs: dict[str, PortData] = {})

Build spike input brick.

Parameters:
  • graph – networkx graph to define connections of the computational graph

  • metadata – dictionary to define the shapes and parameters of the brick

  • control_nodes

    list of dictionary of auxillary nodes. Expected keys:

    ’complete’ - A list of neurons that fire when the brick is done

  • input_lists – list of nodes that will contain input

  • input_coding – list of input coding formats

Returns:

graph of a computational elements and connections output_shape, output_coding, layer, D: dictionary of output parameters (shape, coding, layers, depth, etc) complete_node, begin_node: list of dictionary of control nodes (‘complete’) output_lists (list): list of output output_codings (list): list of coding formats of output

Return type:

graph