Example #1
0
/* Run a regular ring network test, but with an additional variable-sized
 * population of unconnected neurons of a different type.
 *
 * The additional Poisson source neurons should not have any effect on the
 * simulation but should expose errors related to mixing local/global partition
 * indices.
 */
void
testNeuronTypeMixture(backend_t backend, unsigned szOthers, bool izFirst)
{
	const unsigned szRing = 1024;
	boost::scoped_ptr<nemo::Network> net(new nemo::Network());
	if(izFirst) {
		createRing(net.get(), szRing);
	}
	unsigned poisson = net->addNeuronType("PoissonSource");
	float p = 0.001f;
	for(unsigned n=szRing; n<szRing+szOthers; ++n) {
		net->addNeuron(poisson, n, 1, &p);
	}
	if(!izFirst) {
		createRing(net.get(), szRing);
	}

	nemo::Configuration conf = configuration(false, 1024, backend);
	boost::scoped_ptr<nemo::Simulation> sim;
	BOOST_REQUIRE_NO_THROW(sim.reset(nemo::simulation(*net, conf)));

	/* Stimulate a single neuron to get the ring going */
	sim->step(std::vector<unsigned>(1, 0));

	const unsigned duration = 1000;
	for(unsigned ms=1; ms < duration; ++ms) {
		std::vector<unsigned> fired = sim->step();
		BOOST_REQUIRE(fired.size() > 0);
		std::sort(fired.begin(), fired.end());
		BOOST_REQUIRE_EQUAL(fired[0], ms % szRing);
		if(fired.size() > 1) {
			BOOST_REQUIRE(fired[1] >= szRing);
		}
	}
}
Example #2
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 #3
0
int main() {
	JosephRing* ring = NULL;
	int i = 0;
	int k, m;
	printf("Please in put k and m:\n");
	scanf("%d %d", &k, &m);

	ring = createRing();
	for (i = 0; i < 10; i++)
		insert(ring, i);
#ifdef _DEBUG_
	printAll(ring);
#endif
	printf("the last number is %d\n", getNumber(ring, k, m));
	free(ring);

	ring = createRing();
	for (i = 0; i < 10; i++)
		insert(ring, i * 2 + 1);
#ifdef _DEBUG_
	printAll(ring);
#endif // _DEBUG_

	printf("the last number is %d\n", newGetNumber(ring, k));
	free(ring);
	system("pause");
	return 0;
}
Example #4
0
//-----------------------------------------------------------------------------
// create vertex and index buffers
void Wreck::createBuffers()
{
  int sideSteps = 50;
  int outSteps = 240;

  int ringSteps = 30;
  int circleSteps = 50;

  int vertexCount = 3* (outSteps+1) * (sideSteps+1);
  int indexCount = 3*6*outSteps*sideSteps;

  vertexCount += 3* (circleSteps+1) * (ringSteps+1);
  indexCount += 3*6*circleSteps*ringSteps;

  m_vertexes = mgVertexTA::newBuffer(vertexCount);
  m_indexes = mgDisplay->newIndexBuffer(indexCount, false, true);

  for (int i = 0; i < 3; i++)
  {
    mgMatrix4 model;
    model.translate(0, 0, 65+40*i);
    createRing(model, ringSteps, circleSteps);
  }

  createSpine(sideSteps, outSteps);

  for (int i = 0; i < m_towers.length(); i++)
  {
    Tower* tower = (Tower*) m_towers[i];
    if (tower != NULL)
      tower->createBuffers();
  }
}
Example #5
0
void
runRing(backend_t backend, unsigned ncount, unsigned delay)
{
	/* Make sure we go around the ring at least a couple of times */
	const unsigned duration = ncount * 5 / 2;

	nemo::Configuration conf = configuration(false, 1024);
	setBackend(backend, conf);
	boost::scoped_ptr<nemo::Network> net(createRing(ncount, 0, false, 1, delay));
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));

	/* Stimulate a single neuron to get the ring going */
	sim->step(std::vector<unsigned>(1, 0));

	for(unsigned ms=1; ms < duration; ++ms) {
		const std::vector<unsigned>& fired = sim->step();
		if(delay == 1) {
			BOOST_CHECK_EQUAL(fired.size(), 1U);
			BOOST_REQUIRE_EQUAL(fired.front(), ms % ncount);
		} else if(ms % delay == 0) {
			BOOST_CHECK_EQUAL(fired.size(), 1U);
			BOOST_REQUIRE_EQUAL(fired.front(), (ms / delay) % ncount);
		} else {
			BOOST_CHECK_EQUAL(fired.size(), 0U);
		}
	}
}
Example #6
0
void
testCurrentStimulus(backend_t backend)
{
	unsigned ncount = 1500;
	unsigned duration = ncount * 2;

	nemo::Configuration conf = configuration(false, 1024, backend);
	boost::scoped_ptr<nemo::Network> net(createRing(ncount));
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));

	nemo::Simulation::current_stimulus istim;
	// add some noise before and after
	istim.push_back(std::make_pair(5U, 0.001f));
	istim.push_back(std::make_pair(8U, 0.001f));
	istim.push_back(std::make_pair(0U, 1000.0f));
	istim.push_back(std::make_pair(100U, 0.001f));
	istim.push_back(std::make_pair(1U, 0.001f));

	/* Simulate a single neuron to get the ring going */
	sim->step(istim);

	for(unsigned ms=1; ms < duration; ++ms) {
		const std::vector<unsigned>& fired = sim->step();
		BOOST_CHECK_EQUAL(fired.size(), 1U);
		BOOST_REQUIRE_EQUAL(fired.front(), ms % ncount);
	}
}
Example #7
0
/* Make sure that calling applyStdp gives an error */
void
testInvalidStdpUsage(backend_t backend)
{
	boost::scoped_ptr<nemo::Network> net(createRing(10, 0, true));
	nemo::Configuration conf;
	setBackend(backend, conf);
	BOOST_REQUIRE_THROW(simpleStdpRun(*net, conf), nemo::exception);
}
Example #8
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);
}
Example #9
0
void KisColorSelector::recalculateRings(quint8 numRings, quint8 numPieces)
{
    m_colorRings.resize(numRings);
    m_numPieces = numPieces;
    
    for(int i=0; i<numRings; ++i) {
        qreal innerRadius = qreal(i)   / qreal(numRings);
        qreal outerRadius = qreal(i+1) / qreal(numRings);
        qreal saturation  = qreal(i)   / qreal(numRings-1);
        
        createRing(m_colorRings[i], numPieces, innerRadius, outerRadius+0.001);
        m_colorRings[i].saturation = m_inverseSaturation ? (1.0 - saturation) : saturation;
    }
}
Example #10
0
/* Run two small non-overlapping rings with different delays */
void
runDoubleRing(backend_t backend)
{
	/* Make sure we go around the ring at least a couple of times */
	const unsigned ncount = 512;
	const unsigned duration = ncount * 5 / 2;

	nemo::Configuration conf = configuration(false, 1024);
	setBackend(backend, conf);

	boost::scoped_ptr<nemo::Network> net(new nemo::Network);

	createRing(net.get(), ncount, 0, false, 1, 1);
	createRing(net.get(), ncount, ncount, false, 1, 2);

	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));

	/* Stimulate a single neuron in each ring to get them going */
	std::vector<unsigned> fstim;
	fstim.push_back(0);
	fstim.push_back(ncount);

	sim->step(fstim);

	for(unsigned ms=1; ms < duration; ++ms) {
		const std::vector<unsigned>& fired = sim->step();
		if(ms % 2 == 0) {
			BOOST_CHECK_EQUAL(fired.size(), 2U);
			BOOST_REQUIRE_EQUAL(fired[0], ms % ncount);
			BOOST_REQUIRE_EQUAL(fired[1], ncount + (ms / 2) % ncount);
		} else {
			BOOST_CHECK_EQUAL(fired.size(), 1U);
			BOOST_REQUIRE_EQUAL(fired.front(), ms % ncount);
		}
	}
}
Example #11
0
void
testInvalidCurrentStimulus(backend_t backend)
{
	unsigned ncount = 1000U;
	nemo::Configuration conf = configuration(false, 1024, backend);
	boost::scoped_ptr<nemo::Network> net(createRing(ncount));
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));

	sim->step();
	sim->step();

	nemo::Simulation::current_stimulus istim;
	istim.push_back(std::make_pair(ncount+1, 0.5));
	BOOST_REQUIRE_THROW(sim->step(istim), nemo::exception);
}
Example #12
0
bool Mist::setup() {
  vert = rx_create_shader(GL_VERTEX_SHADER, MIST_VS);
  frag = rx_create_shader(GL_FRAGMENT_SHADER, MIST_FS);
  prog = rx_create_program(vert, frag);
  glBindAttribLocation(prog, 0, "a_pos");
  glBindAttribLocation(prog, 1, "a_tex");
  glLinkProgram(prog);
  rx_print_shader_link_info(prog);

  glUseProgram(prog);
  glUniform1i(glGetUniformLocation(prog, "u_tex"), 0);
  u_time = glGetUniformLocation(prog, "u_time");
  u_perc = glGetUniformLocation(prog, "u_perc");

  assert(u_time >= 0);
  assert(u_perc >= 0);

  glGenVertexArrays(1, &vao);
  glBindVertexArray(vao);
  glEnableVertexAttribArray(0);
  glEnableVertexAttribArray(1);

  glGenBuffers(1, &vbo);
  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPT3), (GLvoid*)0);
  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPT3), (GLvoid*)12);

  createRing(effects.win_w * 0.5, effects.win_h * 0.5, 20.0f, 450.0);

  MistShape shape;
  shape.reset();
  shape.offset = offsets.back();
  shape.count = counts.back();
  shape.x = 1024 * 0.5;
  shape.y = 768 * 0.5;
  shapes.push_back(shape);

  mist_tex = rx_create_texture(rx_to_data_path("images/mist.png")); // , GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
  if(!mist_tex) {
    printf("Error: cannot create the mist texture.\n");
    return false;
  }
  printf("mist.mist_tex: %d\n", mist_tex);
  return true;
}
Example #13
0
void
testWriteOnlySynapses(backend_t backend)
{
	bool stdp = false;
	nemo::Configuration conf = configuration(stdp, 1024, backend);
	conf.setWriteOnlySynapses();
	boost::scoped_ptr<nemo::Network> net(createRing(10, 0, true));
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));
	sim->step();
	BOOST_REQUIRE_THROW(const std::vector<synapse_id> ids = sim->getSynapsesFrom(0), nemo::exception);

	/* so, we cant use getSynapsesFrom, but create a synapse id anyway */
	nidx_t neuron = 1;
	unsigned synapse = 0;
	synapse_id id = (uint64_t(neuron) << 32) | uint64_t(synapse);

	BOOST_REQUIRE_THROW(sim->getSynapseWeight(id), nemo::exception);
}
Example #14
0
//----------------------------------------------------------------------------
// Emit rings
//----------------------------------------------------------------------------
void Splash::emitRings( F32 dt )
{
   mTimeSinceLastRing += dt;

   S32 numNewRings = (S32) (mTimeSinceLastRing * F32(mDataBlock->ejectionFreq));

   mTimeSinceLastRing -= numNewRings / mDataBlock->ejectionFreq;

   for( S32 i=numNewRings-1; i>=0; i-- )
   {
      F32 t = F32(i) / F32(numNewRings);
      t *= dt;
      t += mTimeSinceLastRing;

      SplashRing ring = createRing();
      updateRing( ring, t );

      ringList.pushBack( ring );
   }
}
Example #15
0
/* Crudely test that the average rate over a long run approaches the expected value */
void
testRate(backend_t backend, unsigned duration, bool otherNeurons)
{
	nemo::Network net;
	nemo::Configuration conf = configuration(false, 1024, backend);
	if(otherNeurons) {
		/* This population will never fire */
		createRing(&net, 1024, 1);
	}
	unsigned poisson = net.addNeuronType("PoissonSource");
	float rate = 0.010f;
	net.addNeuron(poisson, 0, 1, &rate);
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(net, conf));
	unsigned nfired = 0;
	for(unsigned t=0; t<duration; ++t) {
		const std::vector<unsigned>& fired = sim->step();
		nfired += fired.size();
	}
	unsigned expected = unsigned(fabsf(float(duration)*rate));
	unsigned deviation = nfired - expected;
	//! \todo use a proper statistical test over a large number of runs
	BOOST_REQUIRE(nfired > 0);
	BOOST_REQUIRE(deviation < expected * 2);
}
Example #16
0
/*================MAIN==================*/
int main(int argc, char** argv){
	if(argc != 2 && argc != 4){
		printf("usage: %s [Port]\n", argv[1]);
		printf("usage: %s [my port] [server ipaddress] [server port]\n", argv[1]);
		exit(1);
	}

	//init current node, 2 predecessors, 2 successor0cessors
	current = mmap(NULL, sizeof(current), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	current->id = 0;
	current->port = 0;
	strcpy(current->ip, "\0");

	predecessor0 = mmap(NULL, sizeof(predecessor0), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	predecessor0->id = 0;
	predecessor0->port = 0;
	strcpy(predecessor0->ip, "\0");

	predecessor1 = mmap(NULL, sizeof(predecessor1), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	predecessor1->id = 0;
	predecessor1->port = 0;
	strcpy(predecessor1->ip, "\0");

	successor0 = mmap(NULL, sizeof(successor0), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	successor0->id = 0;
	successor0->port = 0;
	strcpy(successor0->ip, "\0");

	successor1 = mmap(NULL, sizeof(successor1), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	successor1->id = 0;
	successor1->port = 0;
	strcpy(successor1->ip, "\0");

	fingerTable = mmap(NULL, sizeof(FINGERTABLE_SIZE * sizeof(finger)), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);

	quitUpdate = mmap(NULL, sizeof(quitUpdate),PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	*quitUpdate = 0;

	//
	CurrentInfo(argv[1]);

	if(argc == 2){
		printf("Only two arguments.Create a new ring.\n");
		createRing(argv[1]);
	} 
	else{
		printf("Only four arguments. Join a old ring.\n");
		join(argv);
	}

	int pid0 = fork();

	if (pid0 == 0){
		//printf("Need a function send "IS_ALIVE" here");
	} 
	else{
		if (pid0 == -1){
			perror("fork");
			return 1;
		} 
		else{
			
			int pid = fork();
			if (pid == 0){
				//printf("===MAIN: I will fork and set up server.===\n");
				setupServer(argv[1]);
				return 0;
			} 
			else{
				if (pid == -1){
					perror("fork");
					return 1;
				} 
				else{
					//printf("I will deal with ui.\n");
					ui();
					return 0;
				}
			}

			return 0;
		}
	}

}