Exemple #1
0
def test_simulation_copy():
    b1 = ExternalPopulation(100)
    i1 = InternalPopulation(v_min=0, v_max=0.02)
    b1_i1 = Connection(b1, i1, 2, weights=0.005)
    o1 = Network([b1, i1], [b1_i1])
    o2 = o1.copy()
    compare(o1, o2)
Exemple #2
0
def test_simulation_copy():
    b1 = ExternalPopulation(100)
    i1 = InternalPopulation(v_min=0, v_max=.02)
    b1_i1 = Connection(b1, i1, 2, weights=.005)
    o1 = Network([b1, i1], [b1_i1])
    o2 = o1.copy()
    compare(o1, o2)
Exemple #3
0
def test_network_df():
    p1 = ExternalPopulation(100, record=True)
    p2 = ExternalPopulation(200, record=False)
    p3 = InternalPopulation(v_min=0, v_max=0.02, metadata={"X": 0})
    p4 = InternalPopulation(v_min=0, v_max=0.01, metadata={"X": 0})
    n1 = Network(population_list=[p1, p2, p3, p4])

    print n1.to_df()
def test_network_df():
    p1 = ExternalPopulation(100, record=True)
    p2 = ExternalPopulation(200, record=False)
    p3 = InternalPopulation(v_min=0, v_max=.02, metadata={'X': 0})
    p4 = InternalPopulation(v_min=0, v_max=.01, metadata={'X': 0})
    n1 = Network(population_list=[p1, p2, p3, p4])

    print n1.to_df()
Exemple #5
0
def get_leak_matrix(internal_population, sparse=False):
    
    internal_population_copy = internal_population.copy()
    network = Network([internal_population_copy], [])
    network.dt = 1.
    network.t0 = 1.
    network.ti = 1.
    internal_population_copy.initialize()
    
    if sparse == False:
        return internal_population_copy.leak_flux_matrix_dict['dense'].copy()
    else:
        return spsp.csc_matrix(internal_population_copy.leak_flux_matrix_dict['dense'])
Exemple #6
0
def test_general_interface():
    
    # Settings:
    t0 = 0.
    dt = .001
    tf = .01
    
    # Run simulation:
    b1 = ODE(lambda y, t:(100-t)/.1)
    i1 = PopulationInterface()
    b1_i1 = Connection(b1, i1, 1, weights=.005)
    
    network = Network([b1, i1], [b1_i1])
    network.run(dt, tf=tf, t0=t0)
    np.testing.assert_almost_equal(b1.curr_firing_rate, 9.99949999997, 10) 
Exemple #7
0
def get_singlepop_benchmark_network(scale=2):

    from dipde.internals.internalpopulation import InternalPopulation
    from dipde.internals.externalpopulation import ExternalPopulation
    from dipde.internals.network import Network
    from dipde.internals.connection import Connection as Connection

    # Settings:
    dv = .0001
    update_method = 'approx'
    approx_order = None
    tol = 1e-14

    # Run simulation:
    b_list = []
    i_list = []
    conn_list = []
    for _ in range(scale):
        b = ExternalPopulation(100, record=True)
        i = InternalPopulation(v_min=0,
                               v_max=.02,
                               dv=dv,
                               update_method=update_method,
                               approx_order=approx_order,
                               tol=tol)
        c = Connection(b, i, 1, weights=.005)
        b_list += [b]
        i_list += [i]
        conn_list += [c]
    return Network(b_list + i_list, conn_list)
Exemple #8
0
def singlepop(steady_state, tau_m=.02, p0=((0.,),(1.,)), weights={'distribution':'delta', 'loc':.005}, bgfr=100, network_update_callback=lambda s: None, update_method='approx', simulation_configuration=None, tol=None):
    
    # Settings:
    t0 = 0.
    dt = .001
    dv = .001
    v_min = -.01
    v_max = .02
    tf = .1
    
    # Create simulation:
    b1 = ExternalPopulation(bgfr)
    i1 = InternalPopulation(v_min=v_min, tau_m=tau_m, v_max=v_max, dv=dv, update_method=update_method, p0=p0, tol=tol)
    b1_i1 = Connection(b1, i1, 1, weights=weights)
    network = Network([b1, i1], [b1_i1], update_callback=network_update_callback)
    if simulation_configuration is None:
        simulation_configuration = SimulationConfiguration(dt, tf, t0=t0)
    simulation = Simulation(network=network, simulation_configuration=simulation_configuration)
    simulation.run()
    b1.plot()
    
    i1.plot_probability_distribution()
    i1.plot()
    assert i1.n_edges == i1.n_bins+1 

    # Test steady-state:    
    np.testing.assert_almost_equal(i1.get_firing_rate(.05), steady_state, 12)
def get_simulation(dv=.001, update_method='exact', approx_order=None, tol=1e-8):

    # Create simulation:
    b1 = ExternalPopulation('100+50*abs(sin(40*t))')
    i1 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
    b1_i1 = Connection(b1, i1, 1, weights=.005, delays=0.0)
    simulation = Network([b1, i1], [b1_i1])

    return simulation
Exemple #10
0
def test_get_J():

    # Settings:
    bgfr=100
    update_method='approx'
    weights={'distribution':'delta', 'loc':.005}
    p0=((0.,),(1.,)) 
    tau_m=.02
    dv = .001
    v_min = -.01
    v_max = .02
    
    # Create simulation:
    b1 = ExternalPopulation(bgfr)
    i1 = InternalPopulation(v_min=v_min, tau_m=tau_m, v_max=v_max, dv=dv, update_method=update_method, p0=p0)
    b1_i1 = Connection(b1, i1, 1, weights=weights)
    network = Network([b1, i1], [b1_i1])
    network.get_total_flux_matrix(i1,.001)
def get_network(dv=.001, verbose=False, update_method='approx', approx_order=1, tol=1e-14):

    # Create network:
    b1 = ExternalPopulation('100')
    i1 = InternalPopulation(v_min=-.02, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
    b1_i1 = Connection(b1, i1, 1, weights=.005, delays=([.005, .01],[.5,.5]))
    b1_i1_2 = Connection(b1, i1, 1, weights=-.005, delays=sps.uniform(0,.01))
    network = Network([b1, i1], [b1_i1, b1_i1_2])
    
    return network
Exemple #12
0
def get_connection_flux_matrices(connection, sparse=False):

    target_population_copy = connection.target.copy()
    network = Network([target_population_copy], [])
    network.dt = 1.
    network.t0 = 1.
    network.ti = 1.
    target_population_copy.initialize()

    conn_dist = ConnectionDistribution(target_population_copy.edges, connection.weights, connection.probs)
    conn_dist.initialize()
    
    if sparse == False:
        flux_matrix = conn_dist.flux_matrix_dict['dense'].copy()
    else:
        flux_matrix = spsp.csc_matrix(conn_dist.flux_matrix_dict['dense'])
    flux_vector = conn_dist.threshold_flux_vector.copy()
     
    return flux_matrix, flux_vector
Exemple #13
0
def test_delay_distribution():

    # Settings:
    t0 = 0.
    dt = .001
    tf = .1
    
    # Create populations:
    b1 = ExternalPopulation('100*Heaviside(t)')
    i1 = InternalPopulation(v_min=0, v_max=.02, dv=.001, update_method='exact')
    
    # Create connections:
    b1_i1 = Connection(b1, i1, 1, weights=.005, delays=((0,.05),(.5,.5)))
    
    # Create and run simulation:
    simulation = Network([b1, i1], [b1_i1])
    simulation.run(dt=dt, tf=tf, t0=t0)
    
    true_ans = np.array([0.38560647739319964, 5.229266329159536])
    np.testing.assert_almost_equal(np.array(i1.get_firing_rate([.04, .09])), true_ans, 8)
Exemple #14
0
def test_delay_singlepop():

    # Settings:
    t0 = 0.
    dt = .001
    tf = .005
    
    # Create simulation:
    b1 = ExternalPopulation('Heaviside(t)*100')
    i1 = InternalPopulation(v_min=0, v_max=.02, dv=.001, update_method='exact')
    b1_i1 = Connection(b1, i1, 1, weights=.005, delays=2*dt, delay_queue=[0,0,50])
    
#     # DEBUG:
#     b1_i1 = Connection(b1, i1, 1, weights=.005, delays=((0,.001, .002),(0,0,1.)), delay_queue=[0,0,50])
    
    
    simulation = Network([b1, i1], [b1_i1])
    simulation.run(dt=dt, tf=tf, t0=t0)
    
    true_ans = np.array([0, 0.0, 0.0, 0.00066516669656511084, 0.025842290308637855, 0.08117342489138904])
    np.testing.assert_almost_equal(i1.firing_rate_record, true_ans, 12)
Exemple #15
0
def test_general_interface():
    
    # Settings:
    t0 = 0.
    dt = .001
    tf = .01
    
    # Run simulation:
    b1 = ODE(lambda y, t:(100-t)/.1)
    i1 = PopulationInterface()
    b1_i1 = Connection(b1, i1, 1, weights=.005)
        
    network = Network([b1, i1], [b1_i1])
    network.run(dt, tf=tf, t0=t0)
    
    # Tests:
    final_firing_rate = 9.99949999997
    np.testing.assert_almost_equal(b1.curr_firing_rate, final_firing_rate, 10)
    np.testing.assert_almost_equal(i1.source_firing_rate_dict[0], final_firing_rate, 10)
    assert len(i1.source_connection_list) == 1
    assert i1.source_connection_list[0] == b1_i1
Exemple #16
0
def get_multipop_model():

    # Settings:
    dv = .001
    update_method = 'approx'
    approx_order = None
    tol = 1e-14
    
    
    # Create simulation:
    b1 = ExternalPopulation(100)
    b2 = ExternalPopulation(50)
    i1 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
    i2 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
    b1_i1 = Connection(b1, i1, 1, weights=.005)
    i1_i2 = Connection(i1, i2, 20, weights=.005, delays=.001)
    b2_i2 = Connection(b2, i2, 2, weights=.005, delays=.002)
    simulation = Network([b1, b2, i1, i2], [b1_i1, i1_i2, b2_i2])
    simulation_dict = simulation.to_dict()
    
    return simulation_dict
Exemple #17
0
def get_network(dv=.001, update_method='exact', tol=1e-14):

    # Create simulation:
    b1 = ExternalPopulation('100', record=True)
    i1 = InternalPopulation(v_min=0,
                            v_max=.02,
                            dv=dv,
                            update_method=update_method,
                            tol=tol)
    b1_i1 = Connection(b1, i1, 1, weights=.005, delays=0.0)
    network = Network([b1, i1], [b1_i1])

    return network
Exemple #18
0
def test_delay_doublepop():

    # Settings:
    t0 = 0.
    dt = .001
    tf = .010
    
    # Create populations:
    b1 = ExternalPopulation(50)
    i1 = InternalPopulation(v_min=0, v_max=.02, dv=.001, update_method='exact')
    i2 = InternalPopulation(v_min=0, v_max=.02, dv=.001, update_method='exact')
    
    # Create connections:
    b1_i1 = Connection(b1, i1, 2, weights=.005)
    i1_i2 = Connection(i1, i2, 20, weights=.005, delays=2*dt)    
    
    # Create and run simulation:
    simulation = Network([b1, i1, i2], [b1_i1, i1_i2])
    simulation.run(dt=dt, tf=tf, t0=t0)
    
    true_ans = np.array([0, 0.0, 0.0, 0.0, 1.9089656152757652e-13, 1.9787511418980406e-10, 9.5007650186649266e-09, 1.3334881090883857e-07, 1.0103767575651715e-06, 5.3604521936092067e-06, 2.2383604753409621e-05])
    np.testing.assert_almost_equal(i2.firing_rate_record, true_ans, 12)
Exemple #19
0
def test_general_interface():

    # Settings:
    t0 = 0.
    dt = .001
    tf = .01

    # Run simulation:
    b1 = ODE(lambda y, t: (100 - t) / .1)
    i1 = PopulationInterface()
    b1_i1 = Connection(b1, i1, 1, weights=.005)

    network = Network([b1, i1], [b1_i1])
    network.run(dt, tf=tf, t0=t0)

    # Tests:
    final_firing_rate = 9.99949999997
    np.testing.assert_almost_equal(b1.curr_firing_rate, final_firing_rate, 10)
    np.testing.assert_almost_equal(i1.source_firing_rate_dict[0],
                                   final_firing_rate, 10)
    assert len(i1.source_connection_list) == 1
    assert i1.source_connection_list[0] == b1_i1
Exemple #20
0
    def get_simulation(dv=.001,
                       verbose=False,
                       update_method='exact',
                       approx_order=None,
                       tol=1e-8):

        # Create simulation:
        f = RequestFiringRateFunction(5555)
        b1 = ExternalPopulation(f, record=True, name='b1')
        i1 = InternalPopulation(v_min=0,
                                v_max=.02,
                                dv=dv,
                                update_method=update_method,
                                approx_order=approx_order,
                                tol=tol)
        b1_i1 = Connection(b1, i1, 1, weights=.005, delay=0.0)
        simulation = Network([b1, i1], [b1_i1], verbose=verbose)

        return simulation
Exemple #21
0
def get_simulation(dv=.001,
                   update_method='approx',
                   approx_order=None,
                   tol=1e-8):
    import scipy.stats as sps

    # Create simulation:
    b1 = ExternalPopulation(100)
    i1 = InternalPopulation(v_min=0,
                            v_max=.02,
                            dv=dv,
                            update_method=update_method,
                            approx_order=approx_order,
                            tol=tol)
    b1_i1 = Connection(b1,
                       i1,
                       1,
                       delays=0.0,
                       weights=(sps.expon(0, .005), 201))
    simulation = Network([b1, i1], [b1_i1])

    return simulation
Exemple #22
0
def get_simulation(dv=.001, update_method='approx', tol=1e-8):
    import scipy.stats as sps

    # Create simulation:
    b1 = ExternalPopulation(50)
    b2 = ExternalPopulation(1000)
    i1 = InternalPopulation(v_min=-.04,
                            v_max=.02,
                            dv=dv,
                            update_method=update_method,
                            tol=tol)
    b1_i1 = Connection(b1,
                       i1,
                       1,
                       delays=0.0,
                       weights=(sps.expon(0, .00196), 301))
    b2_i1 = Connection(b2,
                       i1,
                       1,
                       delays=0.0,
                       weights=(sps.expon(0, .001), 301))
    simulation = Network([b1, b2, i1], [b1_i1, b2_i1])

    return simulation
Exemple #23
0
    def run(simulation_dict, run_dict, result_dict, rank=None):
    
        t0 = run_dict['t0']
        dt = run_dict['dt']
        tf = run_dict['tf']
        number_of_processes = run_dict.get('number_of_processes', 1)
    
        simulation = Network(**simulation_dict)
        if rank is None:
            simulation.run(dt=dt, tf=tf, t0=t0)
        else:
            
            address_config_dict = {}
            rank_address_function = lambda rank:"ipc://%s" % (5559+rank)
            for ii in range(number_of_processes):
                address_config_dict[ii] = rank_address_function(ii)

            
            simulation.run(dt=dt, tf=tf, t0=t0, synchronization_harness=SynchronizationHarness(rank, address_config_dict, number_of_processes))
        
        result_dict[rank] = {}
        for p in simulation.population_list:
            result_dict[rank][p.gid] = p.firing_rate_record
Exemple #24
0
# import matplotlib
# matplotlib.use('Qt4Agg')
# import matplotlib.pyplot as plt
from dipde.internals.internalpopulation import InternalPopulation
from dipde.internals.externalpopulation import ExternalPopulation
from dipde.internals.network import Network
from dipde.internals.connection import Connection as Connection
from dipde.visualization import visualize

dv = .0001
update_method = 'approx'
approx_order = 1
tol = 1e-14

b1 = ExternalPopulation('100', record=True)
i1 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
i2 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
b1_i1 = Connection(b1, i1, 1, weights=.005, delays=0.0)
b1_i2 = Connection(b1, i2, 2, weights=.005, delays=0.0)
network = Network([b1, i1, i2], [b1_i1, b1_i2])


network.run(dt=.0001, tf=.1, t0=0)

print i1.get_firing_rate(.1)

visualize(network, show=True)

print network.to_dict()
Exemple #25
0
            result.append((u,v,d))
    
    G2 = nx.MultiDiGraph(result)
    for n in G2.nodes_iter():
        G2.node[n] = G.node[n]
        
    if full == True:
        for ii in range(G.number_of_nodes()):
            if not ii in G2:
                G2.add_node(ii, G.node[n])
            
    return G2
    
    
if __name__ == "__main__":
    
    from dipde.examples.cortical_column import get_network, example
    from dipde.internals.network import Network

    network = get_network() 

    G = to_graph(network)
    D = to_dict(G)
    
    round_trip_network = Network(**D)
    example(show=True, network=round_trip_network)
    
    
    
    
    
# Run simulation:
b1 = ExternalPopulation(100)
b2 = ExternalPopulation(100)
b3 = ExternalPopulation(100)
b4 = ExternalPopulation(100)
i1 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
i2 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
i3 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
i4 = InternalPopulation(v_min=0, v_max=.02, dv=dv, update_method=update_method, approx_order=approx_order, tol=tol)
b1_i1 = Connection(b1, i1, 1, weights=.005)
b2_i2 = Connection(b2, i2, 1, weights=.005)
b3_i3 = Connection(b3, i3, 1, weights=.005)
b4_i4 = Connection(b4, i4, 1, weights=.005)

network = Network([b1, b2, b3, b4, i1, i2, i3, i4], [b1_i1, b2_i2, b3_i3, b4_i4])

address_config_dict = {}
rank_address_function = lambda rank:"ipc://%s" % (5559+rank)
for ii in range(number_of_processes):
    address_config_dict[ii] = rank_address_function(ii)

run_dict = {'t0':t0, 
            'dt':dt,
            'tf':tf,
            'synchronization_harness':SynchronizationHarness(rank, address_config_dict, number_of_processes)}

t0 = time.time()
network.run(**run_dict)
print time.time() - t0
# i_tmp.initialize()
#  
#  
b1 = ExternalPopulation(bgfr, record=False)
i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres')
# i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres', p0=(i_tmp.edges.tolist(), p0), initial_firing_rate=f0)
b1_i1 = Connection(b1, i1, nsyn_bg, weights=weight, delays=0.0)
i1_i1 = Connection(i1, i1, nsyn_recc, weights=weight, delays=0.0)
# 
# be  = ExternalPopulation(get_infinitesimal_perturbation(.1,.0005,.001), record=False)
# be_i1 = Connection(be, i1, 1, weights=weight, delays=0.0)
# 
# 
def chirp_fcn(n):
    print n.t, ss_fr, n.population_list[1].curr_firing_rate
network = Network([b1, i1], [b1_i1, i1_i1], update_callback=chirp_fcn)
network.run(tf=5, dt=.0001)
i1.plot()
plt.show()


# def chirp(n):
#     print n.t
#  
# network = Network([b1, i1], [b1_i1, i1_i1], update_callback=chirp)
# network.run(tf=5, dt=.0001)
#   
# ss_fr = i1.firing_rate_record[-1]
#   
# # print ss_fr
# i1.plot()
                        dv=dv,
                        update_method=update_method,
                        approx_order=approx_order,
                        tol=tol)
i4 = InternalPopulation(v_min=0,
                        v_max=.02,
                        dv=dv,
                        update_method=update_method,
                        approx_order=approx_order,
                        tol=tol)
b1_i1 = Connection(b1, i1, 1, weights=.005)
b2_i2 = Connection(b2, i2, 1, weights=.005)
b3_i3 = Connection(b3, i3, 1, weights=.005)
b4_i4 = Connection(b4, i4, 1, weights=.005)

network = Network([b1, b2, b3, b4, i1, i2, i3, i4],
                  [b1_i1, b2_i2, b3_i3, b4_i4])

run_dict = {
    't0':
    t0,
    'dt':
    dt,
    'tf':
    tf,
    'distributed_configuration':
    MongoDistributedConfiguration(rank,
                                  number_of_processes=number_of_processes)
}

import re
from dipde.internals.network import Network
Exemple #29
0
from dipde.visualization import visualize

dv = .0001
update_method = 'approx'
approx_order = 1
tol = 1e-14

b1 = ExternalPopulation('100', record=True)
i1 = InternalPopulation(v_min=0,
                        v_max=.02,
                        dv=dv,
                        update_method=update_method,
                        approx_order=approx_order,
                        tol=tol)
i2 = InternalPopulation(v_min=0,
                        v_max=.02,
                        dv=dv,
                        update_method=update_method,
                        approx_order=approx_order,
                        tol=tol)
b1_i1 = Connection(b1, i1, 1, weights=.005, delays=0.0)
b1_i2 = Connection(b1, i2, 2, weights=.005, delays=0.0)
network = Network([b1, i1, i2], [b1_i1, b1_i2])

network.run(dt=.0001, tf=.1, t0=0)

print i1.get_firing_rate(.1)

visualize(network, show=True)

print network.to_dict()
Exemple #30
0
def get_network(dv=.0001):

    nsyn_background = {
        (23, 'e'): 1600,
        (23, 'i'): 1500,
        (4, 'e'): 2100,
        (4, 'i'): 1900,
        (5, 'e'): 2000,
        (5, 'i'): 1900,
        (6, 'e'): 2900,
        (6, 'i'): 2100
    }

    background_firing_rate = 8

    background_delay = {'e': 0.005, 'i': 0.0}

    internal_population_sizes = {
        (23, 'e'): 20683,
        (23, 'i'): 5834,
        (4, 'e'): 21915,
        (4, 'i'): 5479,
        (5, 'e'): 4850,
        (5, 'i'): 1065,
        (6, 'e'): 14395,
        (6, 'i'): 2948
    }

    connection_probabilities = {
        ((23, 'e'), (23, 'e')): .101,
        ((23, 'e'), (23, 'i')): .135,
        ((23, 'e'), (4, 'e')): .008,
        ((23, 'e'), (4, 'i')): .069,
        ((23, 'e'), (5, 'e')): .100,
        ((23, 'e'), (5, 'i')): .055,
        ((23, 'e'), (6, 'e')): .016,
        ((23, 'e'), (6, 'i')): .036,
        ((23, 'i'), (23, 'e')): .169,
        ((23, 'i'), (23, 'i')): .137,
        ((23, 'i'), (4, 'e')): .006,
        ((23, 'i'), (4, 'i')): .003,
        ((23, 'i'), (5, 'e')): .062,
        ((23, 'i'), (5, 'i')): .027,
        ((23, 'i'), (6, 'e')): .007,
        ((23, 'i'), (6, 'i')): .001,
        ((4, 'e'), (23, 'e')): .088,
        ((4, 'e'), (23, 'i')): .032,
        ((4, 'e'), (4, 'e')): .050,
        ((4, 'e'), (4, 'i')): .079,
        ((4, 'e'), (5, 'e')): .051,
        ((4, 'e'), (5, 'i')): .026,
        ((4, 'e'), (6, 'e')): .021,
        ((4, 'e'), (6, 'i')): .003,
        ((4, 'i'), (23, 'e')): .082,
        ((4, 'i'), (23, 'i')): .052,
        ((4, 'i'), (4, 'e')): .135,
        ((4, 'i'), (4, 'i')): .160,
        ((4, 'i'), (5, 'e')): .006,
        ((4, 'i'), (5, 'i')): .002,
        ((4, 'i'), (6, 'e')): .017,
        ((4, 'i'), (6, 'i')): .001,
        ((5, 'e'), (23, 'e')): .032,
        ((5, 'e'), (23, 'i')): .075,
        ((5, 'e'), (4, 'e')): .007,
        ((5, 'e'), (4, 'i')): .003,
        ((5, 'e'), (5, 'e')): .083,
        ((5, 'e'), (5, 'i')): .060,
        ((5, 'e'), (6, 'e')): .057,
        ((5, 'e'), (6, 'i')): .028,
        ((5, 'i'), (23, 'e')): 0,
        ((5, 'i'), (23, 'i')): 0,
        ((5, 'i'), (4, 'e')): .0003,
        ((5, 'i'), (4, 'i')): 0,
        ((5, 'i'), (5, 'e')): .373,
        ((5, 'i'), (5, 'i')): .316,
        ((5, 'i'), (6, 'e')): .020,
        ((5, 'i'), (6, 'i')): .008,
        ((6, 'e'), (23, 'e')): .008,
        ((6, 'e'), (23, 'i')): .004,
        ((6, 'e'), (4, 'e')): .045,
        ((6, 'e'), (4, 'i')): .106,
        ((6, 'e'), (5, 'e')): .020,
        ((6, 'e'), (5, 'i')): .009,
        ((6, 'e'), (6, 'e')): .040,
        ((6, 'e'), (6, 'i')): .066,
        ((6, 'i'), (23, 'e')): 0,
        ((6, 'i'), (23, 'i')): 0,
        ((6, 'i'), (4, 'e')): 0,
        ((6, 'i'), (4, 'i')): 0,
        ((6, 'i'), (5, 'e')): 0,
        ((6, 'i'), (5, 'i')): 0,
        ((6, 'i'), (6, 'e')): .225,
        ((6, 'i'), (6, 'i')): .144
    }

    conn_weights = {'e': .175 * 1e-3, 'i': -.7 * 1e-3}

    position_dict = {
        (23, 'e'): (0, 0, 3),
        (23, 'i'): (0, 1, 3),
        (4, 'e'): (0, 0, 2),
        (4, 'i'): (0, 1, 2),
        (5, 'e'): (0, 0, 1),
        (5, 'i'): (0, 1, 1),
        (6, 'e'): (0, 0, 0),
        (6, 'i'): (0, 1, 0)
    }

    internal_population_settings = {
        'v_min': -.03,
        'v_max': .015,
        'dv': dv,
        'update_method': 'gmres',
        'tau_m': .01,
        'tol': 1e-7,
        'record': True
    }

    # Create populations:
    background_population_dict = {}
    internal_population_dict = {}
    for layer, celltype in itertools.product([23, 4, 5, 6], ['e', 'i']):
        background_population_dict[layer, celltype] = ExternalPopulation(
            'Heaviside(t)*%s' % background_firing_rate,
            record=False,
            metadata={
                'layer': layer,
                'celltype': celltype
            })
        curr_population_settings = copy.copy(internal_population_settings)
        x_pos, y_pos, z_pos = position_dict[layer, celltype]
        metadata = {
            'layer': layer,
            'celltype': celltype,
            'x': x_pos,
            'y': y_pos,
            'z': z_pos,
        }
        curr_population_settings.update({'metadata': metadata})
        internal_population_dict[layer, celltype] = InternalPopulation(
            **curr_population_settings)

    # Create background connections:
    connection_list = []
    for layer, celltype in itertools.product([23, 4, 5, 6], ['e', 'i']):
        source_population = background_population_dict[layer, celltype]
        target_population = internal_population_dict[layer, celltype]
        if celltype == 'e':
            background_delay = .005
        else:
            background_delay = 0.
        curr_connection = Connection(source_population,
                                     target_population,
                                     nsyn_background[layer, celltype],
                                     weights=conn_weights['e'],
                                     delays=background_delay)
        connection_list.append(curr_connection)

    # Create recurrent connections:
    for source_layer, source_celltype in itertools.product([23, 4, 5, 6],
                                                           ['e', 'i']):
        for target_layer, target_celltype in itertools.product([23, 4, 5, 6],
                                                               ['e', 'i']):
            source_population = internal_population_dict[source_layer,
                                                         source_celltype]
            target_population = internal_population_dict[target_layer,
                                                         target_celltype]
            nsyn = connection_probabilities[
                (source_layer, source_celltype),
                (target_layer,
                 target_celltype)] * internal_population_sizes[source_layer,
                                                               source_celltype]
            weight = conn_weights[source_celltype]
            curr_connection = Connection(source_population,
                                         target_population,
                                         nsyn,
                                         weights=weight,
                                         delays=0)
            connection_list.append(curr_connection)

    # Create simulation:
    population_list = background_population_dict.values(
    ) + internal_population_dict.values()

    def f(n):
        print 't:', n.t
        # if n.t%.001 < 1e-10:
        #     print 't:', n.t

    network = Network(population_list, connection_list, update_callback=f)

    return network
def test_restart_interal():

    # Run part-way and serialize:
    b1 = ExternalPopulation('100', record=True)
    i1 = InternalPopulation(v_min=0, v_max=.02, dv=.001)
    b1_i1 = Connection(b1, i1, 1, weights=.005, delays=0.0)
    simulation = Network([b1, i1], [b1_i1])
    simulation.run(dt=.001, tf=.01, t0=0)
    i1_str = i1.to_json()
    b1_str = b1.to_json()
    
    # Rehydrate and continue run:
    b2 = ExternalPopulation(**json.loads(b1_str))
    i2 = InternalPopulation(**json.loads(i1_str))
    simulation2 = Network([b2, i2], [Connection(b2, i2, 1, weights=.005, delays=0.0)])
    simulation2.run(dt=.001, tf=.02, t0=.01)
    
    # Run straight through, for comparison:
    b3 = ExternalPopulation('100', record=True)
    i3 = InternalPopulation(v_min=0, v_max=.02, dv=.001)
    simulation3 = Network([b3, i3], [Connection(b3, i3, 1, weights=.005, delays=0.0)])
    simulation3.run(dt=.001, tf=.02, t0=0)

    # Test:
    for y1, y2 in zip(i1.firing_rate_record, i3.firing_rate_record):
        np.testing.assert_almost_equal(y1, y2, 8) 

    b3.to_json(StringIO.StringIO())
    i3.to_json(StringIO.StringIO())
    b1_i1.to_json(StringIO.StringIO())
Exemple #32
0
 def __init__(self, population_list=[], connection_list=[]):
     self.simulation = Network(population_list, connection_list)