예제 #1
0
    def test_lif_current(self):
        """
        Simulates one LIF neuron and checks the membrane-potential trace matches
        reference data.

        TODO add assertion on comparison, rather than just graphing the result.
        TODO take parameter for machine hostname.
        """
        print "test_lif_current..."
        pynn.setup(**{'machine':'bluu', 'debug':False}) #TODO take machine parameter
        lif = {"v_rest":-70.0, "v_reset":-70.0, "v_thresh":-50.0,  # mV
               "tau_m":40.0, "tau_syn_E":20.0, "tau_syn_I":5.0,    # mS
               "tau_refrac":1.0, "cm":40.0/50.0, "i_offset":0.0}   # ms, nF, nA
        pop = pynn.Population(1, pynn.IF_curr_exp, lif)
        pop.set("i_offset", 0.5)
        pop.record_v()
        pynn.run(1000)

        with open('data/test_lif_current.pickle', 'r') as f:
            data = f.read()
            trace = pickle.loads(data)

        fig = pylab.figure(figsize=(8.0, 5.7))
        ax = fig.add_subplot(1,1,1)
        ax.plot(pop.get_v()[:,2])
        ax.plot(trace)

        pylab.show()
        pynn.end()
예제 #2
0
    def test_lif_current(self):
        """
        Simulates one LIF neuron and checks the membrane-potential trace matches
        reference data.

        TODO add assertion on comparison, rather than just graphing the result.
        TODO take parameter for machine hostname.
        """
        print "test_lif_current..."
        pynn.setup(**{
            'machine': 'bluu',
            'debug': False
        })  #TODO take machine parameter
        lif = {
            "v_rest": -70.0,
            "v_reset": -70.0,
            "v_thresh": -50.0,  # mV
            "tau_m": 40.0,
            "tau_syn_E": 20.0,
            "tau_syn_I": 5.0,  # mS
            "tau_refrac": 1.0,
            "cm": 40.0 / 50.0,
            "i_offset": 0.0
        }  # ms, nF, nA
        pop = pynn.Population(1, pynn.IF_curr_exp, lif)
        pop.set("i_offset", 0.5)
        pop.record_v()
        pynn.run(1000)

        with open('data/test_lif_current.pickle', 'r') as f:
            data = f.read()
            trace = pickle.loads(data)

        fig = pylab.figure(figsize=(8.0, 5.7))
        ax = fig.add_subplot(1, 1, 1)
        ax.plot(pop.get_v()[:, 2])
        ax.plot(trace)

        pylab.show()
        pynn.end()
    def test_pynn_basic(self):
        pass
        """
        TODO figure out how to take machine name as a parameter
        """
        print "test_pynn_basic setup....."
        pynn.setup(**{'machine': 'spinn-7'})

        n_atoms = 10

        proj1_params = {
            'source': None,
            'delays': 1,
            'weights': 1,
            'target': 'excitatory'
        }
        proj2_params = {
            'allow_self_connections': True,
            'delays': 2,
            'p_connect': 0.1,
            'weights': 2,
            'source': None,
            'target': None
        }

        cell_params = {
            'tau_m': 64,
            'v_init': -75,
            'i_offset': 0,
            'v_rest': -75,
            'v_reset': -95,
            'v_thresh': -40,
            'tau_syn_E': 15,
            'tau_syn_I': 15,
            'tau_refrac': 10
        }

        pop1 = pynn.Population(n_atoms,
                               pynn.IF_curr_exp,
                               cell_params,
                               label='pop1')
        pop2 = pynn.Population(n_atoms * 2,
                               pynn.IF_curr_exp,
                               cell_params,
                               label='pop2')

        proj1 = pynn.Projection(pop1,
                                pop2,
                                pynn.OneToOneConnector(weights=1, delays=1),
                                target='excitatory')
        proj2 = pynn.Projection(
            pop1, pop2,
            pynn.FixedProbabilityConnector(weights=2, delays=2, p_connect=.1))

        pynn.controller.map_model()  # at this stage the model is mapped
        print "checking vertices..."
        self.assertEqual(pop1.vertex.parameters, cell_params)
        self.assertEqual(pynn.controller.dao.vertices[1].parameters,
                         cell_params)

        self.assertEqual(pop1.vertex.model,
                         pacman103.front.pynn.models.IF_curr_exp)
        self.assertEqual(pynn.controller.dao.vertices[0].label, "pop1")
        self.assertEqual(pynn.controller.dao.vertices[1].label, "pop2")

        self.assertEqual(pop1.vertex.atoms, n_atoms)
        self.assertEqual(pynn.controller.dao.vertices[1].atoms, n_atoms * 2)

        print "checking edges..."
        self.assertEqual(pynn.controller.dao.edges[0].model,
                         pacman103.front.pynn.connectors.OneToOneConnector)
        self.assertEqual(
            proj2.edge.model,
            pacman103.front.pynn.connectors.FixedProbabilityConnector)

        self.assertEqual(proj1.edge.parameters, proj1_params)
        self.assertEqual(pynn.controller.dao.edges[1].parameters, proj2_params)

        # testing the mapping phase
        self.assertEqual(len(pynn.controller.dao.subedges), 2)
        self.assertEqual(len(pynn.controller.dao.subvertices), 2)

        self.assertEqual(len(pynn.controller.dao.routings), 2)

        #        pynn.run(100)
        pynn.end()
# Dump data
#pre_pop.printSpikes("results/stdp_pre.spikes")
#post_pop.printSpikes("results/stdp_post.spikes")
#pre_pop.print_v("results/stdp_pre.v")
#post_pop.print_v("results/stdp_post.v")

def plot_spikes(spikes, title):
  if spikes != None:
      pylab.figure()
      pylab.xlim((0, sim_time))
      pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") 
      pylab.xlabel('Time/ms')
      pylab.ylabel('spikes')
      pylab.title(title)
     
  else:
      print "No spikes received"

pre_spikes = pre_pop.getSpikes(compatible_output=True)
post_spikes = post_pop.getSpikes(compatible_output=True)

plot_spikes(pre_spikes, "pre-synaptic")
plot_spikes(post_spikes, "post-synaptic")
IPython.embed()
pylab.show()


# End simulation on SpiNNaker
sim.end()
예제 #5
0
    pylab.show()
else:
    print "No spikes received"

# Make some graphs

if v != None:
    ticks = len(v) / nNeurons
    pylab.figure()
    pylab.xlabel('Time/ms')
    pylab.ylabel('v')
    pylab.title('v')
    for pos in range(0, nNeurons, 20):
        v_for_neuron = v[pos * ticks:(pos + 1) * ticks]
        pylab.plot([i[1] for i in v_for_neuron], [i[2] for i in v_for_neuron])
    pylab.show()

if gsyn != None:
    ticks = len(gsyn) / nNeurons
    pylab.figure()
    pylab.xlabel('Time/ms')
    pylab.ylabel('gsyn')
    pylab.title('gsyn')
    for pos in range(0, nNeurons, 20):
        gsyn_for_neuron = gsyn[pos * ticks:(pos + 1) * ticks]
        pylab.plot([i[1] for i in gsyn_for_neuron],
                   [i[2] for i in gsyn_for_neuron])
    pylab.show()

p.end()
spikes = populations[0].getSpikes(compatible_output=True)

if spikes != None:
    pylab.figure()
    pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") 
    pylab.xlabel('Time/ms')
    pylab.ylabel('spikes')
    pylab.title('spikes')
    pylab.show()
else:
    print "No spikes received"

# Make some graphs
ticks = len(v) / nNeurons

if v != None:
    pylab.figure()
    pylab.xlabel('Time/ms')
    pylab.ylabel('v')
    pylab.title('v')
    print v
    for pos in range(0, nNeurons, 20):
    #for pos in range(0, nNeurons):
        v_for_neuron = v[pos * ticks : (pos + 1) * ticks]
        print v_for_neuron
        pylab.plot([i[1] for i in v_for_neuron], 
                [i[2] for i in v_for_neuron])
    pylab.show()

p.end()
    def test_pynn_basic(self):
        pass
        """
        TODO figure out how to take machine name as a parameter
        """
        print "test_pynn_basic setup....."
        pynn.setup(**{"machine": "spinn-7"})

        n_atoms = 10

        proj1_params = {"source": None, "delays": 1, "weights": 1, "target": "excitatory"}
        proj2_params = {
            "allow_self_connections": True,
            "delays": 2,
            "p_connect": 0.1,
            "weights": 2,
            "source": None,
            "target": None,
        }

        cell_params = {
            "tau_m": 64,
            "v_init": -75,
            "i_offset": 0,
            "v_rest": -75,
            "v_reset": -95,
            "v_thresh": -40,
            "tau_syn_E": 15,
            "tau_syn_I": 15,
            "tau_refrac": 10,
        }

        pop1 = pynn.Population(n_atoms, pynn.IF_curr_exp, cell_params, label="pop1")
        pop2 = pynn.Population(n_atoms * 2, pynn.IF_curr_exp, cell_params, label="pop2")

        proj1 = pynn.Projection(pop1, pop2, pynn.OneToOneConnector(weights=1, delays=1), target="excitatory")
        proj2 = pynn.Projection(pop1, pop2, pynn.FixedProbabilityConnector(weights=2, delays=2, p_connect=0.1))

        pynn.controller.map_model()  # at this stage the model is mapped
        print "checking vertices..."
        self.assertEqual(pop1.vertex.parameters, cell_params)
        self.assertEqual(pynn.controller.dao.vertices[1].parameters, cell_params)

        self.assertEqual(pop1.vertex.model, pacman103.front.pynn.models.IF_curr_exp)
        self.assertEqual(pynn.controller.dao.vertices[0].label, "pop1")
        self.assertEqual(pynn.controller.dao.vertices[1].label, "pop2")

        self.assertEqual(pop1.vertex.atoms, n_atoms)
        self.assertEqual(pynn.controller.dao.vertices[1].atoms, n_atoms * 2)

        print "checking edges..."
        self.assertEqual(pynn.controller.dao.edges[0].model, pacman103.front.pynn.connectors.OneToOneConnector)
        self.assertEqual(proj2.edge.model, pacman103.front.pynn.connectors.FixedProbabilityConnector)

        self.assertEqual(proj1.edge.parameters, proj1_params)
        self.assertEqual(pynn.controller.dao.edges[1].parameters, proj2_params)

        # testing the mapping phase
        self.assertEqual(len(pynn.controller.dao.subedges), 2)
        self.assertEqual(len(pynn.controller.dao.subvertices), 2)

        self.assertEqual(len(pynn.controller.dao.routings), 2)

        #        pynn.run(100)
        pynn.end()