示例#1
0
func (this *SpikingNeuron) ScopedSimulation(I float64, i int, t, T1, tau float64, uu []float64, neuronManager *group.NeuronManager) {
	// Lock...
	if neuronManager != nil {
		// Increment to number of neurons...
		// fmt.Println("Neuron", this.GetId(), "incremented the wait counter...");
		time.Sleep(time.Millisecond)
		neuronManager.GetInnerWaitGroup().Add(1)
		defer neuronManager.GetInnerWaitGroup().Done()
		// fmt.Println("Neuron", this.GetId(), "grabbed the lock...");
		time.Sleep(time.Millisecond)
		neuronManager.OuterLock()
	}

	// Get all the outputs from each connection.
	if this.GetInputPredicate()(i, t, T1, this) {
		I = this.GetInputSuccess()(i, t, T1, this)
	} else {
		I = this.GetInputFail()(i, t, T1, this)
	}

	this.SetV(this.GetV() + tau*(vars.GetConstantV1()*(this.GetV()*this.GetV())+vars.GetConstantV2()*this.GetV()+vars.GetConstantV3()-this.GetU()+I))
	this.SetU(this.GetU() + tau*this.GetA()*(this.GetB()*this.GetV()-this.GetU()))

	if this.GetPredicate()(t, i, this) {
		this.GetSuccess()(t, i, this)
		// Default results.
		this.SetV(this.GetC())
		this.SetU(this.GetU() + this.GetD())
	} else {
		// Don't Fire...
		this.GetFail()(t, i, this)
	}

	uu[i] = this.GetU()
}
示例#2
0
func (this *SpikingNeuron) Simulate(simulation *sim.Simulation, neuronManager *group.NeuronManager) {
	I := float64(0)

	steps := simulation.GetSteps()
	tau := simulation.GetTau()
	timeSeries := simulation.GetTimeSeries()
	start := simulation.GetStart()
	T1 := simulation.GetT()

	uu := make([]float64, len(timeSeries))

	this.SetOutputs(make([]float64, len(timeSeries)))

	for t, i := start, 0; t < steps; t, i = t+tau, i+1 {
		timeSeries[i] = t
		this.ScopedSimulation(I, i, t, T1, tau, uu, neuronManager)

		if neuronManager != nil {
			// fmt.Println("Neuron", this.GetId(), "released the lock");
			time.Sleep(time.Millisecond)
			neuronManager.OuterUnlock()
			// fmt.Println("Neuron", this.GetId(), "is waiting...");
			time.Sleep(time.Millisecond)
			neuronManager.GetInnerWaitGroup().Wait()
			time.Sleep(time.Millisecond * 2)
			// fmt.Println("Neuron", this.GetId(), "is finished at time", t);
		}
	}

	simulation.SetTimeSeries(timeSeries)

	if neuronManager != nil {
		// fmt.Println("Finished", this.GetId());
		neuronManager.DoneWaitGroup()
	}
}