Using region/network in nupic.core?



Vitaly, if so, how can a region know which c++ class inherited RegionImpl should be used/initilized/called? mySensorRegion or other else?

#22, I am waiting for Marcus to chime in


There is a registration mechanism for this. Here is an example:


I forgot a VIP for this topic - @scott, who certainly know the answer!
Could you help me, Scott?


Hi Vitaly
Thank you very much for your example, which is very clear to understand! Perfect, thanks again


Here are more comprehensive region examples:


Exact what i am looking for! Thank you so much!


In python version, i find that you usually implement a region for each TM, SP and sensor like SPRegion, TMRegion or RawSendorRegion and use network() to build them in hierarchy of networks.
Should we borrow this idea for implementing them in c++? or do you have new concept?

If so, i want to test it in c++. Firstly, i implement a sensorRegion, whose input is a scalar and use an encoder to encode input into sdr as output of this region.
Do you think it makes sense?


@vkruglikov @mrcslws what is the syntax for passing node parameters of the region by using the 3rd string input of c++ addRegion()? Like
{x: 1, y: 20.0}, where my region has

Int          x;
Real32 y;


#30, please grep the nupic.core repo sources for “addRegion”. You will quickly see a couple of examples of using the 3rd parameter, like this one:


Thanks @vkruglikov.
Should i use “,” sign for inputing many parameters separately?


In the L2 region, we usually have some lateral inputs from other columns.
Could you please recommend me how to declare Input variable in a region? Like
Input * lateralInputs;
Std:vector<Input *> lateralInputs;





I am using only C++ for network and regions etc. with nupic.core.

  class BundleIO;

  class RegionBase: public RegionImpl
    RegionBase(const ValueMap& params, Region *region) :

    RegionBase(BundleIO& bundle, Region* region) :

    virtual ~RegionBase()

    void compute() override;

    void initialize() override;
    void serialize(BundleIO& bundle) override

    void deserialize(BundleIO& bundle) override

    std::string executeCommand(const std::vector<std::string>& args, Int64 index) override
      return "";

    size_t getNodeOutputElementCount(const std::string& outputName) override


but really do not understand why it needs a link to Python and PyRegion.

/tmp/cc7Xx724.ltrans4.ltrans.o: In function `nupic::PyRegion::setParameterByte(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long, char)':
<artificial>:(.text+0x9f): undefined reference to `PyInt_FromLong'
/tmp/cc7Xx724.ltrans4.ltrans.o: In function `nupic::PyRegion::getParameterBool(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long)':
<artificial>:(.text+0x30e): undefined reference to `PyBool_Type'
<artificial>:(.text+0x34c): undefined reference to `_Py_TrueStruct'
<artificial>:(.text+0x355): undefined reference to `_Py_ZeroStruct'
/tmp/cc7Xx724.ltrans4.ltrans.o: In function `nupic::PyRegion::getParameterUInt32(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long)':
<artificial>:(.text+0x1208): undefined reference to `PyInt_AsLong'
/tmp/cc7Xx724.ltrans4.ltrans.o: In function `nupic::PyRegion::write(capnp::AnyPointer::Builder&) const':
<artificial>:(.text+0x1b07): undefined reference to `PyString_AsStringAndSize'
/tmp/cc7Xx724.ltrans4.ltrans.o: In function `nupic::PyRegion::serialize(nupic::BundleIO&)':
<artificial>:(.text+0x2877): undefined reference to `PyInt_FromLong'
/tmp/cc7Xx724.ltrans5.ltrans.o: In function `nupic::py::Ptr::assign(_object*)':
<artificial>:(.text+0x9da): undefined reference to `PyObject_Type'
<artificial>:(.text+0x9e5): undefined reference to `PyObject_Type'
/tmp/cc7Xx724.ltrans5.ltrans.o: In function `nupic::PyRegion::getNodeOutputElementCount(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':

Do you have any idea, why Python lib are needed here?


I am wondering, why many python types like PyInt** for example are not refrenced by PyRegion?

Which libraries have i to use for solving this linking problems?
Thanks for your comments and help.


After learning by reading c++ codes, now i uderstand much better the region/network concept and can solve those problems myself.


I am wondering why we can not input any data from the main() into a region, here as an sample I use a region named “MyNode”, with

				"Float input data",
				1, 			// count. omit?
				true, 		// required?
				false, 		// isRegionLevel,
				true  		// isDefaultInput

The input array has always the size of 0, so that I have no chance to assign its value!

int main()
    Network net1 = Network();
    Region* region1 = net1.addRegion("region1", "myNode", "");
    Dimensions r1dims;
    ArrayRef rInputArray = region1->getInputData("dataIn");
    std::cout << "num counts before: " << rInputArray.getCount() << std::endl;
    std::cout << "num counts after: " << rInputArray.getCount() << std::endl;

    double myData = 1.234;
    Real64 *bufferL4 = (Real64*) rInputArray.getBuffer();
    bufferL4[0] = myData;

@scott @vkruglikov Can you help me? Thanks


I believe it is a bug where all config data in Spec() are not read correctly by initilze() phase!


Do you have a link connected to the region?


I have tested this region without any link and with a link to another region via its output. I have the same problem in both cases too