Esempio n. 1
0
'''
pop = nngt.NeuralPop.from_groups([oscill, burst, adapt],
                                 names=['oscillators', 'bursters', 'adaptive'],
                                 syn_spec=synapses)
'''
Create the network from this population,
using a Gaussian in-degree
'''
net = ng.gaussian_degree(100., 15., population=pop, weights=155., delays=5.)
'''
Send the network to NEST, monitor and simulate
'''
if nngt.get_config('with_nest'):
    import nngt.simulation as ns
    import nest

    nest.ResetKernel()

    nest.SetKernelStatus({'local_num_threads': 4})

    gids = net.to_nest()

    nngt.simulation.randomize_neural_states(net, {"w": ("uniform", 0, 200)})

    recorders, records = ns.monitor_groups(pop.keys(), net)

    nest.Simulate(1600.)

    if nngt.get_config('with_plot'):
        ns.plot_activity(recorders, records, network=net, show=True)
Esempio n. 2
0
Send to NEST and set excitation and recorders
'''
if nngt.get_config('with_nest'):
    import nest
    import nngt.simulation as ns

    nest.ResetKernel()

    gids = net.to_nest()

    # add noise to the excitatory neurons
    excs = list(pop["excitatory"].nest_gids)
    ns.set_noise(excs, 10., 2.)

    # record
    groups = [key for key in net.population]
    recorder, record = ns.monitor_groups(groups, net)
    '''
    Simulate and plot.
    '''
    simtime = 2000.
    nest.Simulate(simtime)

    if nngt.get_config('with_plot'):
        ns.plot_activity(recorder,
                         record,
                         network=net,
                         show=True,
                         hist=False,
                         limits=(0, simtime))
Esempio n. 3
0
    def simulate(self, simtime, mbis=None, show=False, sort=None):
        '''
        Simulate the activity.

        Parameters
        ----------
        simtime : double
            Duration of the simulation in ms.
        mbis : double, optional (default: None)
            Maximal interval between 2 consecutive spikes to consider them as
            belonging to the same burst. If not specified, it will be set as
            `1.5 * delay`.
        show : bool, optional (default: False)
            Whether the resulting activity should be displayed (available only
            if the NNGT package is present).
        sort : :obj:`str`, optional (default: None)
            Sort neurons depending on a given property (available only
            if the NNGT package is present and simulator was created using
            the ``from_nngt_network`` method).

        See also
        --------
        :func:`nngt.simulation.plot_activity`.
        '''
        mbis = 1.5 * self._params['delay'] if mbis is None else mbis
        self.simtime = simtime
        # check that the neurons are out of equilibrium
        out_of_eq = _plib.out_of_eq_aeif(self._adim_params)
        if out_of_eq:
            try:
                nest.Simulate(simtime)
                if show:
                    from nngt.simulation import plot_activity
                    self.fignums = plot_activity(self.recorders,
                                                 self.record,
                                                 show=False,
                                                 network=self.network,
                                                 gids=self.gids,
                                                 hist=False,
                                                 sort=sort,
                                                 limits=(0, simtime))
                else:
                    self.fignums = None
                self.activity = activity_types(
                    spike_detector=self.recorders[0],
                    limits=(0., simtime),
                    network=self.network,
                    mbis=mbis,
                    fignums=self.fignums,
                    show=show)
                self.phases = self.activity.phases
                self.simulated = True
            except Exception as e:
                if self.ignore_errors:
                    print(e)
                else:
                    raise
        else:
            raise RuntimeError("Parameters lead to stable equilibrium.")
        if not self.simulated:
            self.phases = {
                "network_burst": [],
                "mixed": [],
                "quiescent": [],
                "local_burst": []
            }
Esempio n. 4
0
                                  "delay": delay
                              })

    ns.set_minis(net, base_rate=0.1)

    recorders, records = ns.monitor_groups(["excitatory", "inhibitory"],
                                           network=net)

    nest.Simulate(simtime)

    if nngt.get_config('with_plot'):
        ideg = net.get_degrees("in", syn_type="inhibitory")
        edeg = net.get_degrees("in", syn_type="excitatory")

        # plot the basic activity
        ns.plot_activity(recorders, records, network=net, show=False)
        # sort by firing rate
        ns.plot_activity(recorders,
                         records,
                         network=net,
                         sort="firing_rate",
                         show=False)
        # by in-degree (not working)
        ns.plot_activity(recorders,
                         records,
                         network=net,
                         sort="in-degree",
                         show=False)
        # k_e - k_i (good)
        ns.plot_activity(recorders,
                         records,
def activity_simulation(net, pop, sim_duration=sim_duration):
    '''
    Execute activity simulation on the generated graph
    --------------------------------------------------
    Input :   net : nngt generated graph with model
            pop : neurons population
            sim_duration : time (s) duration of simulation

    Output :
            activity graphs
    '''
    if (nngt.get_config('with_nest')) and (simulate_activity is True):
        print("SIMULATE ACTIVITY")
        import nngt.simulation as ns
        import nest

        nest.ResetKernel()
        nest.SetKernelStatus({'local_num_threads': 14})
        nest.SetKernelStatus({'resolution': .5})

        gids = net.to_nest()

        # nngt.simulation.randomize_neural_states(net, {"w": ("uniform", 0, 200),
        #  "V_m": ("uniform", -70., -40.)})

        nngt.simulation.randomize_neural_states(net, {
            "w": ("normal", 50., 5.),
            "V_m": ("uniform", -80., -50.)
        })
        # add noise to the excitatory neurons
        excs = list(gids)
        # ns.set_noise(excs, 10., 2.)
        # ns.set_poisson_input(gids, rate=3500., syn_spec={"weight": 34.})
        target_rate = 25.

        # 2019 11 13 OLD VERSION TO THIS DATE
        # According to Mallory nngt now dealse differently with
        # minis-rate and weight, automatically normalizing with the degree

        average_degree = net.edge_nb() / float(net.node_nb())
        syn_rate = target_rate / average_degree
        print("syn_rate", syn_rate)
        print("avg_deg", average_degree)
        # ns.set_minis(net, base_rate=syn_rate, weight=.4, gids=gids

        ns.set_minis(net,
                     base_rate=target_rate,
                     weight=.4 * synaptic_weigth,
                     gids=gids)

        vm, vs = ns.monitor_nodes([1, 10], "voltmeter")
        recorders, records = ns.monitor_groups(pop.keys(), net)

        nest.Simulate(sim_duration)

        if plot_activity is True:
            print("Plot raster")
            ns.plot_activity(vm, vs, network=net, show=False)
            ns.plot_activity(recorders,
                             records,
                             network=net,
                             show=False,
                             histogram=True)
        plt.show()
        if animation_movie is True:
            print("Process animation")
            anim = nngt.plot.AnimationNetwork(recorders,
                                              net,
                                              resolution=0.1,
                                              interval=20,
                                              decimate=-1)
            # ~ anim.save_movie("structured_bursting.mp4", fps=2, start=650.,
            # ~ stop=1500, interval=20)
            # ~ anim.save_movie("structured_bursting.mp4", fps=5, num_frames=50)
            anim.save_movie("structured_bursting.mp4", fps=15, interval=10)

        if save_spikes is True:
            print("Save sikes of neurons")
            nngt.simulation.save_spikes("spikes_output.dat")
Esempio n. 6
0
def test_utils():
    '''
    Check NEST utility functions
    '''
    nest = pytest.importorskip("nest")

    import nngt.simulation as ns

    nest.ResetKernel()

    resol = nest.GetKernelStatus('resolution')

    w = 5.

    net, gids = make_nest_net(100, w, deg=10)

    # set inputs
    ns.set_noise(gids, 0., 20.)

    assert len(nest.GetConnections()) == net.edge_nb() + net.node_nb()

    ns.set_poisson_input(gids, 5.)

    assert len(nest.GetConnections()) == net.edge_nb() + 2 * net.node_nb()

    ns.set_minis(net, base_rate=1.5, weight=2.)

    assert len(nest.GetConnections()) == net.edge_nb() + 3 * net.node_nb()

    ns.set_step_currents(gids[::2], times=[40., 60.], currents=[800., 0.])

    min_conn = net.edge_nb() + 3 * net.node_nb() + 1
    max_conn = net.edge_nb() + 4 * net.node_nb()

    num_conn = len(nest.GetConnections())

    assert min_conn <= num_conn <= max_conn

    # check randomization of neuronal properties
    vms = {d['V_m'] for d in nest.GetStatus(gids)}

    assert len(vms) == 1

    ns.randomize_neural_states(net, {'V_m': ('uniform', -70., -60.)})

    vms = {d['V_m'] for d in nest.GetStatus(gids)}

    assert len(vms) == net.node_nb()

    # monitoring nodes
    sd, _ = ns.monitor_groups(net.population, net)

    assert len(nest.GetConnections()) == num_conn + net.node_nb()

    vm, rec = ns.monitor_nodes(gids[0],
                               nest_recorder='voltmeter',
                               params={'interval': resol})

    assert len(nest.GetConnections()) == num_conn + net.node_nb() + 1

    nest.Simulate(100.)

    ns.plot_activity(show=False)

    ns.plot_activity(vm, rec, show=True)
Esempio n. 7
0
#

subnet, gids = make_nest_network(graph)

recorders, record = monitor_nodes(gids, ["spike_detector"], [["spikes"]], network=graph)
recorders2, record2 = monitor_nodes((gids[0],), ["multimeter"], [["V_m","w"]])

set_noise(gids, 0., 200.)

rate = 20000.
if nmodel == "aeif_cond_exp":
    rate = 56000.

#~ set_poisson_input(gids[670:870], rate)
set_poisson_input(gids[:800], rate)
set_poisson_input(gids[800:], 0.75*rate)


#-----------------------------------------------------------------------------#
# Names
#------------------------
#

simtime = 1500.
nest.Simulate(simtime)

fignums = plot_activity(recorders, record, network=graph, show=False, hist=False, limits=(0,simtime))
#~ activity_types(graph, recorders, (0,simtime), raster=fignums[0], simplify=False)
activity_types(graph, recorders, (0,simtime), raster=fignums[0], simplify=True)