Last active
February 2, 2020 17:45
-
-
Save ali2210/203892ffb246457f018fc37916e8bee0 to your computer and use it in GitHub Desktop.
Spike-Informatica
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| "gorgonia.org/gorgonia" | |
| ) | |
| // struct definition for stimulation | |
| type U struct{ | |
| membrane int | |
| t time.Duration | |
| } | |
| type Neuron struct{ | |
| Axon *gorgonia.Node | |
| u U | |
| fire bool | |
| e int | |
| } | |
| const ( | |
| urest int = 0 // Intial Value Reset | |
| numOfPreSynapes int = 2 | |
| fire int = 4 | |
| nums int = 2 | |
| thresold int = 700 | |
| ) | |
| func main() { | |
| // Both neurons fire independent | |
| g := gorgonia.NewGraph() | |
| var postSynapes *gorgonia.Node | |
| var preSynapes[2]*gorgonia.Node | |
| var jSynapes[numOfPreSynapes]Neuron | |
| totalSpikes,totalTime := 0, time.Millisecond | |
| postSynapes = gorgonia.NewScalar(g, gorgonia.Float64,gorgonia.WithName("postSynapes")) | |
| u := U{-67, time.Millisecond} | |
| n := Neuron{postSynapes,u,false,0} | |
| fmt.Println("\tReset Mode[I] Neuron:" ,n.Reset(n.u.t)) | |
| preSynapes[0] = gorgonia.NewScalar(g, gorgonia.Float64, gorgonia.WithName("preSynapes0")) | |
| preSynapes[1] = gorgonia.NewScalar(g, gorgonia.Float64, gorgonia.WithName("preSynapes1")) | |
| for i := 0; i < numOfPreSynapes ; i++{ | |
| jSynapes[i] = Neuron{preSynapes[i],u,false, 0} | |
| fmt.Println("\tReset Mode[J] Neuron:" ,jSynapes[i].Reset(jSynapes[i].u.t)) | |
| } | |
| gorgonia.Let(postSynapes,0) | |
| gorgonia.Let(preSynapes[0],1) | |
| gorgonia.Let(preSynapes[1],2) | |
| ispikes:= 0 | |
| for j := 0; j < nums; j++ { | |
| //fmt.Println("\t********* (J) Neurons Spikes ********") | |
| n.UpdatedMembrane(jSynapes,n.u.t) | |
| // for i := 0; i < numOfPreSynapes; i++ { | |
| // jSynapes[i].e,jSynapes[i].u.t = n.Spike(n.u.t) | |
| // fmt.Println(jSynapes[i]) | |
| // } | |
| n.e , n.u.t, ispikes = n.Spike(n.u.t) | |
| //fmt.Println("\t*********(I) Spikes ***********") | |
| X := zeroToHundred(n.e) | |
| n.e += X | |
| Y := zeroToHundredSec(n.u.t) | |
| n.u.t += Y | |
| fmt.Println("Max J Spike Range ", X) | |
| fmt.Println("[I] # of spikes/ms ", ispikes) | |
| fmt.Println("[J] fire time ", Y) | |
| //fmt.Println("x",X , "Y", Y) | |
| totalTime += n.u.t | |
| totalSpikes += ispikes | |
| //fmt.Println("[j] neuron Reset Mode:" ,n.Reset(n.u.t)) | |
| ispikes =0 | |
| //fmt.Println(n.e) | |
| if X >= thresold { | |
| n.u.t = n.u.t^time.Duration(fire) | |
| n.u.membrane = thresold | |
| dt := n.u.membrane * 1 | |
| fmt.Println("membrane:",dt) | |
| n.u.membrane = urest | |
| } | |
| fmt.Println("Stimulation time:", totalTime) | |
| fmt.Println("Nums of Spikes (i) GET", totalSpikes) | |
| n.e = X | |
| n.u.t = Y | |
| } | |
| //n.u.membrane = urest | |
| fmt.Println("[j] neuron Reset Mode:" ,n.Reset(n.u.t)) | |
| } | |
| func (neuron *Neuron)Reset(intialTime time.Duration)(*Neuron){ | |
| if(intialTime > 0){ | |
| (*neuron).u.membrane = urest | |
| (*neuron).u.t = time.Millisecond | |
| (*neuron).fire = false | |
| } | |
| return neuron | |
| } | |
| func (a *Neuron) Spike(t time.Duration)(int, time.Duration, int){ | |
| info := (*a).u.membrane - urest | |
| e := 0 | |
| if t > 1 || t == 1 && info > 0{ | |
| e = 1 | |
| (*a).u.t = t | |
| }else{ | |
| e = 0 | |
| (*a).u.t = t | |
| } | |
| return info, (*a).u.t, e | |
| } | |
| func (i *Neuron) UpdatedMembrane(pre [2]Neuron,t time.Duration){ | |
| if t > 1 || t == 1{ | |
| for j := 0; j < len(pre); j++ { | |
| pre[j].fire = true | |
| for f := 0; f < fire; f++ { | |
| pre[j].u.t = (t - pre[j].u.t^time.Duration(f)) | |
| (*i).u.membrane = int((*i).N((*i).u.t)) + (*i).E(pre[j].u.t) * int(pre[j].u.t)+urest | |
| t*=1 | |
| // fmt.Println("J time", pre[j].u.t) | |
| // fmt.Println("i time", t) | |
| } | |
| } | |
| } | |
| t*=2 | |
| (*i).u.t = t | |
| } | |
| func (pre *Neuron)E(t time.Duration)(int){ | |
| e := (*pre).u.membrane - urest | |
| if t > 1 || t ==1 && e > 0 && (*pre).fire{ | |
| e = 1 | |
| //fmt.Println("(j) neuron +ve signal\t",e) | |
| return e | |
| } | |
| e = 0 | |
| //fmt.Println("(j) neuron -ve signal\t",e) | |
| return e | |
| } | |
| func (post *Neuron)N(t time.Duration)time.Duration{ | |
| sign := t - max((*post).u.t ^ time.Duration(fire), t , (*post).u.t^time.Duration(fire) < t ) | |
| //fmt.Println(sign) | |
| return sign | |
| } | |
| func max(t, t1 time.Duration, t0 bool)(time.Duration) { | |
| if t0{ | |
| return t | |
| } | |
| return t1 | |
| } | |
| func zeroToHundred (x int)(int){ | |
| return(x/1000000)*100 | |
| } | |
| func zeroToHundredSec (x time.Duration)(time.Duration){ | |
| return(x/1000000)*100 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment