# Using region/network in nupic.core?

**URL:** <https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363>\
**Category:** NuPIC\
**Tags:** cpp\
**Created:** [May 30, 2017, 10:10am UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363 "2017-05-30T10:10:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [May 30, 2017, 10:10am UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/1 "2017-05-30T10:10:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [May 30, 2017, 1:17pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/2 "2017-05-30T13:17:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 30, 2017, 3:37pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/3 "2017-05-30T15:37:03Z")

</div>

> [@thanh-binh.to](#):
>
> Up to now I found only very nice documentation and samples for using them with Python.

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.

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [May 30, 2017, 4:03pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/4 "2017-05-30T16:03:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 30, 2017, 4:05pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/5 "2017-05-30T16:05:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [May 30, 2017, 4:10pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/6 "2017-05-30T16:10:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 30, 2017, 4:11pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/7 "2017-05-30T16:11:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [May 30, 2017, 4:24pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/8 "2017-05-30T16:24:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scott](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/scott/32/170_2.png) [@scott](https://discourse.numenta.org/u/scott)\
**Post date:** [May 30, 2017, 4:59pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/9 "2017-05-30T16:59:50Z")

</div>

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

> <https://github.com/numenta/nupic.core/blob/4748c9d80d1d7dbe76748ab62569767c4cf69837/src/examples/algorithms/HelloSP_TP.cpp>

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

> <https://github.com/numenta/nupic.core/blob/4748c9d80d1d7dbe76748ab62569767c4cf69837/src/examples/regions/HelloRegions.cpp>

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

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [May 30, 2017, 7:34pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/10 "2017-05-30T19:34:03Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [June 2, 2017, 8:08pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/11 "2017-06-02T20:08:31Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [June 9, 2017, 7:49pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/12 "2017-06-09T19:49:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [July 24, 2017, 3:23pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/13 "2017-07-24T15:23:20Z")

</div>

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.

thanks

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [July 25, 2017, 3:00pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/14 "2017-07-25T15:00:16Z")

</div>

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:

```auto
 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()?

```auto
class mySensorRegion : public RegionImpl
{
  public:
    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;

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

```

Thank you very much for help!

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [July 25, 2017, 3:44pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/15 "2017-07-25T15:44:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [July 25, 2017, 4:41pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/16 "2017-07-25T16:41:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vkruglikov](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/vkruglikov/32/474_2.png) [@vkruglikov](https://discourse.numenta.org/u/vkruglikov)\
**Post date:** [July 25, 2017, 5:22pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/17 "2017-07-25T17:22:39Z")

</div>

> [@thanh-binh.to](#):
>
> 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???

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

Deferring to someone else for mandatory virtual function overrides.

Best,  
Vitaly

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [July 25, 2017, 5:57pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/18 "2017-07-25T17:57:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thanh-binh.to](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/thanh-binh.to/32/1793_2.png) [@thanh-binh.to](https://discourse.numenta.org/u/thanh-binh.to)\
**Post date:** [July 25, 2017, 6:10pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/19 "2017-07-25T18:10:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vkruglikov](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/vkruglikov/32/474_2.png) [@vkruglikov](https://discourse.numenta.org/u/vkruglikov)\
**Post date:** [July 25, 2017, 6:10pm UTC](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363/20 "2017-07-25T18:10:31Z")

</div>

> [@thanh-binh.to](#):
>
> @vkruglikov must the 2nd be identical to class name or the file name? Thanks

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

[Next page](https://discourse.numenta.org/t/using-region-network-in-nupic-core/2363.md?page=2)
