示例#1
0
def test_random_unseeded():
    num_seeds = get_num_seeds()

    nngt.seed(msd=42)

    # check that seeds generated by first call indeed allow to reproduce the
    # graph in later calls
    g1 = ng.gaussian_degree(10, 1, nodes=100)

    seeds = nngt.get_config("seeds")

    nngt.seed(msd=42, seeds=seeds)
    g2 = ng.gaussian_degree(10, 1, nodes=100)

    assert np.all(g1.edges_array == g2.edges_array)
示例#2
0
def test_group_vs_type():
    ''' Gaussian degree with groups and types '''
    # first with groups
    nngt.seed(0)

    pop = nngt.NeuralPop.exc_and_inhib(1000)

    igroup = pop["inhibitory"]
    egroup = pop["excitatory"]

    net1 = nngt.Network(population=pop)

    all_groups = list(pop.keys())  # necessary to have same order as types

    avg_e = 50
    std_e = 5
    ng.connect_groups(net1, egroup, all_groups, graph_model="gaussian_degree",
                      avg=avg_e, std=std_e, degree_type="out-degree")

    avg_i = 100
    std_i = 5
    ng.connect_groups(net1, igroup, all_groups, graph_model="gaussian_degree",
                      avg=avg_i, std=std_i, degree_type="out-degree")

    # then with types
    nngt.seed(0)

    pop = nngt.NeuralPop.exc_and_inhib(1000)

    igroup = pop["inhibitory"]
    egroup = pop["excitatory"]

    net2 = nngt.Network(population=pop)

    avg_e = 50
    std_e = 5
    ng.connect_neural_types(net2, 1, [-1, 1], graph_model="gaussian_degree",
                            avg=avg_e, std=std_e, degree_type="out-degree")

    avg_i = 100
    std_i = 5
    ng.connect_neural_types(net2, -1, [-1, 1], graph_model="gaussian_degree",
                            avg=avg_i, std=std_i, degree_type="out-degree")

    # call only on root process (for mpi) unless using distributed backend
    if nngt.on_master_process() or nngt.get_config("backend") == "nngt":
        # check that both networks are equals
        assert np.all(net1.get_degrees() == net2.get_degrees())
示例#3
0
def test_random_seeded():
    num_seeds = get_num_seeds()

    # test equality of graph generated with same seeds
    nngt.seed(msd=0, seeds=[i for i in range(1, num_seeds + 1)])
    g1 = ng.gaussian_degree(10, 1, nodes=100)

    nngt.seed(msd=0, seeds=[i for i in range(1, num_seeds + 1)])
    g2 = ng.gaussian_degree(10, 1, nodes=100)

    assert np.all(g1.edges_array == g2.edges_array)

    # check that subsequent graphs are different
    g3 = ng.gaussian_degree(10, 1, nodes=100)

    # with mpi onnon-distributed backends, test only on master process
    if nngt.get_config("backend") == "nngt" or nngt.on_master_process():
        if g3.edge_nb() == g2.edge_nb():
            assert np.any(g2.edges_array != g3.edges_array)
import matplotlib.pyplot as plt

import nngt
from nngt.geometry import Shape

import pickle
import pdb
print('PDB DEBUGGER ACTIVATED')

# nngt.use_backend("graph-tool")
nngt.use_backend("networkx")

# nngt.set_config({"omp": 8, "palette": 'RdYlBu'})
nngt.set_config("multithreading", False)

nngt.seed(0)
''' Runtime options'''
plot_distribution = True  # plot of the connectivity distribution
plot_graphs = False  # graphic output of spatial network
simulate_activity = True  # whether to run or not a NEST simlation on the model
sim_duration = 2000  # simulation duration in ms
plot_activity = True  # whether to plot simulation activity
animation_movie = True  # wheter to generate activity on map movie
save_spikes = False  # whether to save the spikes of all the neurons
obstacles = True  # set to True for simulation with elevated obstacles

print("\n###################\n Runtime options\n------------------")
print("Plot of the spatial graph  : {0}".format(plot_graphs))
print("Run Nest simulation on the generated graph  : {0}".format(
    simulate_activity))
print("Simulation duration (if True)  : {0}".format(sim_duration))
示例#5
0
import numpy as np

import nngt
import nngt.geospatial as ng

plt.rcParams.update({
    'axes.edgecolor': 'grey',
    'xtick.color': 'grey',
    'ytick.color': 'grey',
    "figure.facecolor": (0, 0, 0, 0),
    "axes.facecolor": (0, 0, 0, 0),
    "axes.labelcolor": "grey",
    "text.color": "grey"
})

nngt.seed(2)

# take random countries
num_nodes = 20

world = ng.maps["adaptive"]
units = nngt._rng.choice(50, num_nodes, replace=False)
codes = list(world.iloc[units].SU_A3)

# make random network
g = nngt.generation.erdos_renyi(nodes=num_nodes, avg_deg=3)

# add the A3 code for each country (that's the crucial part that will link
# the graph to the geospatial data)
g.new_node_attribute("code", "string", codes)