-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for different binding operations #198
Conversation
a82d6b0
to
1756bb1
Compare
Vocabulary that the Semantic Pointer is considered to be part of. | ||
Mutually exclusive with the *algebra* argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why different formatting for algebra
and vocab
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
type_ = infer_types(self, other) | ||
vocab = None if type_ == TAnyVocab else type_.vocab | ||
return SemanticPointer(data=self.v - other.evaluate().v, vocab=vocab) | ||
return self + (-other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does __add__
need type checking, while __sub__
doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because sub re-expresses a - b
as a + (-b)
thus using the implementation of __add__
and __neg__
which already do type checking.
docs/user_guide/spa_intro.rst
Outdated
@@ -180,4 +180,4 @@ All of the control-like steps (e.g. “compared with”, “inferred”, and rou | |||
information through the system), are implemented by a biologically plausible | |||
basal ganglia model. This is one example of the 8 different tasks that Spaun is | |||
able to perform. Videos for all tasks can be found `here | |||
<http://nengo.ca/build-a-brain/spaunvideos/>`_. | |||
<http://www.nengo.ca/build-a-brain/spaunvideos/>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be changed to https://xchoo.github.io/spaun2.0/videos.html
which it redirects to anyways. If I leave tiny nit-picks like this in my review, you can safely assume I'll change them myself once I've reviewed the other files.
nengo_spa/algebras/vtb.py
Outdated
@@ -58,10 +58,22 @@ def invert(cls, v): | |||
return v.reshape((sub_d, sub_d)).T.flatten() | |||
|
|||
@classmethod | |||
def get_binding_matrix(cls, v): | |||
def get_binding_matrix(cls, v, swap_inputs=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the point of swapping inputs as a function argument. Naively, it seems to me that the inputs should just be swapped in the connections and not as a parameter, if the user wants that. Would you mind explaining to me the intent of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using a binding matrix one vector is fixed (the one the matrix) is based on and one varies over time. Thus, there is no way to swap the inputs because there is only on time varying input.
I've read through the code once, but I'd like to read it again. It's pretty remarkable how you managed to abstract such a fundamental part of SPA. |
nengo_spa/algebras/base.py
Outdated
|
||
Parameters | ||
---------- | ||
v : n(d,) darray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is n
here?
Made some formatting fixes and added a test to make sure the unitary vector doesn't change the length of what it's binded with. This PR LGTM. |
Copied from nengo-extras.
Also fix VTB unbinding implementation.
The CircularConvolutionAlgebra essentially implements the same functionality.
@Seanny123, can you “officially” approve this PR? |
Motivation and context:
This adds the possibility to change the binding (and superposition) operation used by Nengo SPA. It also implements vector-derived transformation binding (VTB) as one alternate binding method.
The specific choice of a superpositiion operation and a binding operation is called an algebra in this PR (as it roughly fits the mathematical definition of an algebra or algebraic structure). Such in algebra is implemented by a class providing pure math implementations of the operations, methods to obtain special elements like the identity, and two methods to provide neural implementations of the two operators.
Each vocabulary (and
SemanticPointer
which might not have a vocabulary) is assigned such an algbra determining the operations used when operands get combined in the SPA syntax (it defaults toCircularConvolutionAlgebra
). Because operands are required to have the same vocabulary, it is always clear what algebra to use, i.e., there is no situation in which the operands might have different algebras (except forSemanticPointer
which raises an exception in this case).Currently there is not way to change the default algebra, but one has to explicitely create a vocabulary with the desired algbra. Not sure whether there should be a way to set this default ...
Closes #69.
Interactions with other PRs:
none
How has this been tested?
Tests have been added, updated, etc.
An
algebra
fixture has been added that will parametrize a test to run with both implemented algebras.How long should this take to review?
Where should a reviewer start?
The commits should be self-contained, so that one could go commit by commit. But I revised some things multiple times and the back and forth might not be that helpful. Such it might be better to look at the final diff. There are multiple parts that stand mostly on its own:
nengo_spa/networks/matrix_multiplication.py
.nengo_spa/modules/superposition.py
.nengo_spa/algebras/base.py
.nengo_spa/algebras/cconv.py
. (Probably best to look at this one first as it uses familiar operations.)nengo_spa/algebras/vtb.py
with the binding networknengo_spa/networks/vtb.py
.nengo_spa/vocab.py
andnengo_spa/pointer.py
and some other files to enable the use of algebras.Types of changes:
Checklist:
Still to do: