本文整理汇总了C++中Network::addRegion方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::addRegion方法的具体用法?C++ Network::addRegion怎么用?C++ Network::addRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Network
的用法示例。
在下文中一共展示了Network::addRegion方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSecondTimeLeak
void testSecondTimeLeak()
{
Network n;
Network::registerPyRegion("nupic.regions.TestNode", "TestNode");
n.addRegion("r1", "py.TestNode", "");
n.addRegion("r2", "py.TestNode", "");
}
示例2: testYAML
void testYAML()
{
const char *params = "{int32Param: 1234, real64Param: 23.1}";
// badparams contains a non-existent parameter
const char *badparams = "{int32Param: 1234, real64Param: 23.1, badParam: 4}";
Network net = Network();
Region* level1;
SHOULDFAIL(level1 = net.addRegion("level1", "TestNode", badparams););
示例3: x
TEST(InputTest, BasicNetworkConstruction)
{
Network net;
Region * r1 = net.addRegion("r1", "TestNode", "");
Region * r2 = net.addRegion("r2", "TestNode", "");
//Test constructor
Input x(*r1, NTA_BasicType_Int32, true);
Input y(*r2, NTA_BasicType_Byte, false);
EXPECT_THROW(Input i(*r1, (NTA_BasicType)(NTA_BasicType_Last + 1), true),
std::exception);
//test getRegion()
ASSERT_EQ(r1, &(x.getRegion()));
ASSERT_EQ(r2, &(y.getRegion()));
//test isRegionLevel()
ASSERT_TRUE(x.isRegionLevel());
ASSERT_TRUE(! y.isRegionLevel());
//test isInitialized()
ASSERT_TRUE(! x.isInitialized());
ASSERT_TRUE(! y.isInitialized());
//test one case of initialize()
EXPECT_THROW(x.initialize(), std::exception);
EXPECT_THROW(y.initialize(), std::exception);
Dimensions d1;
d1.push_back(8);
d1.push_back(4);
r1->setDimensions(d1);
Dimensions d2;
d2.push_back(4);
d2.push_back(2);
r2->setDimensions(d2);
net.link("r1", "r2", "TestFanIn2", "");
x.initialize();
y.initialize();
//test evaluateLinks()
//should return 0 because x is initialized
ASSERT_EQ(0u, x.evaluateLinks());
//should return 0 because there are no links
ASSERT_EQ(0u, y.evaluateLinks());
//test getData()
const ArrayBase * pa = &(y.getData());
ASSERT_EQ(0u, pa->getCount());
Real64* buf = (Real64*)(pa->getBuffer());
ASSERT_TRUE(buf != nullptr);
}
示例4: testUnregisterRegion
void testUnregisterRegion()
{
Network n;
n.addRegion("test", "py.TestNode", "");
Network::unregisterPyRegion("TestNode");
bool caughtException = false;
try
{
n.addRegion("test", "py.TestNode", "");
} catch (std::exception& e) {
NTA_DEBUG << "Caught exception as expected: '" << e.what() << "'";
caughtException = true;
}
if (caughtException)
{
NTA_DEBUG << "testUnregisterRegion passed";
} else {
NTA_THROW << "testUnregisterRegion did not throw an exception as expected";
}
}
示例5: testExceptionBug
void testExceptionBug()
{
Network n;
Region *l1 = n.addRegion("l1", "py.TestNode", "");
//Dimensions d(1);
Dimensions d(1);
l1->setDimensions(d);
bool caughtException = false;
try
{
n.run(1);
} catch (std::exception& e) {
NTA_DEBUG << "Caught exception as expected: '" << e.what() << "'";
caughtException = true;
}
if (caughtException)
{
NTA_DEBUG << "testExceptionBug passed";
} else {
NTA_THROW << "testExceptionBug did not throw an exception as expected";
}
}
示例6: testPynodeLinking
void testPynodeLinking()
{
Network net = Network();
Region * region1 = net.addRegion("region1", "TestNode", "");
Region * region2 = net.addRegion("region2", "py.TestNode", "");
std::cout << "Linking region 1 to region 2" << std::endl;
net.link("region1", "region2", "TestFanIn2", "");
std::cout << "Setting region1 dims to (6,4)" << std::endl;
Dimensions r1dims;
r1dims.push_back(6);
r1dims.push_back(4);
region1->setDimensions(r1dims);
std::cout << "Initializing network..." << std::endl;
net.initialize();
const Dimensions& r2dims = region2->getDimensions();
NTA_CHECK(r2dims.size() == 2) << " actual dims: " << r2dims.toString();
NTA_CHECK(r2dims[0] == 3) << " actual dims: " << r2dims.toString();
NTA_CHECK(r2dims[1] == 2) << " actual dims: " << r2dims.toString();
ArrayRef r1OutputArray = region1->getOutputData("bottomUpOut");
region1->compute();
std::cout << "Checking region1 output after first iteration..." << std::endl;
Real64 *buffer = (Real64*) r1OutputArray.getBuffer();
for (size_t i = 0; i < r1OutputArray.getCount(); i++)
{
if (verbose)
std::cout << " " << i << " " << buffer[i] << "" << std::endl;
if (i%2 == 0)
NTA_CHECK(buffer[i] == 0);
else
NTA_CHECK(buffer[i] == (i-1)/2);
}
region2->prepareInputs();
ArrayRef r2InputArray = region2->getInputData("bottomUpIn");
std::cout << "Region 2 input after first iteration:" << std::endl;
Real64 *buffer2 = (Real64*) r2InputArray.getBuffer();
NTA_CHECK(buffer != buffer2);
for (size_t i = 0; i < r2InputArray.getCount(); i++)
{
if (verbose)
std::cout << " " << i << " " << buffer2[i] << "" << std::endl;
if (i%2 == 0)
NTA_CHECK(buffer[i] == 0);
else
NTA_CHECK(buffer[i] == (i-1)/2);
}
std::cout << "Region 2 input by node" << std::endl;
std::vector<Real64> r2NodeInput;
for (size_t node = 0; node < 6; node++)
{
region2->getInput("bottomUpIn")->getInputForNode(node, r2NodeInput);
if (verbose)
{
std::cout << "Node " << node << ": ";
for (size_t i = 0; i < r2NodeInput.size(); i++)
{
std::cout << r2NodeInput[i] << " ";
}
std::cout << "" << std::endl;
}
// 4 nodes in r1 fan in to 1 node in r2
int row = node/3;
int col = node - (row * 3);
NTA_CHECK(r2NodeInput.size() == 8);
NTA_CHECK(r2NodeInput[0] == 0);
NTA_CHECK(r2NodeInput[2] == 0);
NTA_CHECK(r2NodeInput[4] == 0);
NTA_CHECK(r2NodeInput[6] == 0);
// these values are specific to the fanin2 link policy
NTA_CHECK(r2NodeInput[1] == row * 12 + col * 2)
<< "row: " << row << " col: " << col << " val: " << r2NodeInput[1];
NTA_CHECK(r2NodeInput[3] == row * 12 + col * 2 + 1)
<< "row: " << row << " col: " << col << " val: " << r2NodeInput[3];
NTA_CHECK(r2NodeInput[5] == row * 12 + 6 + col * 2)
<< "row: " << row << " col: " << col << " val: " << r2NodeInput[5];
NTA_CHECK(r2NodeInput[7] == row * 12 + 6 + col * 2 + 1)
<< "row: " << row << " col: " << col << " val: " << r2NodeInput[7];
}
region2->compute();
}
示例7: w
TEST(WatcherTest, SampleNetwork) {
// NOTE: This test generates files for the subsequent two tests.
// generate sample network [level1] -> [level2] -> [level3]
Network n;
n.addRegion("level1", "TestNode", "{dim: [4,2]}");
n.addRegion("level2", "TestNode", "");
n.addRegion("level3", "TestNode", "");
n.link("level1", "level2");
n.link("level2", "level3");
n.initialize();
// erase any previous contents of testfile
Directory::removeTree("TestOutputDir");
Directory::create("TestOutputDir");
// test creation
Watcher w("TestOutputDir/testfile");
// test uint32Params
unsigned int id1 = w.watchParam("level1", "uint32Param");
ASSERT_EQ(id1, (unsigned int)1);
// test uint64Params
unsigned int id2 = w.watchParam("level1", "uint64Param");
ASSERT_EQ(id2, (unsigned int)2);
// test int32Params
w.watchParam("level1", "int32Param");
// test int64Params
w.watchParam("level1", "int64Param");
// test real32Params
w.watchParam("level1", "real32Param");
// test real64Params
w.watchParam("level1", "real64Param");
// test stringParams
w.watchParam("level1", "stringParam");
// test unclonedParams
w.watchParam("level1", "unclonedParam", 0);
w.watchParam("level1", "unclonedParam", 1);
// test attachToNetwork()
w.attachToNetwork(n);
//test two simultaneous Watchers on the same network with different files
Watcher* w2 = new Watcher("TestOutputDir/testfile2");
// test int64ArrayParam
w2->watchParam("level1", "int64ArrayParam");
// test real32ArrayParam
w2->watchParam("level1", "real32ArrayParam");
// test output
w2->watchOutput("level1", "bottomUpOut");
// test int64ArrayParam, sparse = false
w2->watchParam("level1", "int64ArrayParam", -1, false);
w2->attachToNetwork(n);
// set one of the uncloned parameters to 1 instead of 0
// n.getRegions().getByName("level1")->getNodeAtIndex(1).setParameterUInt32("unclonedParam",(UInt32)1);
//n.run(3);
// see if Watcher notices change in parameter values after 3 iterations
n.getRegions().getByName("level1")->setParameterUInt64("uint64Param", (UInt64)66);
n.run(3);
// test flushFile() - this should produce output
w2->flushFile();
// test closeFile()
w2->closeFile();
// test to make sure data is flushed when Watcher is deleted
delete w2;
// The two generated files are used in next test.
}
示例8: RunTests
void InputTest::RunTests()
{
{
Network net;
Region * r1 = net.addRegion("r1", "TestNode", "");
Region * r2 = net.addRegion("r2", "TestNode", "");
//Test constructor
Input x(*r1, NTA_BasicType_Int32, true);
Input y(*r2, NTA_BasicType_Byte, false);
SHOULDFAIL(Input i(*r1, (NTA_BasicType)(NTA_BasicType_Last + 1), true));
//test getRegion()
TESTEQUAL(r1, &(x.getRegion()));
TESTEQUAL(r2, &(y.getRegion()));
//test isRegionLevel()
TEST(x.isRegionLevel());
TEST(! y.isRegionLevel());
//test isInitialized()
TEST(! x.isInitialized());
TEST(! y.isInitialized());
//test one case of initialize()
SHOULDFAIL(x.initialize());
SHOULDFAIL(y.initialize());
Dimensions d1;
d1.push_back(8);
d1.push_back(4);
r1->setDimensions(d1);
Dimensions d2;
d2.push_back(4);
d2.push_back(2);
r2->setDimensions(d2);
net.link("r1", "r2", "TestFanIn2", "");
x.initialize();
y.initialize();
//test evaluateLinks()
//should return 0 because x is initialized
TESTEQUAL(0u, x.evaluateLinks());
//should return 0 because there are no links
TESTEQUAL(0u, y.evaluateLinks());
//test getData()
const ArrayBase * pa = &(y.getData());
TESTEQUAL(0u, pa->getCount());
Real64* buf = (Real64*)(pa->getBuffer());
TEST(buf != nullptr);
}
{
Network net;
Region * region1 = net.addRegion("region1", "TestNode", "");
Region * region2 = net.addRegion("region2", "TestNode", "");
Dimensions d1;
d1.push_back(8);
d1.push_back(4);
region1->setDimensions(d1);
net.link("region1", "region2", "TestFanIn2", "");
//test initialize(), which is called by net.initialize()
//also test evaluateLinks() which is called here
net.initialize();
net.run(1);
//test that region has correct induced dimensions
Dimensions d2 = region2->getDimensions();
TESTEQUAL(2u, d2.size());
TESTEQUAL(4u, d2[0]);
TESTEQUAL(2u, d2[1]);
//test getName() and setName()
Input * in1 = region1->getInput("bottomUpIn");
Input * in2 = region2->getInput("bottomUpIn");
TESTEQUAL("bottomUpIn", in1->getName());
TESTEQUAL("bottomUpIn", in2->getName());
in1->setName("uselessName");
TESTEQUAL("uselessName", in1->getName());
in1->setName("bottomUpIn");
//test isInitialized()
TEST(in1->isInitialized());
TEST(in2->isInitialized());
//test getLinks()
std::vector<Link*> links = in2->getLinks();
TESTEQUAL(1u, links.size());
for(auto & link : links) {
//do something to make sure l[i] is a valid Link*
TEST(link != nullptr);
//should fail because regions are initialized
SHOULDFAIL(in2->removeLink(link));
}
//.........这里部分代码省略.........
示例9: main
int main(int argc, const char * argv[])
{
// Create network
Network net = Network();
// Add VectorFileSensor region to network
Region* region = net.addRegion("region", "VectorFileSensor", "{activeOutputCount: 1}");
// Set region dimensions
Dimensions dims;
dims.push_back(1);
std::cout << "Setting region dimensions" << dims.toString() << std::endl;
region->setDimensions(dims);
// Load data
std::string path = Path::makeAbsolute("../../src/examples/regions/Data.csv");
std::cout << "Loading data from " << path << std::endl;
std::vector<std::string> loadFileArgs;
loadFileArgs.push_back("loadFile");
loadFileArgs.push_back(path);
loadFileArgs.push_back("2");
region->executeCommand(loadFileArgs);
// Initialize network
std::cout << "Initializing network" << std::endl;
net.initialize();
ArrayRef outputArray = region->getOutputData("dataOut");
// Compute
std::cout << "Compute" << std::endl;
region->compute();
// Get output
Real64 *buffer = (Real64*) outputArray.getBuffer();
for (size_t i = 0; i < outputArray.getCount(); i++)
{
std::cout << " " << i << " " << buffer[i] << "" << std::endl;
}
// Serialize
Network net2;
{
std::stringstream ss;
net.write(ss);
net2.read(ss);
}
net2.initialize();
Region* region2 = net2.getRegions().getByName("region");
region2->executeCommand(loadFileArgs);
ArrayRef outputArray2 = region2->getOutputData("dataOut");
Real64 *buffer2 = (Real64*)outputArray2.getBuffer();
net.run(1);
net2.run(1);
NTA_ASSERT(outputArray2.getCount() == outputArray.getCount());
for (size_t i = 0; i < outputArray.getCount(); i++)
{
std::cout << " " << i << " " << buffer[i] << " " << buffer2[i]
<< std::endl;
}
return 0;
}
示例10: realmain
int realmain(bool leakTest)
{
// verbose == true turns on extra output that is useful for
// debugging the test (e.g. when the TestNode compute()
// algorithm changes)
std::cout << "Creating network..." << std::endl;
Network n;
std::cout << "Region count is " << n.getRegions().getCount() << "" << std::endl;
std::cout << "Adding a PyNode region..." << std::endl;
Network::registerPyRegion("nupic.regions.TestNode", "TestNode");
Region* level2 = n.addRegion("level2", "py.TestNode", "{int32Param: 444}");
std::cout << "Region count is " << n.getRegions().getCount() << "" << std::endl;
std::cout << "Node type: " << level2->getType() << "" << std::endl;
std::cout << "Nodespec is:\n" << level2->getSpec()->toString() << "" << std::endl;
Real64 rval;
std::string int64Param("int64Param");
std::string real64Param("real64Param");
// get the value of intArrayParam after the setParameter call.
// --- Test getParameterReal64 of a PyNode
rval = level2->getParameterReal64("real64Param");
NTA_CHECK(rval == 64.1);
std::cout << "level2 getParameterReal64() returned: " << rval << std::endl;
// --- Test setParameterReal64 of a PyNode
level2->setParameterReal64("real64Param", 77.7);
rval = level2->getParameterReal64("real64Param");
NTA_CHECK(rval == 77.7);
// should fail because network has not been initialized
SHOULDFAIL(n.run(1));
// should fail because network can't be initialized
SHOULDFAIL (n.initialize() );
std::cout << "Setting dimensions of level1..." << std::endl;
Dimensions d;
d.push_back(4);
d.push_back(4);
std::cout << "Setting dimensions of level2..." << std::endl;
level2->setDimensions(d);
std::cout << "Initializing again..." << std::endl;
n.initialize();
testExceptionBug();
testPynodeInputOutputAccess(level2);
testPynodeArrayParameters(level2);
testPynodeLinking();
if (!leakTest)
{
//testNuPIC1x();
//testPynode1xLinking();
}
std::cout << "Done -- all tests passed" << std::endl;
return 0;
}
示例11: testSecondTimeLeak
void testSecondTimeLeak()
{
Network n;
n.addRegion("r1", "py.TestNode", "");
n.addRegion("r2", "py.TestNode", "");
}
示例12:
TEST(InputTest, Links)
{
Network net;
Region * region1 = net.addRegion("region1", "TestNode", "");
Region * region2 = net.addRegion("region2", "TestNode", "");
Dimensions d1;
d1.push_back(8);
d1.push_back(4);
region1->setDimensions(d1);
net.link("region1", "region2", "TestFanIn2", "");
//test initialize(), which is called by net.initialize()
//also test evaluateLinks() which is called here
net.initialize();
net.run(1);
//test that region has correct induced dimensions
Dimensions d2 = region2->getDimensions();
ASSERT_EQ(2u, d2.size());
ASSERT_EQ(4u, d2[0]);
ASSERT_EQ(2u, d2[1]);
//test getName() and setName()
Input * in1 = region1->getInput("bottomUpIn");
Input * in2 = region2->getInput("bottomUpIn");
EXPECT_STREQ("bottomUpIn", in1->getName().c_str());
EXPECT_STREQ("bottomUpIn", in2->getName().c_str());
in1->setName("uselessName");
EXPECT_STREQ("uselessName", in1->getName().c_str());
in1->setName("bottomUpIn");
//test isInitialized()
ASSERT_TRUE(in1->isInitialized());
ASSERT_TRUE(in2->isInitialized());
//test getLinks()
std::vector<Link*> links = in2->getLinks();
ASSERT_EQ(1u, links.size());
for(auto & link : links) {
//do something to make sure l[i] is a valid Link*
ASSERT_TRUE(link != nullptr);
//should fail because regions are initialized
EXPECT_THROW(in2->removeLink(link), std::exception);
}
//test findLink()
Link * l1 = in1->findLink("region1", "bottomUpOut");
ASSERT_TRUE(l1 == nullptr);
Link * l2 = in2->findLink("region1", "bottomUpOut");
ASSERT_TRUE(l2 != nullptr);
//test removeLink(), uninitialize()
//uninitialize() is called internally from removeLink()
{
//can't remove link b/c region1 initialized
EXPECT_THROW(in2->removeLink(l2), std::exception);
//can't remove region b/c region1 has links
EXPECT_THROW(net.removeRegion("region1"), std::exception);
region1->uninitialize();
region2->uninitialize();
EXPECT_THROW(in1->removeLink(l2), std::exception);
in2->removeLink(l2);
EXPECT_THROW(in2->removeLink(l2), std::exception);
//l1 == NULL
EXPECT_THROW(in1->removeLink(l1), std::exception);
}
}
示例13: o
TEST(WatcherTest, SampleNetwork)
{
//generate sample network
Network n;
n.addRegion("level1", "TestNode", "");
n.addRegion("level2", "TestNode", "");
n.addRegion("level3", "TestNode", "");
Dimensions d;
d.push_back(8);
d.push_back(4);
n.getRegions().getByName("level1")->setDimensions(d);
n.link("level1", "level2", "TestFanIn2", "");
n.link("level2", "level3", "TestFanIn2", "");
n.initialize();
//erase any previous contents of testfile
OFStream o("testfile");
o.close();
//test creation
Watcher w("testfile");
//test uint32Params
unsigned int id1 = w.watchParam("level1", "uint32Param");
ASSERT_EQ(id1, (unsigned int)1);
//test uint64Params
unsigned int id2 = w.watchParam("level1", "uint64Param");
ASSERT_EQ(id2, (unsigned int)2);
//test int32Params
w.watchParam("level1", "int32Param");
//test int64Params
w.watchParam("level1", "int64Param");
//test real32Params
w.watchParam("level1", "real32Param");
//test real64Params
w.watchParam("level1", "real64Param");
//test stringParams
w.watchParam("level1", "stringParam");
//test unclonedParams
w.watchParam("level1", "unclonedParam", 0);
w.watchParam("level1", "unclonedParam", 1);
//test attachToNetwork()
w.attachToNetwork(n);
//test two simultaneous Watchers on the same network with different files
Watcher* w2 = new Watcher("testfile2");
//test int64ArrayParam
w2->watchParam("level1", "int64ArrayParam");
//test real32ArrayParam
w2->watchParam("level1", "real32ArrayParam");
//test output
w2->watchOutput("level1", "bottomUpOut");
//test int64ArrayParam, sparse = false
w2->watchParam("level1", "int64ArrayParam", -1, false);
w2->attachToNetwork(n);
//set one of the uncloned parameters to 1 instead of 0
//n.getRegions().getByName("level1")->getNodeAtIndex(1).setParameterUInt32("unclonedParam", (UInt32)1);
//n.run(3);
//see if Watcher notices change in parameter values after 3 iterations
n.getRegions().getByName("level1")->setParameterUInt64("uint64Param", (UInt64)66);
n.run(3);
//test flushFile() - this should produce output
w.flushFile();
//test closeFile()
w.closeFile();
//test to make sure data is flushed when Watcher is deleted
delete w2;
}