/
superposition.py
57 lines (47 loc) · 1.7 KB
/
superposition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from nengo.params import Default, IntParam
from nengo_spa.network import Network
from nengo_spa.vocabulary import VocabularyOrDimParam
class Superposition(Network):
"""
Network for superposing multiple inputs.
Parameters
----------
n_inputs : int
Number of inputs.
vocab : Vocabulary or int
The vocabulary to use to interpret the vector. If an integer is given,
the default vocabulary of that dimensionality will be used.
neurons_per_dimension : int, optional (Default: 200)
Number of neurons to use in each dimension.
**kwargs : dict
Keyword arguments passed through to `nengo_spa.Network`.
Attributes
----------
inputs : sequence
Inputs.
output : nengo.Node
Output.
"""
vocab = VocabularyOrDimParam("vocab", default=None, readonly=True)
neurons_per_dimension = IntParam(
"neurons_per_dimension", default=200, low=1, readonly=True
)
n_inputs = IntParam("n_inputs", optional=False, low=1, readonly=True)
def __init__(
self, n_inputs, vocab=Default, neurons_per_dimension=Default, **kwargs
):
super(Superposition, self).__init__(**kwargs)
self.vocab = vocab
self.neurons_per_dimension = neurons_per_dimension
self.n_inputs = n_inputs
with self:
(
self.superposition_net,
self.inputs,
self.output,
) = self.vocab.algebra.implement_superposition(
self.neurons_per_dimension, self.vocab.dimensions, self.n_inputs
)
for inp in self.inputs:
self.declare_input(inp, self.vocab)
self.declare_output(self.output, self.vocab)