Skip to content

Commit

Permalink
Allow SPA connection to utility nodes.
Browse files Browse the repository at this point in the history
Closes #190.

This does not allow connections to the basal ganglia input node in this
style because this would require to allow SPA style connections to sliced
inputs which is currently not implemented.
  • Loading branch information
jgosmann committed Jul 10, 2018
1 parent 73e10d8 commit ddb6710
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Release History
0.6.0 (unreleased)
==================

**Added**

- Allow to connect to the utility node returned by `ifmax` with the SPA `>>`
operator.
(`#190 <https://github.com/nengo/nengo_spa/issues/190>`_,
`#194 <https://github.com/nengo/nengo_spa/pull/194>`_)

**Changed**

- Require the ``mapping`` argument for associative memories. In addition to
Expand Down
6 changes: 4 additions & 2 deletions nengo_spa/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from nengo.utils.compat import is_string

from nengo_spa.ast import dynamic
from nengo_spa.connectors import ModuleInput, RoutedConnection
from nengo_spa.connectors import (
input_vocab_registry, ModuleInput, RoutedConnection)
from nengo_spa.exceptions import SpaActionSelectionError, SpaTypeError
from nengo_spa.types import TScalar

Expand Down Expand Up @@ -147,7 +148,8 @@ def __len__(self):

def add_action(self, name, *actions):
assert ActionSelection.active is self
utility = nengo.Node(size_in=1)
utility = input_vocab_registry.declare_connector(
nengo.Node(size_in=1), None)
if name is not None:
self._name2idx[name] = len(self._actions)
self._utilities.append(utility)
Expand Down
3 changes: 2 additions & 1 deletion nengo_spa/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def ifmax(name, condition=None, *actions):
-------
NengoObject
Nengo object that can be connected to, to provide additional input to
the utility value.
the utility value. It is possible (but not necessary) to use SPA style
connections of the form ``scalar >> utility`` to this object.
"""
if not is_string(name):
if condition is not None:
Expand Down
7 changes: 7 additions & 0 deletions nengo_spa/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ def test_action_selection(Simulator, rng):
sim.trange(), sim.data[p_pointer], vocab['E'], skip=2.3, duration=0.2)


def test_spa_connections_to_utilities():
with spa.Network():
with ActionSelection():
utility = spa.ifmax(0.)
0.1 >> utility


def test_does_not_allow_nesting_of_action_selection():
with spa.Network():
with ActionSelection():
Expand Down

0 comments on commit ddb6710

Please sign in to comment.