Using region/network in nupic.core?

cpp

#21

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


#22

@thanh-binh.to, I am waiting for Marcus to chime in


#23

There is a registration mechanism for this. Here is an example: https://github.com/numenta/nupic.core/blob/master/src/test/unit/engine/LinkTest.cpp#L121-L148


#24

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


#25

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


#26

Here are more comprehensive region examples: https://github.com/numenta/nupic.core/blob/master/src/test/unit/engine/LinkTest.cpp#L417-L783


#27

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


#28

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?


#29

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

Thanks


#30

@thanh-binh.to, 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: https://github.com/numenta/nupic.core/blob/d3fdfde9d0029b14a5fe0abacd5a1cdb5b145e3a/src/examples/regions/HelloRegions.cpp#L43


#31

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


#32

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;
or
Std:vector<Input *> lateralInputs;

Thanks


#33

It’s JSON


#34

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

  class BundleIO;

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

    RegionBase(BundleIO& bundle, Region* region) :
      RegionImpl(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
    {
    }

  private:
    RegionBase();
  };

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


#35

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.


#36

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


#37

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

	    ns->inputs.add(
			"dataIn",
			InputSpec(
				"Float input data",
				NTA_BasicType_Real32,
				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;
    r1dims.push_back(1);
    region1->setDimensions(r1dims);
    net1.initialize();
    ArrayRef rInputArray = region1->getInputData("dataIn");
    std::cout << "num counts before: " << rInputArray.getCount() << std::endl;
    region1->compute();
    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


#38

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


#39

Do you have a link connected to the region?


#40

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