Using region/network in nupic.core?



I want to add SpatialPooler, encoders or tm into a region of a network in c++, but really do not find any sample for it. Could anyone show me?thanks


Up to now I found only very nice documentation and samples for using them with Python.
In C++, I can do
Network* net = new Network();
SpatialPooler sp; // as pseudo-code
string name = “my_sp_region”;
string nodeType = “SP”; // do not know if there is a specific name???
Region* spR = net->adRegion(name, nodeType, “”);

But I really do not know how to put/link/connect SpatialPooler into this Region?
One thing I can do is to use static_cast like
spR = static_cast< nupic::Region* >(sp);

, but really do not know if it is correct. Please help!


We don’t have good examples or docs in C++. It’s something I’ve wanted to work on, but frankly will probably not have time.


Thanks for quick response!
Do you have any idea or pseudo-code for implementing it so that we can develop this interface soon?


I am totally unfamiliar with the C++ codebase, sorry. :slight_frown:


Who from Numenta does know better from the whole concept? @subutai?


Maybe @mrcslws, @scott, @vkruglikov, or @Austin_Marshall?


Thanks. I am waiting for feedback of other Numenta guys…,


There is an example script for some of the algorithms here:

And a separate example for how to use the network api, which you can use to link the algorithms together:

I’m not sure if we have anything more complete at the moment.


@scott thanks for your links. Unfortunately, the Hello_SP_TP.cpp does NOT use network and region, the HelloRegion.cpp is very very elementary in comparison to python examples.
Do you have any idea to bring network/region C++ fully functionable like pyRegion?
I need to understand how SP/TM/encoder/AD etc. can be assigned/copied/converted in the Python version.
Where in RegionImpl or RegionFactory is common space/interface for saving data of different nodes?


In the meantime i took a look at the current ETM with basal and apical connections and sometkme i am not sure if the network and region are really needed in the future because encoder and SP are used in the lowest region. higher levels are connected together over TM via basal and apical connections. Please correct me if i am wrong here!


@mrcslws @vkruglikov any comment and hint from you? Thanks


I am using an example “HelloRegions.cpp”, which uses VectorFileSensor as input region. This sensor opens a file and read data out.
My question:
how to implement a sensor for region like RawSensor, so that I can input a scalar to it and let it process data and put something (sparse data) at the output? It should look like an integration of any encoder into a region.



I think my last question is very complex, so that I did not get any feedback from you.
Now I try to ask @mrcslws and @vkruglikov for you help by better understanding how Region in C++ functions .
In HelloRegions.cpp we insert a new region using:

 Region* region = net.addRegion("region", "VectorFileSensor", "{activeOutputCount: 1}");

Could you please inform me,

  1. if the 2nd input argument of “addRegion”, here the string “VectorFileSensor” is optional (i.e. can it be an empty “”?) or it is strongly related to a class “VectorFileSensor”, implemented in the file “VectorFileSensor.cpp”?? My feeling: it is exactly the name of a class, which implements a region, but not sure???
  2. What is the mandatory virtual functions should be implemented in a new implemented application region like mySensorRegion()?
class mySensorRegion : public RegionImpl
    void initialize() override;

    mySensorRegion(const ValueMap & params, Region *region);

    mySensorRegion(BundleIO& bundle, Region* region);

    mySensorRegion(capnp::AnyPointer::Reader& proto, Region* region);

    virtual ~mySensorRegion();
    virtual void serialize(BundleIO& bundle) override;
    virtual void deserialize(BundleIO& bundle) override;
    void compute() override;

    NTA_UInt32 iterations_;        // Number of times compute() has been called
    ArrayRef dataOut_;
    ArrayRef categoryOut_;
    ArrayRef resetOut_;    

Thank you very much for help!


I’m sorry I’m not much help here. I don’t know C++ and have focused all my efforts on the NuPIC Python interface.


I think @mrcslws and @vkruglikov know it and can help me


It’s strongly related to a class. The API does NOT define it as optional.

Deferring to someone else for mandatory virtual function overrides.



@vkruglikov must the 2nd be identical to class name or the file name? Thanks


Hi Vitaly,
which constructor in mySensorRegion should be mandatory?
Is installize() function called automatically at addRegion()?
By running
Which function of region does update / get the input data into this region? compute()?
Which function for update output?


nodeType doesn’t have to be identical to either, AFAIK