Open in Colab

Partitioning

Here are listed all the relation blocks to slice or select a subvector inside the neural architecture.

[1]:
# uncomment the command below to install the nnodely package
#!pip install nnodely

from nnodely import *
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>-- nnodely_v1.5.0 --<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Part

Represents a sub-window from a relation in the neural network model. The index of the first and last element must be provided.

The Part relation works along the object dimension (third dimension) of the input.

[2]:
x = Input('x', dimensions=10).last()
sub = Part(x, 0, 2)
out = Output('out', sub)
test = Modely(visualizer=None)
test.addModel('test', [out])
test.neuralizeModel()
test({'x': [[1,2,3,4,5,6,7,8,9,10]]})
[2]:
{'out': [[[1.0, 2.0]]]}

Select

Represents a single element from a relation in the neural network model, using 0-index convention. The index of the element must be provided.

The Select relation works along the object dimension (third dimension) of the input.

[3]:
x = Input('x', dimensions=3).last()
sub = Select(x, 1)
out = Output('out', sub)
test = Modely(visualizer=None)
test.addModel('test', [out])
test.neuralizeModel()
test({'x': [[1,2,3]]})
[check_names] The name 'x' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'out' is already in defined as NeuObj but it is overwritten.
[3]:
{'out': [2.0]}

Concatenate

Represents the concatenate function between two relations.

The Concatenate relation works along the object dimension (third dimension) of the input.

[4]:
x = Input('x', dimensions=3).last()
y = Input('y', dimensions=5).last()
cat = Concatenate(x, y)
out = Output('out', cat)
test = Modely(visualizer=None)
test.addModel('test', [out])
test.neuralizeModel()
test({'x': [[1,2,3]],'y': [[4,5,6,7,8]]})
[check_names] The name 'x' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'out' is already in defined as NeuObj but it is overwritten.
[4]:
{'out': [[[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]]]}

SamplePart

Represents a sub-window from a relation in the neural network model. The index of the first and last element must be provided.

The SamplePart relation works along the time dimension (second dimension) of the input.

[5]:
x = Input('x')
x_sw10 = x.sw(10)
relation = SamplePart(x_sw10, 0, 3)
out = Output('out', relation)
out2 = Output('out2', x.last())
test = Modely(visualizer=None)
test.addModel('test', [out,out2])
test.neuralizeModel()
# Test 1 input in time
test({'x': [1,2,3,4,5,6,7,8,9,10]})
[check_names] The name 'x' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'out' is already in defined as NeuObj but it is overwritten.
[5]:
{'out2': [10.0], 'out': [[1.0, 2.0, 3.0]]}
[6]:
# Test 2 input in time
test({'x': [1,2,3,4,5,6,7,8,9,10,11]})
[6]:
{'out2': [10.0, 11.0], 'out': [[1.0, 2.0, 3.0], [2.0, 3.0, 4.0]]}

SampleSelect

Represents a single element from a relation in the neural network model, using 0-index convention. The index of the element must be provided.

The SampleSelect relation works along the time dimension (second dimension) of the input.

[7]:
x = Input('x').sw(10)
relation = SampleSelect(x, 5)
out = Output('out', relation)
test = Modely(visualizer=None)
test.addModel('test', [out])
test.neuralizeModel()
test({'x': [1,2,3,4,5,6,7,8,9,10]})
[check_names] The name 'x' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'out' is already in defined as NeuObj but it is overwritten.
[7]:
{'out': [6.0]}
[8]:
test = Modely(visualizer=None)
test.addModel('test', [out, Output('out2',  relation.sw(2))])
test.neuralizeModel()
test({'x': [1,2,3,4,5,6,7,8,9,10,11]})
[check_names] The name 'out2' is already in defined as NeuObj but it is overwritten.
[8]:
{'out2': [[0.0, 6.0], [6.0, 7.0]], 'out': [6.0, 7.0]}

TimeConcatenate

Represents the concatenate function between two relations but the TimeConcatenate relation works along the time dimension (second dimension).

[9]:
x = Input('x').sw(5)
y = Input('y').sw(3)
cat = TimeConcatenate(x, y)
cat2 = TimeConcatenate(Fir(x), y)
out = Output('out', cat)
out2 = Output('out2', cat2)
test = Modely(visualizer=None)
test.addModel('test', [out,out2])
test.neuralizeModel()
test({'x': [1,2,3,4,5],'y': [1,2,3]})
[check_names] The name 'x' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'y' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'out' is already in defined as NeuObj but it is overwritten.
[check_names] The name 'out2' is already in defined as NeuObj but it is overwritten.
[9]:
{'out2': [[4.684988021850586, 1.0, 2.0, 3.0]],
 'out': [[1.0, 2.0, 3.0, 4.0, 5.0, 1.0, 2.0, 3.0]]}