[Pybrainsim-activity] SF.net SVN: pybrainsim:[132] trunk/src
Status: Planning
Brought to you by:
rgoj
From: <rg...@us...> - 2009-09-13 23:40:43
|
Revision: 132 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=132&view=rev Author: rgoj Date: 2009-09-13 23:40:34 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * PyBrainSimGUI.py becomes PyBrainSim.py * We now have a graphical interface! Added Paths: ----------- trunk/src/PyBrainSim.py Removed Paths: ------------- trunk/src/PyBrainSimGUI.pyw Copied: trunk/src/PyBrainSim.py (from rev 130, trunk/src/PyBrainSimGUI.pyw) =================================================================== --- trunk/src/PyBrainSim.py (rev 0) +++ trunk/src/PyBrainSim.py 2009-09-13 23:40:34 UTC (rev 132) @@ -0,0 +1,281 @@ +#!/usr/bin/python + +# PyBrainSim +# Copyright 2009 Roman Goj +# +# This file is part of PyBrainSim. +# +# PyBrainSim is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# PyBrainSim is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. + +""" +PyBrainSim is an interactive tool for the simulation and visualization of the +electromagnetic activity of the brain, currently under development. + +This script allows you to choose from a few example simulations, ranging from +adding numbers to neural mass models. + +pybrainsim.sourceforge.net +""" + +import wx +from wx import xrc + +import numpy +import pylab +from random import random +from scipy.integrate import ode + +from Head import Head +from HeadModel import HeadModel +from HeadModelHalfSphere import HeadModelHalfSphere +from Experiment import Experiment +from Stimulus import Stimulus +from StimulusDummy import StimulusDummy +from GeneratorDummy import GeneratorDummy +from GeneratorNumberIncrementing import GeneratorNumberIncrementing +from GeneratorSine import GeneratorSine +from Connection import Connection +from ConnectionDummy import ConnectionDummy + +class PyBrainSimGUI(wx.App): + def OnInit(self): + self.res = xrc.XmlResource("PyBrainSimGUI.xrc") + + self.frame = self.res.LoadFrame(None, "menuFrame") + self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton2, id=xrc.XRCID("menuButton2")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton3, id=xrc.XRCID("menuButton3")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton4, id=xrc.XRCID("menuButton4")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton5, id=xrc.XRCID("menuButton5")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton6, id=xrc.XRCID("menuButton6")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton7, id=xrc.XRCID("menuButton7")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) + self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) + self.frame.Show() + return True + + def menuButton1(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleStimulus = StimulusDummy('Stim', exampleHead) + exampleGenerator = GeneratorDummy('Gen', exampleHead) + exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) + print("\nSimulations resulted in the following recording:") + print(exampleExperiment.getRecording()) + + def menuButton2(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes([0.3, 0.6]) + exampleGenerator = GeneratorNumberIncrementing('Gen', exampleHead) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + + def menuButton3(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(10) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0) + exampleExperiment.setStimulusTimes([[0.3, 0.6], [0.5]]) + + exampleStimulus1 = Stimulus('Stim1', exampleHead) + exampleStimulus2 = Stimulus('Stim2', exampleHead) + exampleStimulus1.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleStimulus2.setStimulusTimes(exampleExperiment.getStimulusTimes()[1]) + + exampleGenerator1 = GeneratorNumberIncrementing('Gen1', exampleHead) + exampleGenerator2 = GeneratorNumberIncrementing('Gen2', exampleHead) + exampleConnection1 = Connection('Con1', exampleHead, exampleStimulus1, exampleGenerator1) + exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + + def menuButton4(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(128) + exampleHead.addRegistrationSite([0, 0, 0]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) + exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) + + exampleStimulus = Stimulus('Stim', exampleHead) + print exampleExperiment.getStimulusTimes()[0] + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleGenerator = GeneratorSine('Gen', exampleHead) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + print("\nSimulations resulted in the following recording:") + print exampleExperiment.getRecording() + exampleExperiment.plotRecording() + + def menuButton5(self, control): + exampleHead = Head() + exampleHeadModel = HeadModel(exampleHead) + exampleHead.setSamplingFrequency(256) + exampleHead.addRegistrationSite([0, 0, 0]) + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 100.0) + + # Randomizing stimuli times + stimuli = [] + for i in range(100): + stimuli.append( i + 0.2 +random()/2 ) + exampleExperiment.setStimulusTimes([stimuli]) + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + + # Creating many generators with random frequencies in the range 2-20 Hz and + # random phases. Connecting some of them to the stimulus generator + exampleGenerators = [] + exampleConnections = [] + for i in range(100): + randomFrequency = 2.0 + random() * 18 + randomPhaseShift = random() + exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency=randomFrequency, phaseShift=randomPhaseShift)) + if(random() > 0.75): + exampleConnections.append(Connection('Con', exampleHead, exampleStimulus, exampleGenerators[i])) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + exampleExperiment.plotRecording() + + def menuButton6(self, control): + exampleHead = Head() + exampleHeadModel = HeadModelHalfSphere(exampleHead) + exampleHead.setSamplingFrequency(128) + exampleHead.addRegistrationSite([ 0.5, 0.0, 0.866]) + exampleHead.addRegistrationSite([ 0.0, 0.0, 0.866]) + exampleHead.addRegistrationSite([-0.5, 0.0, 0.866]) + + exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) + exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) + + exampleStimulus = Stimulus('Stim', exampleHead) + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) + exampleGenerator = GeneratorSine('Gen', exampleHead, position = [0.5, 0, 0.366], frequency = 7) + exampleGenerator = GeneratorSine('Gen', exampleHead, position = [-0.5, 0, 0.366], frequency = 4) + exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) + + exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) + exampleExperiment.plotRecording() + + def menuButton7(self, control): + exampleHead = Head() + exampleHead.displayHead() + + def menuButton8(self, control): + # This class will produce noise that will be fed into the modelled + # cortical area as input. + class NeuralNoise: + def __init__(self, timeSpan, dtime): + self.noise = [] + self.dtime = dtime + self.timePoints = range( int(timeSpan//dtime+1) ) + # Random noise distributed evenly between 120 and 320 + for i in self.timePoints: + self.noise.append( 120+200*random() ) + def getNoise(self, time): + # Searching for the appropriate time point + for i in self.timePoints: + if time < self.timePoints[i]*self.dtime: + # Interpolating between the randomly generated values + return self.noise[i] + \ + (self.noise[i+1]-self.noise[i]) \ + * ((self.timePoints[i]*self.dtime-time)/self.dtime) + + # The sigmoid function + def sigmoidFunction(v): + """Constants taken from Jansen and Rit 1995, p. 360""" + cEzero = 2.5 + cR = 0.56 + cVzero = 6 + + """Sigmoid function taken from Jansen and Rit 1995, p. 360""" + return 2*cEzero / ( 1 + numpy.exp( cR*( cVzero - v ) ) ) + + # Defining the equations + def f(t, y, noiseObject, cC): + cA=3.25 + ca=100.0 + cB=22.0 + cb=50.0 + cC1=cC + cC2=0.8*cC1 + cC3=0.25*cC1 + cC4=0.25*cC1 + noise = noiseObject.getNoise(t) + #print("Time: " + str(t) + " Noise: " + str(noise)) + return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - + ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - + 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) + ) - 2*cb*y[5] - cb**2*y[4]] + + # How many seconds should be modelled and how accurately + timeSpan = 3 + dtime = 0.001 + firstPointToDisplay = 1000 + + # A noise object that will be used as input into the equations + someNoise = NeuralNoise(timeSpan+1, dtime*10) + + # Initial conditions + y0, t0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0 + + # Preparing for simulations + r = [] + recording = [ [], [], [], [], [], [] ] + parameter = [ 68, 128, 135, 270, 675, 1350 ] + + # Differential equation integration + for i in range(len(parameter)): + # Preparing the integration + r.append(ode(f).set_integrator('vode', method='bdf')) + r[i].set_initial_value(y0, t0) + r[i].set_f_params( someNoise, parameter[i] ) + # Integrating + print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) + while r[i].successful() and r[i].t < timeSpan: + r[i].integrate(r[i].t+dtime) + recording[i].append(r[i].y[2] - r[i].y[4]) + + # Show results of simulations + for i in range(len(parameter)): + pylab.subplot( len(parameter), 1, i+1) + if i==0: + pylab.title("Simulations based on Fig. 3 from Jansen and Rit 1995") + pylab.ylabel( "C = " + str(parameter[i]) ) + pylab.plot(recording[i][firstPointToDisplay:]) + pylab.show() + + def menuButtonQuit(self, control): + self.Exit() + +if __name__ == '__main__': + app = PyBrainSimGUI(0) + app.MainLoop() Property changes on: trunk/src/PyBrainSim.py ___________________________________________________________________ Added: svn:executable + * Added: svn:mergeinfo + Deleted: trunk/src/PyBrainSimGUI.pyw =================================================================== --- trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:39:27 UTC (rev 131) +++ trunk/src/PyBrainSimGUI.pyw 2009-09-13 23:40:34 UTC (rev 132) @@ -1,281 +0,0 @@ -#!/usr/bin/python - -# PyBrainSim -# Copyright 2009 Roman Goj -# -# This file is part of PyBrainSim. -# -# PyBrainSim is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# PyBrainSim is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# PyBrainSim. If not, see <http://www.gnu.org/licenses/>. - -""" -PyBrainSim is an interactive tool for the simulation and visualization of the -electromagnetic activity of the brain, currently under development. - -This script allows you to choose from a few example simulations, ranging from -adding numbers to neural mass models. - -pybrainsim.sourceforge.net -""" - -import wx -from wx import xrc - -import numpy -import pylab -from random import random -from scipy.integrate import ode - -from Head import Head -from HeadModel import HeadModel -from HeadModelHalfSphere import HeadModelHalfSphere -from Experiment import Experiment -from Stimulus import Stimulus -from StimulusDummy import StimulusDummy -from GeneratorDummy import GeneratorDummy -from GeneratorNumberIncrementing import GeneratorNumberIncrementing -from GeneratorSine import GeneratorSine -from Connection import Connection -from ConnectionDummy import ConnectionDummy - -class PyBrainSimGUI(wx.App): - def OnInit(self): - self.res = xrc.XmlResource("PyBrainSimGUI.xrc") - - self.frame = self.res.LoadFrame(None, "menuFrame") - self.frame.Bind(wx.EVT_BUTTON, self.menuButton1, id=xrc.XRCID("menuButton1")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton2, id=xrc.XRCID("menuButton2")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton3, id=xrc.XRCID("menuButton3")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton4, id=xrc.XRCID("menuButton4")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton5, id=xrc.XRCID("menuButton5")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton6, id=xrc.XRCID("menuButton6")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton7, id=xrc.XRCID("menuButton7")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButton8, id=xrc.XRCID("menuButton8")) - self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) - self.frame.Show() - return True - - def menuButton1(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleStimulus = StimulusDummy('Stim', exampleHead) - exampleGenerator = GeneratorDummy('Gen', exampleHead) - exampleConnection = ConnectionDummy('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print(exampleExperiment.getRecording()) - - def menuButton2(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes([0.3, 0.6]) - exampleGenerator = GeneratorNumberIncrementing('Gen', exampleHead) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0, exampleHead.runSimulation( 1.0 )) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - - def menuButton3(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(10) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 1.0) - exampleExperiment.setStimulusTimes([[0.3, 0.6], [0.5]]) - - exampleStimulus1 = Stimulus('Stim1', exampleHead) - exampleStimulus2 = Stimulus('Stim2', exampleHead) - exampleStimulus1.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleStimulus2.setStimulusTimes(exampleExperiment.getStimulusTimes()[1]) - - exampleGenerator1 = GeneratorNumberIncrementing('Gen1', exampleHead) - exampleGenerator2 = GeneratorNumberIncrementing('Gen2', exampleHead) - exampleConnection1 = Connection('Con1', exampleHead, exampleStimulus1, exampleGenerator1) - exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - - def menuButton4(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([0, 0, 0]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) - exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) - - exampleStimulus = Stimulus('Stim', exampleHead) - print exampleExperiment.getStimulusTimes()[0] - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleGenerator = GeneratorSine('Gen', exampleHead) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() - exampleExperiment.plotRecording() - - def menuButton5(self, control): - exampleHead = Head() - exampleHeadModel = HeadModel(exampleHead) - exampleHead.setSamplingFrequency(256) - exampleHead.addRegistrationSite([0, 0, 0]) - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 100.0) - - # Randomizing stimuli times - stimuli = [] - for i in range(100): - stimuli.append( i + 0.2 +random()/2 ) - exampleExperiment.setStimulusTimes([stimuli]) - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - - # Creating many generators with random frequencies in the range 2-20 Hz and - # random phases. Connecting some of them to the stimulus generator - exampleGenerators = [] - exampleConnections = [] - for i in range(100): - randomFrequency = 2.0 + random() * 18 - randomPhaseShift = random() - exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency=randomFrequency, phaseShift=randomPhaseShift)) - if(random() > 0.75): - exampleConnections.append(Connection('Con', exampleHead, exampleStimulus, exampleGenerators[i])) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - exampleExperiment.plotRecording() - - def menuButton6(self, control): - exampleHead = Head() - exampleHeadModel = HeadModelHalfSphere(exampleHead) - exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([ 0.5, 0.0, 0.866]) - exampleHead.addRegistrationSite([ 0.0, 0.0, 0.866]) - exampleHead.addRegistrationSite([-0.5, 0.0, 0.866]) - - exampleExperiment = Experiment(exampleHead.getSamplingFrequency(), 10.0) - exampleExperiment.setStimulusTimes([[0.3, 1.75, 2.16, 3.87, 4.31, 5.183, 6.34, 7.13]]) - - exampleStimulus = Stimulus('Stim', exampleHead) - exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()[0]) - exampleGenerator = GeneratorSine('Gen', exampleHead, position = [0.5, 0, 0.366], frequency = 7) - exampleGenerator = GeneratorSine('Gen', exampleHead, position = [-0.5, 0, 0.366], frequency = 4) - exampleConnection = Connection('Con', exampleHead, exampleStimulus, exampleGenerator) - - exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - exampleExperiment.plotRecording() - - def menuButton7(self, control): - exampleHead = Head() - exampleHead.displayHead() - - def menuButton8(self, control): - # This class will produce noise that will be fed into the modelled - # cortical area as input. - class NeuralNoise: - def __init__(self, timeSpan, dtime): - self.noise = [] - self.dtime = dtime - self.timePoints = range( int(timeSpan//dtime+1) ) - # Random noise distributed evenly between 120 and 320 - for i in self.timePoints: - self.noise.append( 120+200*random() ) - def getNoise(self, time): - # Searching for the appropriate time point - for i in self.timePoints: - if time < self.timePoints[i]*self.dtime: - # Interpolating between the randomly generated values - return self.noise[i] + \ - (self.noise[i+1]-self.noise[i]) \ - * ((self.timePoints[i]*self.dtime-time)/self.dtime) - - # The sigmoid function - def sigmoidFunction(v): - """Constants taken from Jansen and Rit 1995, p. 360""" - cEzero = 2.5 - cR = 0.56 - cVzero = 6 - - """Sigmoid function taken from Jansen and Rit 1995, p. 360""" - return 2*cEzero / ( 1 + numpy.exp( cR*( cVzero - v ) ) ) - - # Defining the equations - def f(t, y, noiseObject, cC): - cA=3.25 - ca=100.0 - cB=22.0 - cb=50.0 - cC1=cC - cC2=0.8*cC1 - cC3=0.25*cC1 - cC4=0.25*cC1 - noise = noiseObject.getNoise(t) - #print("Time: " + str(t) + " Noise: " + str(noise)) - return [y[1], cA*ca*( sigmoidFunction(y[2] - y[4]) ) - 2*ca*y[1] - - ca**2*y[0], y[3], cA*ca*( noise + cC2*sigmoidFunction(cC1*y[0]) ) - - 2*ca*y[3] - ca**2*y[2], y[5], cB*cb*( cC4*sigmoidFunction(cC3*y[0]) - ) - 2*cb*y[5] - cb**2*y[4]] - - # How many seconds should be modelled and how accurately - timeSpan = 3 - dtime = 0.001 - firstPointToDisplay = 1000 - - # A noise object that will be used as input into the equations - someNoise = NeuralNoise(timeSpan+1, dtime*10) - - # Initial conditions - y0, t0 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0 - - # Preparing for simulations - r = [] - recording = [ [], [], [], [], [], [] ] - parameter = [ 68, 128, 135, 270, 675, 1350 ] - - # Differential equation integration - for i in range(len(parameter)): - # Preparing the integration - r.append(ode(f).set_integrator('vode', method='bdf')) - r[i].set_initial_value(y0, t0) - r[i].set_f_params( someNoise, parameter[i] ) - # Integrating - print("Performing simulation " + str(i+1) + "/" + str(len(parameter))) - while r[i].successful() and r[i].t < timeSpan: - r[i].integrate(r[i].t+dtime) - recording[i].append(r[i].y[2] - r[i].y[4]) - - # Show results of simulations - for i in range(len(parameter)): - pylab.subplot( len(parameter), 1, i+1) - if i==0: - pylab.title("Simulations based on Fig. 3 from Jansen and Rit 1995") - pylab.ylabel( "C = " + str(parameter[i]) ) - pylab.plot(recording[i][firstPointToDisplay:]) - pylab.show() - - def menuButtonQuit(self, control): - self.Exit() - -if __name__ == '__main__': - app = PyBrainSimGUI(0) - app.MainLoop() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |