[Pybrainsim-activity] SF.net SVN: pybrainsim:[26] trunk/src
Status: Planning
Brought to you by:
rgoj
From: <rg...@us...> - 2009-07-29 14:42:56
|
Revision: 26 http://pybrainsim.svn.sourceforge.net/pybrainsim/?rev=26&view=rev Author: rgoj Date: 2009-07-29 14:42:44 +0000 (Wed, 29 Jul 2009) Log Message: ----------- * Changing generator names, moving the word "Generator" to the front for better readability Modified Paths: -------------- trunk/src/DummyConnection.py trunk/src/Experiment.py trunk/src/Head.py trunk/src/PyBrainSim.py Added Paths: ----------- trunk/src/GeneratorNumberIncrementing.py trunk/src/GeneratorSine.py trunk/src/GeneratorStimulusActivationZeroing.py Removed Paths: ------------- trunk/src/ActivationZeroingStimulusGenerator.py trunk/src/DummyGenerator.py trunk/src/SineGenerator.py Deleted: trunk/src/ActivationZeroingStimulusGenerator.py =================================================================== --- trunk/src/ActivationZeroingStimulusGenerator.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/ActivationZeroingStimulusGenerator.py 2009-07-29 14:42:44 UTC (rev 26) @@ -1,46 +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/>. - -__metaclass__ = type # New style classes. Is this necessary? - -""" -The ActivationZeroingStimulusGenerator class is a child class of the Generator class. It reimplements the runGenerator method, so that a stimulus can be periodically sent to all connected generators. - -Currently the ActivationZeroingStimulusGenerator class only keeps a counter to remember the number of times it was called. -""" - -from DummyGenerator import DummyGenerator - -class ActivationZeroingStimulusGenerator(DummyGenerator): - def __init__(self): - self.activation = 0 - self.connectedGeneratorOutput = 0 - self.counter = 0 - - def receiveInput(self, input): - self.connectedGeneratorOutput = input - - def runGenerator(self, time): - if self.counter == 10: - self.activation = -self.connectedGeneratorOutput - self.counter = 0 - else: - self.activation = 0 - self.counter += 1 - - return 0 # This is necessary, because the activation of this function is added to the recording in Head.py Modified: trunk/src/DummyConnection.py =================================================================== --- trunk/src/DummyConnection.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/DummyConnection.py 2009-07-29 14:42:44 UTC (rev 26) @@ -32,4 +32,5 @@ def runConnection(self): """Sends the output of the source generator to the target generator, without any changes.""" + print("Running connection...") self.targetGenerator.receiveInput(self.sourceGenerator.sendOutput()) Deleted: trunk/src/DummyGenerator.py =================================================================== --- trunk/src/DummyGenerator.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/DummyGenerator.py 2009-07-29 14:42:44 UTC (rev 26) @@ -1,37 +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/>. - -__metaclass__ = type # New style classes. Is this necessary? - -""" -The DummyGenerator class serves as a starting point for creating complex classes simulation populations of neurons. Although currently all it does is adding integers. -""" - -class DummyGenerator: - def __init__(self): - self.activation = 0 - - def sendOutput(self): - return self.activation - - def receiveInput(self, input): - self.activation += input - - def runGenerator(self, time): - self.activation = self.activation + 1 - return self.activation Modified: trunk/src/Experiment.py =================================================================== --- trunk/src/Experiment.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/Experiment.py 2009-07-29 14:42:44 UTC (rev 26) @@ -27,6 +27,9 @@ self.recording = recording self.stimulusTimes = stimulusTimes + def setRecording(self, recording): + self.recording = recording + def getRecording(self): return self.recording Copied: trunk/src/GeneratorNumberIncrementing.py (from rev 20, trunk/src/DummyGenerator.py) =================================================================== --- trunk/src/GeneratorNumberIncrementing.py (rev 0) +++ trunk/src/GeneratorNumberIncrementing.py 2009-07-29 14:42:44 UTC (rev 26) @@ -0,0 +1,37 @@ +# 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/>. + +__metaclass__ = type # New style classes. Is this necessary? + +""" +The DummyGenerator class serves as a starting point for creating complex classes simulation populations of neurons. Although currently all it does is adding integers. +""" + +class DummyGenerator: + def __init__(self): + self.activation = 0 + + def sendOutput(self): + return self.activation + + def receiveInput(self, input): + self.activation += input + + def runGenerator(self, time): + self.activation = self.activation + 1 + return self.activation Copied: trunk/src/GeneratorSine.py (from rev 22, trunk/src/SineGenerator.py) =================================================================== --- trunk/src/GeneratorSine.py (rev 0) +++ trunk/src/GeneratorSine.py 2009-07-29 14:42:44 UTC (rev 26) @@ -0,0 +1,44 @@ +# 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/>. + +__metaclass__ = type # New style classes. Is this necessary? + +""" +The SineGenerator class is an example generator that simply generates a single sine. +""" + +import math + +class SineGenerator: + def __init__(self, frequency = 1, phaseShift = 0): + self.activation = 0 + self.frequency = frequency + self.phase = phaseShift + self.phaseShift = phaseShift + + def sendOutput(self): + print("Sending output: " + str(self.phase)) + return self.phase + + def receiveInput(self, newPhaseShift): + self.phaseShift = newPhaseShift + + def runGenerator(self, time): + self.phase = (2 * math.pi * self.frequency * time + 2 * math.pi * self.phaseShift) % (2 * math.pi / self.frequency) / (2 * math.pi) + print("Phase is now: " + str(self.phase)) + return math.sin(self.phase * 2 * math.pi) Property changes on: trunk/src/GeneratorSine.py ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/GeneratorStimulusActivationZeroing.py (from rev 20, trunk/src/ActivationZeroingStimulusGenerator.py) =================================================================== --- trunk/src/GeneratorStimulusActivationZeroing.py (rev 0) +++ trunk/src/GeneratorStimulusActivationZeroing.py 2009-07-29 14:42:44 UTC (rev 26) @@ -0,0 +1,46 @@ +# 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/>. + +__metaclass__ = type # New style classes. Is this necessary? + +""" +The ActivationZeroingStimulusGenerator class is a child class of the Generator class. It reimplements the runGenerator method, so that a stimulus can be periodically sent to all connected generators. + +Currently the ActivationZeroingStimulusGenerator class only keeps a counter to remember the number of times it was called. +""" + +from DummyGenerator import DummyGenerator + +class ActivationZeroingStimulusGenerator(DummyGenerator): + def __init__(self): + self.activation = 0 + self.connectedGeneratorOutput = 0 + self.counter = 0 + + def receiveInput(self, input): + self.connectedGeneratorOutput = input + + def runGenerator(self, time): + if self.counter == 10: + self.activation = -self.connectedGeneratorOutput + self.counter = 0 + else: + self.activation = 0 + self.counter += 1 + + return 0 # This is necessary, because the activation of this function is added to the recording in Head.py Modified: trunk/src/Head.py =================================================================== --- trunk/src/Head.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/Head.py 2009-07-29 14:42:44 UTC (rev 26) @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with PyBrainSim. If not, see <http://www.gnu.org/licenses/>. +from __future__ import division __metaclass__ = type # New style classes. Is this necessary? """ @@ -26,7 +27,7 @@ class Head: def __init__(self): - self.samplingFrequency = 128; + self.samplingFrequency = 10; self.generatorList = [] self.generatorSiteList = [] self.connectionList = [] @@ -74,7 +75,8 @@ # Querying all generators and connections for timePoint in range(duration * self.samplingFrequency): for i in range(len(self.generatorList)): - generatorOutput[i] = (self.generatorList[i]).runGenerator(timePoint) + generatorOutput[i] = (self.generatorList[i]).runGenerator(timePoint/self.samplingFrequency) + print("Time: " + str(timePoint/self.samplingFrequency) + ", Generator: " + str(i) + ", Generator Output: " + str(generatorOutput[i])) for i in range(len(self.connectionList)): self.connectionList[i].runConnection() Modified: trunk/src/PyBrainSim.py =================================================================== --- trunk/src/PyBrainSim.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/PyBrainSim.py 2009-07-29 14:42:44 UTC (rev 26) @@ -30,6 +30,7 @@ from SineGenerator import SineGenerator from DummyConnection import DummyConnection from ActivationZeroingStimulusGenerator import ActivationZeroingStimulusGenerator +from PhaseResetStimulusGenerator import PhaseResetStimulusGenerator welcomeMessage = "\n\ Welcome to this early version of PyBrainSim\n\n\ @@ -60,28 +61,32 @@ exampleStimulusToGeneratorConnection = DummyConnection(exampleStimulus, exampleGenerator1) exampleGeneratorToStimulusConnection = DummyConnection(exampleGenerator1, exampleStimulus) + exampleHead.addConnection(exampleStimulusToGeneratorConnection) exampleHead.addConnection(exampleGeneratorToStimulusConnection) - exampleHead.addConnection(exampleStimulusToGeneratorConnection) exampleExperiment = Experiment(exampleHead.runSimulation(1)) print exampleExperiment.getRecording() elif userChoice == 2: + exampleExperiment = Experiment() + exampleExperiment.addStimulusTime(0.2341) + exampleHead = Head() - exampleHead.setSamplingFrequency(32) + exampleHead.setSamplingFrequency(10) exampleHead.addRegistrationSite([0, 0, 0]) exampleGenerator1 = SineGenerator() exampleHead.addGenerator(exampleGenerator1) - #exampleStimulus = ActivationZeroingStimulusGenerator() - #exampleHead.addGenerator(exampleStimulus) + exampleStimulus = PhaseResetStimulusGenerator() + exampleStimulus.setStimulusTimes(exampleExperiment.getStimulusTimes()) + exampleHead.addGenerator(exampleStimulus) - #exampleStimulusToGeneratorConnection = DummyConnection(exampleStimulus, exampleGenerator1) - #exampleGeneratorToStimulusConnection = DummyConnection(exampleGenerator1, exampleStimulus) - #exampleHead.addConnection(exampleGeneratorToStimulusConnection) - #exampleHead.addConnection(exampleStimulusToGeneratorConnection) + exampleStimulusToGeneratorConnection = DummyConnection(exampleStimulus, exampleGenerator1) + exampleGeneratorToStimulusConnection = DummyConnection(exampleGenerator1, exampleStimulus) + exampleHead.addConnection(exampleGeneratorToStimulusConnection) + exampleHead.addConnection(exampleStimulusToGeneratorConnection) - exampleExperiment = Experiment(exampleHead.runSimulation(1)) + exampleExperiment.setRecording(exampleHead.runSimulation(1.1)) print exampleExperiment.getRecording() else: print("No such option unfortunately...") Deleted: trunk/src/SineGenerator.py =================================================================== --- trunk/src/SineGenerator.py 2009-07-29 09:22:28 UTC (rev 25) +++ trunk/src/SineGenerator.py 2009-07-29 14:42:44 UTC (rev 26) @@ -1,37 +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/>. - -__metaclass__ = type # New style classes. Is this necessary? - -""" -The SineGenerator class is an example generator that simply generates a single sine. -""" - -import math - -class SineGenerator: - def __init__(self, frequency = 10, phaseShift = 0): - self.activation = 0 - self.frequency = frequency - self.phaseShift = phaseShift - - def receiveInput(self, newPhaseShift): - self.phaseShift = newPhaseShift - - def runGenerator(self, time): - return math.sin(2 * math.pi / self.frequency * time + 2 * math.pi * self.phaseShift) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |