Thread: [Pybrainsim-activity] SF.net SVN: pybrainsim:[118] trunk/src/PyBrainSim.py (Page 2)
Status: Planning
Brought to you by:
rgoj
From: <rg...@us...> - 2009-08-15 16:12:44
|
Revision: 118 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=118&view=rev Author: rgoj Date: 2009-08-15 16:12:35 +0000 (Sat, 15 Aug 2009) Log Message: ----------- * Correcting error in example 5 from PyBrainSim.py caused by changing the GeneratorSine __init__() method: a new parameter was added and this was not correctly set by the example. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-08-15 16:04:26 UTC (rev 117) +++ trunk/src/PyBrainSim.py 2009-08-15 16:12:35 UTC (rev 118) @@ -143,9 +143,9 @@ exampleGenerators = [] exampleConnections = [] for i in range(100): - frequency = 2.0 + random() * 18 - phaseShift = random() - exampleGenerators.append(GeneratorSine('Gen', exampleHead, frequency, phaseShift)) + 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])) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-08-15 16:15:49
|
Revision: 119 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=119&view=rev Author: rgoj Date: 2009-08-15 16:15:42 +0000 (Sat, 15 Aug 2009) Log Message: ----------- * Added a third registration site in example 6 in PyBrainSim, to showcase the new functionality (HeadModelHalfSphere) even better. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-08-15 16:12:35 UTC (rev 118) +++ trunk/src/PyBrainSim.py 2009-08-15 16:15:42 UTC (rev 119) @@ -155,8 +155,9 @@ exampleHead = Head() exampleHeadModel = HeadModelHalfSphere(exampleHead) exampleHead.setSamplingFrequency(128) - exampleHead.addRegistrationSite([0.5, 0, 0.866]) - exampleHead.addRegistrationSite([-0.5, 0, 0.866]) + 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]]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-08-18 11:05:16
|
Revision: 121 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=121&view=rev Author: rgoj Date: 2009-08-18 11:05:08 +0000 (Tue, 18 Aug 2009) Log Message: ----------- * Added a new example to the PyBrainSim.py scritpt, that will be used to showcase the 3d head model display features. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-08-18 11:04:12 UTC (rev 120) +++ trunk/src/PyBrainSim.py 2009-08-18 11:05:08 UTC (rev 121) @@ -49,7 +49,8 @@ 4. A single sinusoidal generator\n\ 5. A hundred sinusoidal generators with random frequencies, some connected\ to a stimulus.\n\ - 6. A single sinusoidal generator but with two registration sites" + 6. A single sinusoidal generator but with two registration sites\n\ + 7. A presentation of the 3d head model." print(welcomeMessage) userChoice = input("Your choice: ") @@ -170,5 +171,8 @@ exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) exampleExperiment.plotRecording() +elif userChoice == 7: + exampleHead = Head() + exampleHead.displayHead() else: print("No such option unfortunately...") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-11 10:03:36
|
Revision: 124 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=124&view=rev Author: rgoj Date: 2009-09-11 10:03:26 +0000 (Fri, 11 Sep 2009) Log Message: ----------- * Preparing the PyBrainSim script to host an example cortical area simulation with a neural mass model from Jansen and Rit 1995. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-02 08:51:22 UTC (rev 123) +++ trunk/src/PyBrainSim.py 2009-09-11 10:03:26 UTC (rev 124) @@ -48,9 +48,10 @@ 3. Incrementing numbers, two generators and a stimulus for one of them\n\ 4. A single sinusoidal generator\n\ 5. A hundred sinusoidal generators with random frequencies, some connected\ - to a stimulus.\n\ + to a stimulus\n\ 6. A single sinusoidal generator but with two registration sites\n\ - 7. A presentation of the 3d head model." + 7. A presentation of the 3d head model\n\ + 8. A model of a cortical area, based on Jansen and Rit 1995." print(welcomeMessage) userChoice = input("Your choice: ") @@ -174,5 +175,7 @@ elif userChoice == 7: exampleHead = Head() exampleHead.displayHead() +elif userChoice == 8: + print("Not implemented yet...") else: print("No such option unfortunately...") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-11 10:07:44
|
Revision: 125 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=125&view=rev Author: rgoj Date: 2009-09-11 10:07:37 +0000 (Fri, 11 Sep 2009) Log Message: ----------- * Adding module imports: ** numpy ** integration from scipy Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-11 10:03:26 UTC (rev 124) +++ trunk/src/PyBrainSim.py 2009-09-11 10:07:37 UTC (rev 125) @@ -26,7 +26,9 @@ pybrainsim.sourceforge.net """ +import numpy from random import random +from scipy.integrate import ode from Head import Head from HeadModel import HeadModel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-13 19:24:23
|
Revision: 127 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=127&view=rev Author: rgoj Date: 2009-09-13 19:24:15 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * Added an example cortical area simulation with a neural mass model from Jansen and Rit 1995. This currently isn't programmed with classes, so it will need to be rewritten to allow neural mass model specification, but it shows that it is easy to use such models and is a good starting point for writing the classes. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-11 10:30:28 UTC (rev 126) +++ trunk/src/PyBrainSim.py 2009-09-13 19:24:15 UTC (rev 127) @@ -178,6 +178,88 @@ exampleHead = Head() exampleHead.displayHead() elif userChoice == 8: - print("Not implemented yet...") + # 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 + from pylab import * + for i in range(len(parameter)): + subplot( len(parameter), 1, i+1) + if i==0: + title("Simulations based on Fig. 3 from Jansen and Rit 1995") + ylabel( "C = " + str(parameter[i]) ) + plot(recording[i][firstPointToDisplay:]) + show() else: print("No such option unfortunately...") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-13 23:39:38
|
Revision: 131 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=131&view=rev Author: rgoj Date: 2009-09-13 23:39:27 +0000 (Sun, 13 Sep 2009) Log Message: ----------- * Removing the old text based PyBrainSim.py script to make room for PyBrainSimGUI. Removed Paths: ------------- trunk/src/PyBrainSim.py Deleted: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-13 23:37:32 UTC (rev 130) +++ trunk/src/PyBrainSim.py 2009-09-13 23:39:27 UTC (rev 131) @@ -1,265 +0,0 @@ -# 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 can be executed to run an example simulation, using the Head and -GeneratorDummy classes. Currently it only generates a list of integer -numbers... but work is under way to make it simulate the brain... Have fun! - -pybrainsim.sourceforge.net -""" - -import numpy -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 - -welcomeMessage = "\n\ -Welcome to this early version of PyBrainSim\n\n\ -Choose the type of simulation you would like to perform:\n\ - 1. Example dummy simulation\n\ - 2. Incrementing numbers, one generator and a stimulus\n\ - 3. Incrementing numbers, two generators and a stimulus for one of them\n\ - 4. A single sinusoidal generator\n\ - 5. A hundred sinusoidal generators with random frequencies, some connected\ - to a stimulus\n\ - 6. A single sinusoidal generator but with two registration sites\n\ - 7. A presentation of the 3d head model\n\ - 8. A model of a cortical area, based on Jansen and Rit 1995." - -print(welcomeMessage) -userChoice = input("Your choice: ") -print("\n") - -if userChoice == 1: - 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()) -elif userChoice == 2: - 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() -elif userChoice == 3: - 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() -elif userChoice == 4: - 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() -elif userChoice == 5: - 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() -elif userChoice == 6: - 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() -elif userChoice == 7: - exampleHead = Head() - exampleHead.displayHead() -elif userChoice == 8: - # 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 - from pylab import * - for i in range(len(parameter)): - subplot( len(parameter), 1, i+1) - if i==0: - title("Simulations based on Fig. 3 from Jansen and Rit 1995") - ylabel( "C = " + str(parameter[i]) ) - plot(recording[i][firstPointToDisplay:]) - show() -else: - print("No such option unfortunately...") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2009-09-14 00:50:56
|
Revision: 136 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=136&view=rev Author: rgoj Date: 2009-09-14 00:50:41 +0000 (Mon, 14 Sep 2009) Log Message: ----------- * Simulations that presented their output via stdandard output, now print to the output log window. * Removed simulation progress information from the neural mass simulation, because somehow it just won't get displayed in the log window... Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-09-14 00:48:51 UTC (rev 135) +++ trunk/src/PyBrainSim.py 2009-09-14 00:50:41 UTC (rev 136) @@ -49,9 +49,10 @@ class PyBrainSimGUI(wx.App): def OnInit(self): - self.res = xrc.XmlResource("PyBrainSimGUI.xrc") + self.res1 = xrc.XmlResource("PyBrainSimGUI1.xrc") + self.res2 = xrc.XmlResource("PyBrainSimGUI2.xrc") - self.frame = self.res.LoadFrame(None, "menuFrame") + self.frame = self.res1.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")) @@ -62,6 +63,10 @@ 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() + + self.logWindow = self.res2.LoadFrame(None, "outputWindow") + self.log = xrc.XRCCTRL(self.logWindow, "outputLog") + return True def menuButton1(self, control): @@ -75,8 +80,9 @@ 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()) + output = str(exampleExperiment.getRecording()) + self.log.SetValue(output) + self.logWindow.Show() def menuButton2(self, control): exampleHead = Head() @@ -90,8 +96,9 @@ 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() + output = str(exampleExperiment.getRecording()) + self.log.SetValue(output) + self.logWindow.Show() def menuButton3(self, control): exampleHead = Head() @@ -113,8 +120,9 @@ exampleConnection2 = Connection('Con2', exampleHead, exampleStimulus2, exampleGenerator2) exampleExperiment.setRecording(exampleHead.runSimulation(exampleExperiment.getDuration())) - print("\nSimulations resulted in the following recording:") - print exampleExperiment.getRecording() + output = str(exampleExperiment.getRecording()) + self.log.SetValue(output) + self.logWindow.Show() def menuButton4(self, control): exampleHead = Head() @@ -126,14 +134,11 @@ 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): @@ -230,7 +235,6 @@ 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]) @@ -251,7 +255,7 @@ r = [] recording = [ [], [], [], [], [], [] ] parameter = [ 68, 128, 135, 270, 675, 1350 ] - + # Differential equation integration for i in range(len(parameter)): # Preparing the integration @@ -259,7 +263,6 @@ 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]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 16:33:51
|
Revision: 140 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=140&view=rev Author: rgoj Date: 2010-06-27 16:33:45 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Added an example usage of the work in progress dipole single sphere head model. This example will be modified later to actually show something interesting. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 15:56:09 UTC (rev 139) +++ trunk/src/PyBrainSim.py 2010-06-27 16:33:45 UTC (rev 140) @@ -38,11 +38,13 @@ from Head import Head from HeadModel import HeadModel from HeadModelHalfSphere import HeadModelHalfSphere +from HeadModelDipoleSphere import HeadModelDipoleSphere from Experiment import Experiment from Stimulus import Stimulus from StimulusDummy import StimulusDummy from GeneratorDummy import GeneratorDummy from GeneratorNumberIncrementing import GeneratorNumberIncrementing +from GeneratorNoisy import GeneratorNoisy from GeneratorSine import GeneratorSine from Connection import Connection from ConnectionDummy import ConnectionDummy @@ -61,6 +63,7 @@ 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.menuButton9, id=xrc.XRCID("menuButton9")) self.frame.Bind(wx.EVT_BUTTON, self.menuButtonQuit, id=xrc.XRCID("menuButtonQuit")) self.frame.Show() @@ -276,6 +279,38 @@ pylab.plot(recording[i][firstPointToDisplay:]) pylab.show() + def menuButton9(self, control): + # head will hold sources, registrations sites and the head model + head = Head() + + # headModel will be our single sphere head model + headModel = HeadModelDipoleSphere(head, 10.0) + + # We need only one data point per simulation + head.setSamplingFrequency(1) + + # Adding registration sites + head.addRegistrationSite([-numpy.pi/2, numpy.pi/2]) + head.addRegistrationSite([-numpy.pi/4, numpy.pi/2]) + head.addRegistrationSite([0, numpy.pi/2]) + head.addRegistrationSite([numpy.pi/4, numpy.pi/2]) + head.addRegistrationSite([numpy.pi/2, numpy.pi/2]) + + # Adding generators + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + + # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) + simulatedData = numpy.array(head.runSimulation(5)) + + # Add Gaussian noise with mean 0 and variance 1 + electrodeNoise = numpy.random.normal(0, 0.0000001, simulatedData.shape); + simulatedData = simulatedData + electrodeNoise + + print(simulatedData) + + def menuButtonQuit(self, control): self.Exit() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 16:41:35
|
Revision: 141 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=141&view=rev Author: rgoj Date: 2010-06-27 16:41:28 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Changes to dipole source example: ** No noise at level of electrode ** Easy to specify number of evenly spaced electrodes Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 16:33:45 UTC (rev 140) +++ trunk/src/PyBrainSim.py 2010-06-27 16:41:28 UTC (rev 141) @@ -290,24 +290,16 @@ head.setSamplingFrequency(1) # Adding registration sites - head.addRegistrationSite([-numpy.pi/2, numpy.pi/2]) - head.addRegistrationSite([-numpy.pi/4, numpy.pi/2]) - head.addRegistrationSite([0, numpy.pi/2]) - head.addRegistrationSite([numpy.pi/4, numpy.pi/2]) - head.addRegistrationSite([numpy.pi/2, numpy.pi/2]) + nElectrodes = 20 + for i in range(nElectrodes): + head.addRegistrationSite([i*numpy.pi/(nElectrodes-1),numpy.pi/2]) # Adding generators generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) - simulatedData = numpy.array(head.runSimulation(5)) + simulatedData = numpy.array(head.runSimulation(1)) - # Add Gaussian noise with mean 0 and variance 1 - electrodeNoise = numpy.random.normal(0, 0.0000001, simulatedData.shape); - simulatedData = simulatedData + electrodeNoise - print(simulatedData) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 17:14:50
|
Revision: 142 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=142&view=rev Author: rgoj Date: 2010-06-27 17:14:44 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Added a plot to the dipole spherical head model example. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 16:41:28 UTC (rev 141) +++ trunk/src/PyBrainSim.py 2010-06-27 17:14:44 UTC (rev 142) @@ -290,17 +290,25 @@ head.setSamplingFrequency(1) # Adding registration sites - nElectrodes = 20 + nElectrodes = 200 + angles = [] for i in range(nElectrodes): - head.addRegistrationSite([i*numpy.pi/(nElectrodes-1),numpy.pi/2]) + angles.append(i*numpy.pi/(nElectrodes-1) - numpy.pi/2) + head.addRegistrationSite([angles[-1],numpy.pi/2]) - # Adding generators - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, 0, 0, 0], mean=1, stddev=0.1) + # Adding a generator + orientation = 0; + generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, orientation, 0, 0], mean=1, stddev=0.1) # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) simulatedData = numpy.array(head.runSimulation(1)) print(simulatedData) + pylab.plot(angles,simulatedData) + pylab.xlabel("Location of measurement on scalp [radians]") + pylab.ylabel("Potential on scalp [arbitrary units]") + pylab.title("Potential from superficial dipole of orientation " + str(orientation)) + pylab.show() def menuButtonQuit(self, control): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-27 19:43:38
|
Revision: 143 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=143&view=rev Author: rgoj Date: 2010-06-27 19:43:32 +0000 (Sun, 27 Jun 2010) Log Message: ----------- * Preparing for the presentation of dipoles with different rotations in the dipolar model example. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-27 17:14:44 UTC (rev 142) +++ trunk/src/PyBrainSim.py 2010-06-27 19:43:32 UTC (rev 143) @@ -281,33 +281,51 @@ def menuButton9(self, control): # head will hold sources, registrations sites and the head model - head = Head() + head1 = Head() + head2 = Head() + head3 = Head() # headModel will be our single sphere head model - headModel = HeadModelDipoleSphere(head, 10.0) + headModel1 = HeadModelDipoleSphere(head1, 10.0) + headModel2 = HeadModelDipoleSphere(head2, 10.0) + headModel3 = HeadModelDipoleSphere(head3, 10.0) # We need only one data point per simulation - head.setSamplingFrequency(1) + head1.setSamplingFrequency(1) + head2.setSamplingFrequency(1) + head3.setSamplingFrequency(1) # Adding registration sites nElectrodes = 200 angles = [] for i in range(nElectrodes): angles.append(i*numpy.pi/(nElectrodes-1) - numpy.pi/2) - head.addRegistrationSite([angles[-1],numpy.pi/2]) + head1.addRegistrationSite([angles[-1],numpy.pi/2]) + head2.addRegistrationSite([angles[-1],numpy.pi/2]) + head3.addRegistrationSite([angles[-1],numpy.pi/2]) # Adding a generator - orientation = 0; - generator = GeneratorNoisy('Gen', head, position = [ 0.3, 0, orientation, 0, 0], mean=1, stddev=0.1) + orientation1= 0; + orientation2= numpy.pi/2; + orientation3= numpy.pi/4; + generator1 = GeneratorNoisy('Gen', head1, position = [ 0.3, 0, orientation1, 0, 0], mean=1, stddev=0.1) + generator2 = GeneratorNoisy('Gen', head2, position = [ 0.3, 0, orientation2, 0, 0], mean=1, stddev=0.1) + generator3 = GeneratorNoisy('Gen', head3, position = [ 0.3, 0, orientation3, 0, 0], mean=1, stddev=0.1) # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) - simulatedData = numpy.array(head.runSimulation(1)) + simulatedData1 = numpy.array(head1.runSimulation(1)) + simulatedData2 = numpy.array(head2.runSimulation(1)) + simulatedData3 = numpy.array(head3.runSimulation(1)) - print(simulatedData) - pylab.plot(angles,simulatedData) + pylab.subplot(311) + pylab.plot(angles,simulatedData1) + pylab.title("Potential from superficial dipoles of different orientations") + pylab.subplot(312) + pylab.plot(angles,simulatedData2) + pylab.subplot(313) + pylab.plot(angles,simulatedData3) pylab.xlabel("Location of measurement on scalp [radians]") - pylab.ylabel("Potential on scalp [arbitrary units]") - pylab.title("Potential from superficial dipole of orientation " + str(orientation)) + pylab.ylabel("Scalp potential [relative]") pylab.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rg...@us...> - 2010-06-30 08:42:46
|
Revision: 145 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=145&view=rev Author: rgoj Date: 2010-06-30 08:42:36 +0000 (Wed, 30 Jun 2010) Log Message: ----------- * Modyfying the example of the use of the spherical head model to showcase it a little better. Modified Paths: -------------- trunk/src/PyBrainSim.py Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2010-06-30 08:36:31 UTC (rev 144) +++ trunk/src/PyBrainSim.py 2010-06-30 08:42:36 UTC (rev 145) @@ -296,22 +296,25 @@ head3.setSamplingFrequency(1) # Adding registration sites - nElectrodes = 200 + nElectrodes = 201 angles = [] for i in range(nElectrodes): angles.append(i*numpy.pi/(nElectrodes-1) - numpy.pi/2) - head1.addRegistrationSite([angles[-1],numpy.pi/2]) - head2.addRegistrationSite([angles[-1],numpy.pi/2]) - head3.addRegistrationSite([angles[-1],numpy.pi/2]) + head1.addRegistrationSite([angles[-1],0]) + head2.addRegistrationSite([angles[-1],0]) + head3.addRegistrationSite([angles[-1],0]) # Adding a generator orientation1= 0; orientation2= numpy.pi/2; orientation3= numpy.pi/4; - generator1 = GeneratorNoisy('Gen', head1, position = [ 0.3, 0, orientation1, 0, 0], mean=1, stddev=0.1) - generator2 = GeneratorNoisy('Gen', head2, position = [ 0.3, 0, orientation2, 0, 0], mean=1, stddev=0.1) - generator3 = GeneratorNoisy('Gen', head3, position = [ 0.3, 0, orientation3, 0, 0], mean=1, stddev=0.1) + generator1 = GeneratorNoisy('Gen', head1, position = [ 4.0, 0, 0, orientation1, numpy.pi/2], mean=1, stddev=0.0) + generator2 = GeneratorNoisy('Gen', head2, position = [ 4.0, numpy.pi/4, 0, orientation2, numpy.pi/2], mean=1, stddev=0.0) + generator30 = GeneratorNoisy('Gen', head3, position = [ 4.0, 0, 0, orientation1, numpy.pi/2], mean=1, stddev=0.5) + generator31 = GeneratorNoisy('Gen', head3, position = [ 4.0, numpy.pi/4, 0, orientation2, numpy.pi/2], mean=3, stddev=0.5) + generator32 = GeneratorNoisy('Gen', head3, position = [ 4.0, -numpy.pi/4, 0, orientation3, numpy.pi/2], mean=2, stddev=0.5) + # Run the simulation just once (or, equivalently for one second with the sampling rate of 1 Hz) simulatedData1 = numpy.array(head1.runSimulation(1)) simulatedData2 = numpy.array(head2.runSimulation(1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |