Exemple #1
0
    def _activate_hln(self, sim, block_interval, firing_rate):
        next_block_tstart = (block_interval[1] +
                             1) * sim.dt  # The next time-step
        next_block_tstop = next_block_tstart + sim.nsteps_block * sim.dt  # The time-step when the next block ends

        # This is where you can use the firing-rate of the low-level neurons to generate a set of spike times for the
        # next block
        psg = PoissonSpikeGenerator()
        psg.add(node_ids=[0],
                firing_rate=firing_rate,
                times=(next_block_tstart, next_block_tstop))
        self._spike_events = psg.get_times(0)

        # Update firing rate of bladder afferent neurons
        for gid in self._high_level_neurons:
            nc = self._netcons[gid]
            for t in self._spike_events:
                nc.event(t)

        # If pressure is maxxed, update firing rate of EUS motor neurons
        # Guarding reflex
        press_change = self._prev_glob_press - self._glob_press
        if self._glob_press > press_thres or press_change > change_thres:
            psg = PoissonSpikeGenerator()
            psg.add(node_ids=[0],
                    firing_rate=150,
                    times=(next_block_tstart, next_block_tstop))
            self._spike_events = psg.get_times(0)

            for gid in self._eus_neurons:
                nc = self._netcons[gid]
                for t in self._spike_events:
                    nc.event(t)
Exemple #2
0
def test_psg_fixed():
    psg = PoissonSpikeGenerator(population='test', seed=100)
    psg.add(node_ids=range(10), firing_rate=5.0, times=(0.0, 3.0))
    assert (psg.populations == ['test'])
    assert (np.all(psg.node_ids() == list(range(10))))
    assert (psg.n_spikes() == 143)
    assert (psg.n_spikes(population='test') == 143)
    assert (np.allclose(psg.time_range(),
                        (5.380662350673328, 2986.5205688893295)))

    df = psg.to_dataframe()
    assert (df.shape == (143, 3))

    assert (np.allclose(psg.get_times(node_id=0), [
        156.7916, 222.0400, 332.5493, 705.1267, 706.0727, 731.9963, 954.1834,
        1303.7542, 1333.1543, 1504.3314, 1948.2045, 1995.1471, 2036.1411,
        2059.0835, 2108.6982, 2877.7935
    ],
                        atol=1.0e-3))

    assert (np.allclose(psg.get_times(node_id=9, population='test'), [
        23.3176, 241.7332, 390.1951, 428.2215, 1001.0229, 1056.4003, 2424.8442,
        2599.6312, 2640.1228, 2737.9504, 2780.0140, 2885.8020
    ],
                        atol=1.0e-3))
Exemple #3
0
    def _activate_hln(self, sim, block_interval, firing_rate):
        next_block_tstart = (block_interval[1] + 1) * sim.dt  # The next time-step
        next_block_tstop = next_block_tstart + sim.nsteps_block*sim.dt  # The time-step when the next block ends

        # This is where you can use the firing-rate of the low-level neurons to generate a set of spike times for the
        # next block
        if firing_rate != 0.0:
            psg = PoissonSpikeGenerator()
            psg.add(node_ids=[0], firing_rate=firing_rate, times=(next_block_tstart/1000.0, next_block_tstop/1000.0))
            if psg.n_spikes() <= 0:
                io.log_info('     _activate_hln: firing rate {} did not produce any spikes'.format(firing_rate))
            else:
                self._spike_events = psg.get_times(0)
                # Update firing rate of bladder afferent neurons
                for gid in self._high_level_neurons:
                    nc = self._netcons[gid]
                    for t in self._spike_events:
                        nc.event(t)
        else:
            io.log_info('     _activate_hln: firing rate 0')

        # If pressure is maxxed, update firing rate of EUS motor neurons 
        # Guarding reflex
        # press_change = self._prev_glob_press - self._glob_press
        # if self._glob_press > press_thres or press_change > change_thres:
            # psg = PoissonSpikeGenerator()
            # eus_fr = self._glob_press*10 + press_change*10 # Assumption: guarding reflex
                                                           # # depends on current pressure
                                                           # # and change from last pressure
            # psg.add(node_ids=[0], firing_rate=eus_fr, times=(next_block_tstart, next_block_tstop))
            # self._spike_events = psg.get_times(0)
            # for gid in self._eus_neurons:
                # nc = self._netcons[gid]
                # for t in self._spike_events:
                    # nc.event(t)
################ Activate higher order based on pressure threshold ##############################

        # if block_interval[1] % 2000 == 1000:  # For fast testing, only add events to every other block
        # if False:  # For testing
        if self._glob_press > self.press_thres:
            io.log_info('      updating pag input')
            psg = PoissonSpikeGenerator()
            print(self.press_thres)

            pag_fr = self.press_thres #change
            psg.add(node_ids=[0], firing_rate=pag_fr, times=(next_block_tstart/1000.0, next_block_tstop/1000.0))
            if psg.n_spikes() <= 0:
                io.log_info('     no psg spikes generated by Poisson distritubtion')
            self._spike_events = psg.get_times(0)
            for gid in self._pag_neurons:
                nc = self._netcons[gid]
                for t in self._spike_events:
                    nc.event(t)
Exemple #4
0
def test_psg_fixed():
    psg = PoissonSpikeGenerator(population='test', seed=0.0)
    psg.add(node_ids=range(10), firing_rate=10.0, times=(0.0, 10.0))
    assert(psg.populations == ['test'])
    assert(psg.nodes() == list(range(10)))

    time_range = psg.time_range()
    assert(0 <= time_range[0] < 1.0)
    assert(9.0 < time_range[1] <= 10.0)

    # This may fail on certain versions
    assert(psg.get_times(node_id=5).size > 10)
    assert(0 < psg.get_times(node_id=8).size < 300)

    for i in range(10):
        spikes = psg.get_times(i)
        assert(np.max(spikes) > 0.1)
Exemple #5
0
def test_psg_variable():
    times = np.linspace(0.0, 3.0, 1000)
    fr = np.exp(-np.power(times - 1.0, 2) / (2 * np.power(.5, 2))) * 5

    psg = PoissonSpikeGenerator(population='test', seed=0.0)
    psg.add(node_ids=range(10), firing_rate=fr, times=times)

    assert (psg.populations == ['test'])
    assert (np.all(psg.node_ids() == list(range(10))))
    assert (psg.n_spikes() == 59)
    assert (np.allclose(psg.time_range(),
                        (0.13932107933711294, 2.9013003727909172)))
    assert (psg.to_dataframe().shape == (59, 3))
    assert (np.allclose(psg.get_times(node_id=0),
                        [0.442, 0.520, 0.640, 1.099, 1.393, 1.725],
                        atol=1.0e-3))
    assert (np.allclose(psg.get_times(node_id=9),
                        [0.729, 0.885, 1.047, 1.276, 1.543, 1.669, 1.881],
                        atol=1.0e-3))
Exemple #6
0
def test_psg_variable():
    times = np.linspace(0.0, 3.0, 1000)
    fr = np.exp(-np.power(times - 1.0, 2) / (2 * np.power(.5, 2))) * 5

    psg = PoissonSpikeGenerator(population='test', seed=0.0)
    psg.add(node_ids=range(10), firing_rate=fr, times=times)

    assert (psg.populations == ['test'])
    assert (np.all(psg.node_ids() == list(range(10))))
    assert (psg.n_spikes() == 59)
    assert (np.allclose(psg.time_range(),
                        (139.32107933711294, 2901.3003727909172)))
    assert (psg.to_dataframe().shape == (59, 3))
    assert (np.allclose(
        psg.get_times(node_id=0),
        [442.8378, 520.3624, 640.3880, 1099.0661, 1393.0794, 1725.6109],
        atol=1.0e-3))
    assert (np.allclose(psg.get_times(node_id=9), [
        729.6267, 885.2469, 1047.7728, 1276.3554, 1543.6557, 1669.9070,
        1881.3605
    ],
                        atol=1.0e-3))
Exemple #7
0
def test_psg_fixed():
    psg = PoissonSpikeGenerator(population='test', seed=100)
    psg.add(node_ids=range(10), firing_rate=5.0, times=(0.0, 3.0))
    assert (psg.populations == ['test'])
    assert (np.all(psg.node_ids() == list(range(10))))
    assert (psg.n_spikes() == 143)
    assert (psg.n_spikes(population='test') == 143)
    assert (np.allclose(psg.time_range(),
                        (0.005380662350673328, 2.9865205688893295)))

    df = psg.to_dataframe()
    assert (df.shape == (143, 3))

    assert (np.allclose(psg.get_times(node_id=0), [
        0.156, 0.222, 0.332, 0.705, 0.706, 0.731, 0.954, 1.303, 1.333, 1.504,
        1.948, 1.995, 2.036, 2.059, 2.108, 2.877
    ],
                        atol=1.0e-3))
    assert (np.allclose(psg.get_times(node_id=9, population='test'), [
        0.0233, 0.241, 0.390, 0.428, 1.001, 1.056, 2.424, 2.599, 2.640, 2.737,
        2.780, 2.885
    ],
                        atol=1.0e-3))
Exemple #8
0
def test_psg_variable():
    times = np.linspace(0.0, 10.0, 1000)
    fr = np.exp(-np.power(times - 5.0, 2) / (2*np.power(.5, 2)))*5

    psg = PoissonSpikeGenerator(population='test', seed=0.0)
    psg.add(node_ids=range(10), firing_rate=fr, times=times)

    assert(psg.populations == ['test'])
    assert(psg.nodes() == list(range(10)))

    for i in range(10):
        spikes = psg.get_times(i)
        assert(len(spikes) > 0)
        assert(1.0 < np.min(spikes))
        assert(np.max(spikes) < 9.0)
Exemple #9
0
    def _activate_hln(self, sim, block_interval, firing_rate):
        next_block_tstart = (block_interval[1] + 1) * sim.dt  # The next time-step
        next_block_tstop = next_block_tstart + sim.nsteps_block*sim.dt  # The time-step when the next block ends

        # This is where you can use the firing-rate of the low-level neurons to generate a set of spike times for the
        # next block
        psg = PoissonSpikeGenerator()
        psg.add(node_ids=[0], firing_rate=firing_rate/1000, times=(next_block_tstart, next_block_tstop))
        self._spike_events = psg.get_times(0)
        
        if self._spike_events.shape[0]==0:
            self._spike_events = np.array((next_block_tstart+0.2,))

        # Update firing rate of bladder afferent neurons
        for gid in self._high_level_neurons:
            nc = self._netcons[gid]
            for t in self._spike_events:
                nc.event(t)
Exemple #10
0
    def _activate_hln(self, sim, block_interval, firing_rate):
        next_block_tstart = (block_interval[1] +
                             1) * sim.dt  # The next time-step
        next_block_tstop = next_block_tstart + sim.nsteps_block * sim.dt  # The time-step when the next block ends
        # TODO: See if we've reached the end of the simulation

        # This is where you can use the firing-rate of the low-level neurons to generate a set of spike times for the
        # next block. For this case I'm just setting the high-level neuron to start bursting
        #if firing_rate > firing_rate_threshold:
        #self._spike_events = np.linspace(next_block_tstart, next_block_tstop, 500)
        psg = PoissonSpikeGenerator()
        psg.add(node_ids=[0],
                firing_rate=firing_rate,
                times=(next_block_tstart, next_block_tstop))
        self._spike_events = psg.get_times(0)

        for gid in self._high_level_neurons:
            nc = self._netcons[gid]
            for t in self._spike_events:
                nc.event(t)
Exemple #11
0
    def _activate_hln(self, sim, block_interval, firing_rate):
        block_length = sim.nsteps_block * sim.dt / 1000.0
        next_block_tstart = (block_interval[1] +
                             1) * sim.dt / 1000.0  # The next time-step
        next_block_tstop = next_block_tstart + block_length  # The time-step when the next block ends

        # This is where you can use the firing-rate of the low-level neurons to generate a set of spike times for the
        # next block
        if firing_rate > 0.0:
            psg = PoissonSpikeGenerator()
            # # Use homogeneous input
            # psg.add(node_ids=[0], firing_rate=firing_rate, times=(next_block_tstart, next_block_tstop)) # sec
            # spikes = psg.get_times([0])*1000 # convert sec to ms
            # n_spikes = len(spikes)
            # io.log_info('     _activate_hln firing rate: {:.2f} Hz'.format(n_spikes/block_length))
            # if n_spikes > 0:
            # # Update firing rate of bladder afferent neurons
            # for gid in self._high_level_neurons:
            # self._spike_events[gid] = np.concatenate((self._spike_events[gid],spikes))
            # nc = self._netcons[gid]
            # for t in spikes:
            # nc.event(t)
            # io.log_info('Last spike: {:.1f} ms'.format(spikes[-1]))
            # Use inhomogeneous input
            n = len(self._high_level_neurons)
            psg.add(node_ids=self._high_level_neurons,
                    firing_rate=firing_rate,
                    times=(next_block_tstart, next_block_tstop))
            n_spikes = np.zeros(n)
            last_spike = 0.0
            for i, gid in enumerate(self._high_level_neurons):
                spikes = psg.get_times(gid) * 1000
                n_spikes[i] = len(spikes)
                if n_spikes[i] > 0:
                    self._spike_events[gid] = np.concatenate(
                        (self._spike_events[gid], spikes))
                    nc = self._netcons[gid]
                    for t in spikes:
                        nc.event(t)
                    last_spike = max(last_spike, spikes[-1])
            io.log_info(
                '     _activate_hln firing rate: ' +
                ','.join(["%.2f" % (ns / block_length)
                          for ns in n_spikes]) + ' Hz')
            if last_spike > 0:
                io.log_info('Last spike: {:.1f} ms'.format(last_spike))
        else:
            io.log_info('     _activate_hln firing rate: 0')

        # If pressure is maxxed, update firing rate of EUS motor neurons
        # Guarding reflex
        # press_change = self._prev_glob_press - self._glob_press
        # if self._glob_press > press_thres or press_change > change_thres:
        # psg = PoissonSpikeGenerator()
        # eus_fr = self._glob_press*10 + press_change*10 # Assumption: guarding reflex
        # # depends on current pressure
        # # and change from last pressure
        # psg.add(node_ids=[0], firing_rate=eus_fr, times=(next_block_tstart, next_block_tstop))
        # self._spike_events = psg.get_times(0)
        # for gid in self._eus_neurons:
        # nc = self._netcons[gid]
        # for t in self._spike_events:
        # nc.event(t)
################ Activate higher order based on pressure threshold ##############################

# if block_interval[1] % 2000 == 1000:  # For fast testing, only add events to every other block
# if False:  # For testing
# if self._glob_press > self.press_thres:
#     io.log_info('      updating pag input')
#     psg = PoissonSpikeGenerator()
#     print(self.press_thres)
#
#     pag_fr = self.press_thres #change
#     psg.add(node_ids=[0], firing_rate=pag_fr, times=(next_block_tstart/1000.0, next_block_tstop/1000.0))
#     if psg.n_spikes() <= 0:
#         io.log_info('     no psg spikes generated by Poisson distritubtion')
#     self._spike_events = psg.get_times(0)
#     for gid in self._pag_neurons:
#         nc = self._netcons[gid]
#         for t in self._spike_events:
#             nc.event(t)
################ Activate higher order based on afferent firing rate ##############################
        if firing_rate > 10:
            pag_fr = 15
            psg = PoissonSpikeGenerator()
            # # Use homogeneous input
            # psg.add(node_ids=[0], firing_rate=pag_fr, times=(next_block_tstart, next_block_tstop))
            # spikes = psg.get_times([0])*1000
            # n_spikes = len(spikes)
            # io.log_info('     pag firing rate: {:.2f} Hz'.format(n_spikes/block_length))
            # if n_spikes>0:
            # io.log_info('Last spike: {:.1f} ms'.format(spikes[-1]))
            # for gid in self._pag_neurons:
            # self._spike_events[gid] = np.concatenate((self._spike_events[gid],spikes))
            # nc = self._netcons[gid]
            # for t in spikes:
            # nc.event(t)
            # Use inhomogeneous input
            n = len(self._pag_neurons)
            psg.add(node_ids=self._pag_neurons,
                    firing_rate=pag_fr,
                    times=(next_block_tstart, next_block_tstop))
            n_spikes = np.zeros(n)
            last_spike = 0.0
            for i, gid in enumerate(self._pag_neurons):
                spikes = psg.get_times(gid) * 1000
                n_spikes[i] = len(spikes)
                if n_spikes[i] > 0:
                    self._spike_events[gid] = np.concatenate(
                        (self._spike_events[gid], spikes))
                    nc = self._netcons[gid]
                    for t in spikes:
                        nc.event(t)
                    last_spike = max(last_spike, spikes[-1])
            io.log_info(
                '     pag firing rate: ' +
                ','.join(["%.2f" % (ns / block_length)
                          for ns in n_spikes]) + ' Hz')
            if last_spike > 0:
                io.log_info('Last spike: {:.1f} ms'.format(last_spike))

        io.log_info('\n')