Example #1
0
void
testNonContigousNeuronIndices(backend_t backend, unsigned n0, unsigned nstep)
{
	unsigned ncount = 1000;
	bool stdp = false;

	boost::scoped_ptr<nemo::Network> net0(createRing(ncount, 0, false, nstep));
	boost::scoped_ptr<nemo::Network> net1(createRing(ncount, n0, false, nstep));

	std::vector<unsigned> cycles0, cycles1;
	std::vector<unsigned> fired0, fired1;

	unsigned seconds = 2;
	nemo::Configuration conf = configuration(false, 1024, backend);

	runSimulation(net0.get(), conf, seconds, &cycles0, &fired0, stdp, std::vector<unsigned>(1, 0));
	runSimulation(net1.get(), conf, seconds, &cycles1, &fired1, stdp, std::vector<unsigned>(1, n0));

	/* The results should be the same, except firing indices
	 * should have the same offset. */
	BOOST_REQUIRE_EQUAL(cycles0.size(), cycles1.size());
	BOOST_REQUIRE_EQUAL(fired0.size(), seconds*ncount);
	BOOST_REQUIRE_EQUAL(fired1.size(), seconds*ncount);

	for(unsigned i = 0; i < cycles0.size(); ++i) {
		BOOST_REQUIRE_EQUAL(cycles0.at(i), cycles1.at(i));
		BOOST_REQUIRE_EQUAL(fired0.at(i), fired1.at(i) - n0);
	}

	//! \todo also add ring networks with different steps.
}
Example #2
0
void
testGetSynapses(backend_t backend, bool stdp)
{
	nemo::Configuration conf = configuration(stdp, 1024, backend);

	unsigned m = 1000;
	boost::scoped_ptr<nemo::Network> net1(nemo::torus::construct(4, m, stdp, 32, false));
	testGetSynapses(*net1, conf, 0, m);

	unsigned n0 = 1000000U;
	boost::scoped_ptr<nemo::Network> net2(createRing(1500, n0));
	testGetSynapses(*net2, conf, n0, 1);
}
void testMultipleNetwork() {
	log("******************************************");
	log("TESTING MultipleNetwork");
	log("REQUIRES Network class to have been tested");

	log("Creating an empty multiple network...",false);
	MultipleNetwork mnet;
	log("done!");

	log("Adding seven global vertexes with different methods...",false);
	global_vertex_id gv0 = mnet.addVertex();
	global_vertex_id gv1 = mnet.addVertex();
	global_vertex_id gv2 = mnet.addVertex();
	global_vertex_id gv3 = mnet.addVertex();
	mnet.addVertexes(3);
	if (mnet.getNumVertexes()!=7) throw FailedUnitTestException("Wrong number of global vertexes");
	log("done!");

	log("Creating and adding three anonymous undirected and directed networks...",false);
	// Network 1
	Network net1(false,false,false);
	vertex_id n1v0 = net1.addVertex();
	vertex_id n1v1 = net1.addVertex();
	vertex_id n1v2 = net1.addVertex();
	// Network 2
	Network net2(false,true,false);
	vertex_id n2v0 = net2.addVertex();
	vertex_id n2v1 = net2.addVertex();
	vertex_id n2v2 = net2.addVertex();
	// Network 3
	Network net3(false,true,false);
	vertex_id n3v0 = net3.addVertex();
	vertex_id n3v1 = net3.addVertex();
	vertex_id n3v2 = net3.addVertex();

	network_id n1 = mnet.addNetwork(net1);
	network_id n2 = mnet.addNetwork(net2);
	network_id n3 = mnet.addNetwork(net3);
	if (mnet.getNumNetworks()!=3) throw FailedUnitTestException("Wrong number of networks");
	log("done!");

	log("Specifying vertex mappings...",false);
	// To network 1
	mnet.map(gv0,n1v0,n1);
	mnet.map(gv1,n1v1,n1);
	mnet.map(gv2,n1v2,n1);
	// To network 2
	mnet.map(gv0,n2v0,n2);
	mnet.map(gv1,n2v1,n2);
	mnet.map(gv3,n2v2,n2);
	// To network 3
	mnet.map(gv0,n3v0,n3);
	mnet.map(gv2,n3v1,n3);
	mnet.map(gv3,n3v2,n3);
	if (mnet.getGlobalVertexId(n3v2,n3)!=gv3) throw FailedUnitTestException("Wrong mapping between global and local vertex");
	if (mnet.getLocalVertexId(gv3,n2)!=n2v2) throw FailedUnitTestException("Wrong mapping between global and local vertex");
	log("done!");

	/* behavior to be decided and tested
	log("Adding duplicate vertex mapping...",false);
	try {
		mnet.map(gv3,n3v2,n3);
		// should not arrive here
		throw FailedUnitTestException("Duplicate value non caught");
	}
	catch (DuplicateElementException& ex) {
		log("correctly thrown Exception!");
	}
	*/

	log("Adding five edges...",false); // they can also be added directly to the single networks
	mnet.getNetwork(n1)->addEdge(n1v0,n1v1);
	mnet.getNetwork(n2)->addEdge(n2v0,n2v1);
	mnet.getNetwork(n2)->addEdge(n2v1,n2v2);
	mnet.getNetwork(n3)->addEdge(n3v0,n3v2);
	mnet.getNetwork(n3)->addEdge(n3v1,n3v2);
	if (mnet.getNumEdges()!=5) throw FailedUnitTestException("Wrong number of global edges");
	log("done!");

	log("Mapping to a non existing network...",false);
	try {
		mnet.map(gv3,n2v2,n3+1);
		// should not arrive here
		throw FailedUnitTestException("Non existing network non caught");
	}
	catch (ElementNotFoundException& ex) {
		log("[FAIL] done!");
	}

	log("Mapping between non existing vertexes...",false);
	try {
		mnet.map(gv3,n2v2+1,n2);
		// should not arrive here
		throw FailedUnitTestException("Non existing vertex non caught");
	}
	catch (ElementNotFoundException& ex) {
		log("[FAIL] done!");
	}

	log("TEST SUCCESSFULLY COMPLETED (MultipleNetwork class - numeric identifiers)");

	log("Printing final multiple network information:");
	print(mnet);

}
void testMultilayerNetwork() {
	log("**************************************************************");
	log("TESTING basic multilayer network components (global_vertex_id, global_edge_id, network_id)...",false);
	/*
	 * these are normally automatically created
	 * by functions of the MultilayerNetwork class.
	 * However, here we test them by directly manipulating them.
	 */
	network_id nid1 = 0;
	network_id nid2 = 1;
	vertex_id vid1 = 0;
	vertex_id vid2 = 1;
	vertex_id vid3 = 0;
	global_vertex_id gvid1(vid1,nid1);
	global_vertex_id gvid2(vid2,nid1);
	global_vertex_id gvid3(vid3,nid2);
	// a directed edge
	global_edge_id e1(vid1,vid2,nid1,true);
	// another directed edge
	global_edge_id e2(vid2,vid1,nid1,true);
	// a third directed edge
	global_edge_id e3(vid2,vid1,nid1,true);
	// an undirected edge
	global_edge_id e4(vid1,vid2,nid1,false);
	// another undirected edge
	global_edge_id e5(vid2,vid1,nid1,false);
	if (e1==e2) throw FailedUnitTestException("Wrong edge_id comparison");
	if (e2!=e3) throw FailedUnitTestException("Wrong edge_id comparison");
	if (e4!=e5) throw FailedUnitTestException("Wrong edge_id comparison");
	log("done!");
	log("******************************************");
	log("TESTING MultilayerNetwork");
	log("REQUIRES Network class having been tested");

	log("Creating an empty multiple network...",false);
	MultilayerNetwork mnet;
	log("done!");

	log("Creating and adding three anonymous undirected and directed networks...",false);
	// Network 1
	Network net1(false,false,false);
	vertex_id n1v0 = net1.addVertex();
	vertex_id n1v1 = net1.addVertex();
	/*vertex_id n1v2 = */net1.addVertex();
	// Network 2
	Network net2(false,true,false);
	vertex_id n2v0 = net2.addVertex();
	vertex_id n2v1 = net2.addVertex();
	vertex_id n2v2 = net2.addVertex();
	// Network 3
	Network net3(false,true,false);
	vertex_id n3v0 = net3.addVertex();
	vertex_id n3v1 = net3.addVertex();
	vertex_id n3v2 = net3.addVertex();

	network_id n1 = mnet.addNetwork(net1);
	network_id n2 = mnet.addNetwork(net2);
	network_id n3 = mnet.addNetwork(net3);
	if (mnet.getNumNetworks()!=3) throw FailedUnitTestException("Wrong number of networks");
	log("done!");

	// TODO Check named networks

	log("Adding five edges...",false); // they can also be added directly to the single networks
	mnet.getNetwork(n1).addEdge(n1v0,n1v1);
	mnet.getNetwork(n2).addEdge(n2v0,n2v1);
	mnet.getNetwork(n2).addEdge(n2v1,n2v2);
	mnet.getNetwork(n3).addEdge(n3v0,n3v2);
	mnet.getNetwork(n3).addEdge(n3v1,n3v2);
	if (mnet.getNumEdges()!=5) throw FailedUnitTestException("Wrong number of global edges");
	log("done!");

	// Iterating through global edges and vertexes
	std::set<global_vertex_id> vertexes;
	std::set<global_edge_id> edges;

	log("TEST SUCCESSFULLY COMPLETED (MultilayerNetwork class - numeric identifiers)");

	log("Printing final multiple network information:");
	print(mnet);

}