Note
This documentation is for a development version. Click here for the latest stable release (v1.3.0).
nengo_spa.semantic_pointer¶
Classes
|
Absorbing element. |
|
Identity element. |
|
Negative identity element. |
|
A Semantic Pointer, based on Holographic Reduced Representations. |
|
Sign of a Semantic Pointer. |
|
Zero element. |
-
class
nengo_spa.semantic_pointer.
SemanticPointer
(data, vocab=None, algebra=None, name=None)[source]¶ A Semantic Pointer, based on Holographic Reduced Representations.
Operators are overloaded so that
+
and-
are addition,*
is circular convolution, and~
is the two-sided inversion operator. The left and right inverese can be obtained with thelinv
andrinv
methods.- Parameters
- dataarray_like
The vector constituting the Semantic Pointer.
- vocabVocabulary, optional
Vocabulary that the Semantic Pointer is considered to be part of. Mutually exclusive with the algebra argument.
- algebraAbstractAlgebra, optional
Algebra used to perform vector symbolic operations on the Semantic Pointer. Defaults to
HrrAlgebra
. Mutually exclusive with the vocab argument.- namestr, optional
A name for the Semantic Pointer.
- Attributes
- varray_like
The vector constituting the Semantic Pointer.
- algebraAbstractAlgebra
Algebra that defines the vector symbolic operations on this Semantic Pointer.
- vocabVocabulary or None
The vocabulary the this Semantic Pointer is considered to be part of.
- namestr or None
Name of the Semantic Pointer.
-
normalized
()[source]¶ Normalize the Semantic Pointer and return it as a new object.
If the vector length is zero, the Semantic Pointer will be returned unchanged.
The original object is not modified.
-
unitary
()[source]¶ Make the Semantic Pointer unitary and return it as a new object.
The original object is not modified.
A unitary Semantic Pointer has the property that it does not change the length of Semantic Pointers it is bound with.
-
sign
()[source]¶ Return the sign of the Semantic Pointer.
See
AbstractAlgebra.sign
for details on signs of Semantic Pointers.- Returns
- SemanticPointerSign
Sign of the Semantic Pointer.
-
abs
()[source]¶ Return the absolute Semantic Pointer.
See
AbstractAlgebra.abs
for details on absolute Semantic Pointers.
-
__pow__
(other)[source]¶ Binding power of the Semantic Pointer.
Integer exponents are supported for any algebra. See the
binding_power
documentation of the respective algebra for details about fractional exponents.- Parameters
- otherfloat
Exponent of the binding power.
- Returns
- SemanticPointer
-
__invert__
()[source]¶ Return a reorganized
SemanticPointer
that acts as a two-sided inverse for binding.
-
linv
()[source]¶ Return a reorganized
SemanticPointer
that acts as a left inverse for binding.See also
-
rinv
()[source]¶ Return a reorganized
SemanticPointer
that acts as a right inverse for binding.See also
-
get_binding_matrix
(swap_inputs=False)[source]¶ Return the matrix that does a binding with this vector.
This should be such that
A*B == dot(A.get_binding_matrix(), B.v)
.
-
compare
(other)[source]¶ Return the similarity between two SemanticPointers.
This is the normalized dot product, or (equivalently), the cosine of the angle between the two vectors.
-
reinterpret
(vocab)[source]¶ Reinterpret the Semantic Pointer as part of vocabulary vocab.
The vocab parameter can be set to None to clear the associated vocabulary and allow the source to be interpreted as part of the vocabulary of any Semantic Pointer it is combined with.
-
translate
(vocab, populate=None, keys=None, solver=None)[source]¶ Translate the Semantic Pointer to vocabulary vocab.
The translation of a Semantic Pointer uses some form of projection to convert the Semantic Pointer to a Semantic Pointer of another vocabulary. By default the outer products of terms in the source and target vocabulary are used, but if solver is given, it is used to find a least squares solution for this projection.
- Parameters
- vocabVocabulary
Target vocabulary.
- populatebool, optional
Whether the target vocabulary should be populated with missing keys. This is done by default, but with a warning. Set this explicitly to True or False to silence the warning or raise an error.
- keyslist, optional
All keys to translate. If None, all keys in the source vocabulary will be translated.
- solvernengo.Solver, optional
If given, the solver will be used to solve the least squares problem to provide a better projection for the translation.
-
class
nengo_spa.semantic_pointer.
SemanticPointerSign
(sign, *, algebra=None, dimensions=None, vocab=None, name=None)[source]¶ Bases:
nengo_spa.algebras.base.AbstractSign
Sign of a Semantic Pointer.
This class acts as proxy to the actual sign instance of the underlying algebra. Use the sign attribute if you want to perform equality checks with other signs.
- Parameters
- signAbstractSign
Actual underlying sign.
- algebraAbstractAlgebra, optional
The underlying algebra of the Semantic Pointer for which the sign is represented.
- dimensionsint, optional
Number of dimensions of the Semantic Pointer for which the sign is represented. If not given, vocab must be given.
- vocabVocabulary, optional
Vocabulary of the Semantic Pointer for which the sign is represented. If not given, dimensions must be given. If dimensions and vocab are given, they must agree on the dimensionality.
- namestr or Node, optional
Name of the Semantic Pointer including the invoked sign operation.
- Attributes
- signAbstractSign
Actual underlying sign
- algebraAbstractAlgebra or None
The underlying algebra of the Semantic Pointer for which the sign is represented.
- dimensionsint
Number of dimensions of the Semantic Pointer for which the sign is represented.
- vocabVocabulary or None
Vocabulary of the Semantic Pointer for which the sign is represented.
-
class
nengo_spa.semantic_pointer.
Identity
(n_dimensions, vocab=None, algebra=None, *, sidedness=<ElementSidedness.TWO_SIDED: 'two-sided'>)[source]¶ Bases:
nengo_spa.semantic_pointer.SemanticPointer
Identity element.
- Parameters
- n_dimensionsint
Dimensionality of the identity vector.
- vocabVocabulary, optional
Vocabulary that the Semantic Pointer is considered to be part of. Mutually exclusive with the algebra argument.
- algebraAbstractAlgebra, optional
Algebra used to perform vector symbolic operations on the Semantic Pointer. Defaults to
HrrAlgebra
. Mutually exclusive with the vocab argument.- sidednessElementSidedness, optional
Side in the binding operation on which the element acts as identity.
-
class
nengo_spa.semantic_pointer.
NegativeIdentity
(n_dimensions, vocab=None, algebra=None, *, sidedness=<ElementSidedness.TWO_SIDED: 'two-sided'>)[source]¶ Bases:
nengo_spa.semantic_pointer.SemanticPointer
Negative identity element.
- Parameters
- n_dimensionsint
Dimensionality of the negative identity vector.
- vocabVocabulary, optional
Vocabulary that the Semantic Pointer is considered to be part of. Mutually exclusive with the algebra argument.
- algebraAbstractAlgebra, optional
Algebra used to perform vector symbolic operations on the Semantic Pointer. Defaults to
HrrAlgebra
. Mutually exclusive with the vocab argument.- sidednessElementSidedness, optional
Side in the binding operation on which the element acts as identity.
-
class
nengo_spa.semantic_pointer.
AbsorbingElement
(n_dimensions, vocab=None, algebra=None, *, sidedness=<ElementSidedness.TWO_SIDED: 'two-sided'>)[source]¶ Bases:
nengo_spa.semantic_pointer.SemanticPointer
Absorbing element.
If \(z\) denotes the absorbing element, \(v \circledast z = c z\), where \(v\) is a Semantic Pointer and \(c\) is a real-valued scalar. Furthermore \(\|z\| = 1\).
- Parameters
- n_dimensionsint
Dimensionality of the identity vector.
- vocabVocabulary, optional
Vocabulary that the Semantic Pointer is considered to be part of. Mutually exclusive with the algebra argument.
- algebraAbstractAlgebra, optional
Algebra used to perform vector symbolic operations on the Semantic Pointer. Defaults to
HrrAlgebra
. Mutually exclusive with the vocab argument.- sidednessElementSidedness, optional
Side in the binding operation on which the element acts as absorbing element.
-
class
nengo_spa.semantic_pointer.
Zero
(n_dimensions, vocab=None, algebra=None, sidedness=<ElementSidedness.TWO_SIDED: 'two-sided'>)[source]¶ Bases:
nengo_spa.semantic_pointer.SemanticPointer
Zero element.
- Parameters
- n_dimensionsint
Dimensionality of the identity vector.
- vocabVocabulary, optional
Vocabulary that the Semantic Pointer is considered to be part of. Mutually exclusive with the algebra argument.
- algebraAbstractAlgebra, optional
Algebra used to perform vector symbolic operations on the Semantic Pointer. Defaults to
HrrAlgebra
. Mutually exclusive with the vocab argument.- sidednessElementSidedness, optional
Side in the binding operation on which the element acts as zero element.