Adding a model - simonbe/nexa GitHub Wiki

New models can be added by deriving and extending from any of the existing network objects. Operations that modify the state variables of a network object are called Modifiers (e.g. ProjectionModifer for models of synaptic plasticity). Here we will illustrate it by implementing a winner-take-all function in every column of a columnar population. As we are modifying the values of a population, we derive from a PopulationModifier.

  1. Define our new class WTA, derived from a PopulationModifier.
class WTA : public PopulationModifier
{
public:

	WTA()
	{
		m_name = "WTA"; // name identifier of our new class
	}

	void Simulate(); // overridden from PopulationModifier and called every simulation time step


private:

	vector<float> wta(vector<float> data);  // the actual winner-take-all function,
						// which takes the input vector data and
						//  returns a vector with a 1 on the position 
						//  of the highest value in data and 0 on 
						//  all other positions
};
  1. During a simulation, the object is called each time step in the Simulate function. We extend this to perform a WTA function in each column. To make sure that all values of the column exists on , irrespectivly of how the network has been parallelized on a machine, we call the help function Population::MPI::MakeActivityValuesLocal
void WTA::Simulate()
{
	PopulationColumns* population = (PopulationColumns*)m_population;
	vector<int> localHypercolumnIndexes = population->GetLocalHypercolumnIndexes();

	population->MPI()->MakeActivityValuesLocal();// make sure all columnar values are local

	for(int i=0;i<localHypercolumnIndexes.size();i++)
	{
		Hypercolumn* h = (Hypercolumn*)population->GetHypercolumn(i); // retrieve the column from zero-based index

		vector<float> data = h->GetValues(); // retrieve all unit activity values for column
		data = wta(data); // perform the winner-take-all operation on data

		h->SetValues(data); // set the values of all units in the column
	}
}
  1. The model can now be used in a network by adding it to a defined columnar population in NetworkSetupStructure.
columnarPopulation->AddPopulationModifier(new WTA());

More example implementations can be found in NetworkPopulationModifier.h/.cpp

⚠️ **GitHub.com Fallback** ⚠️