I am trying to create a new kind of region called an AccumulatorRegion. This is a very simple and widely applicable region which:
- takes a sequence of inputs each of which is a sparse list of cells arranged into mini-columns (e.g. the output of a TM)
- as each input is presented using the AccmulatorRegion’s “compute()” method, this increments a counter on each column which then holds the number of times times this column has appeared in the inputs
- at any time the regions “getWinnerColumns()” method can be called which returns a sparse list of column indices whose accumulated count is above (or equal to) a threshold. This threshold is determined dynamically by taking the current highest count across all the columns and multiplying this by a configuration parameter called “winnerPercentThreshold” (which is an integer 0-100, so we then divide the result by 100). (It is intended this threshold would normally be set fairly high.) This returns the “most popular” columns.
I have created and tested an implementation of the algorithm that does this, which works fine (it is very simple).
I am now trying to make this work using the Network API. I have created the code for an AccumulatorRegion following the example of existing nupic regions. Where I am stuck is getting the Network API to load the implementation of my new region. I have tried “registering” the new region as per the code below but this does not seem to work:
from nupic.engine import Network import yaml import json # A network that will hold the regions. network = Network() # register my implementation (module accumulator.py and class Accumulator) of my new Region: AccumulatorRegion module = __import__("accumulator") accRegionClass = getattr(module, "Accumulator") network.registerRegion(accRegionClass) _PARAMS_PATH = "accModel.yaml" # this model includes: ''' accParams: regionName: AccumulatorRegion implementation: accumulator ''' with open(_PARAMS_PATH, "r") as f: modelParams = yaml.safe_load(f)["modelParams"] accParams=modelParams["accParams"] network.addRegion("ACC", "py.AccumulatorRegion", json.dumps(accParams)) tmParams = modelParams["tmParams"] network.addRegion("TM", "py.TMRegion", json.dumps(tmParams))
The error message I get from this is:
ERR: Matching Python module for AccumulatorRegion not found. [/root/bamboo-agent-home/xml-data/build-dir/NUP-CORE-NCRM/src/nupic/engine/RegionImplFactory.cpp line 377] Traceback (most recent call last): File "testAccRegion.py", line 24, in <module> network.addRegion("ACC", "py.AccumulatorRegion", json.dumps(accParams)) File "/usr/local/lib/python2.7/site-packages/nupic/engine/__init__.py", line 645, in addRegion engine_internal.Network.addRegion(self, name, nodeType, nodeParams) File "/usr/local/lib/python2.7/site-packages/nupic/bindings/engine_internal.py", line 1218, in addRegion return _engine_internal.Network_addRegion(self, *args, **kwargs) RuntimeError: Matching Python module for AccumulatorRegion not found.
What is the correct way to add a new kind of region?
If I manage to get it all working I would be happy to share the code. Is there somewhere in particular that I should put it?