Пример #1
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) 
Пример #2
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)
Пример #3
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
Пример #4
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)
Пример #5
0
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())
Пример #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)

    # 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
Пример #7
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)
Пример #8
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
Пример #9
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()
Пример #10
0
#  
#  
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()
# plt.show()
Пример #11
0
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


# profile = profile_simulation(simulation, run_dict, logging=False)
# total_time = extract_value(profile, 'simulation.py', 'run')
# parallel_overhead = extract_value(profile, 'distributedconfiguration.py', 'update')
# parallel_win = extract_value(profile, 'internalpopulation.py', 'update')
# if rank == 0: print 'total time: %s' % total_time
# if rank == 0: print 'parallel_overhead: %s' % parallel_overhead
# print 'parallel_win: %s' % parallel_win


#      1001    0.001    0.000    0.193    0.000 distributedconfiguration.py:28(update)

# if rank == 0:
Пример #12
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()