Beispiel #1
0
def test_delay_doublepop():

    # Settings:
    t0 = 0.
    dt = .001
    tf = .010
    verbose = False

    # 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], probs=[1.])
    i1_i2 = Connection(i1, i2, 20, weights=[.005], probs=[1.], delay=2 * dt)

    # Create and run simulation:
    simulation = Simulation([b1, i1, i2], [b1_i1, i1_i2], verbose=verbose)
    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)
Beispiel #2
0
def get_matrices():

    dv = .001
    nsyn_bg = 1
    bgfr = 200
    we = .1
    wi = -.1
    nsyn_00, nsyn_01, nsyn_10, nsyn_11 = 5, 5, 2, 20

    # Components:
    b0 = ExternalPopulation(bgfr, record=True)
    i0 = 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')
    b0_i0 = Connection(b0, i0, nsyn_bg, weights=we, delays=0.0)
    b0_i1 = Connection(b0, i1, nsyn_bg, weights=we, delays=0.0)
    i0_i0 = Connection(i0, i0, nsyn_00, weights=we, delays=0.0)
    i0_i1 = Connection(i0, i1, nsyn_01, weights=we, delays=0.0)
    i1_i0 = Connection(i1, i0, nsyn_10, weights=wi, delays=0.0)
    i1_i1 = Connection(i1, i1, nsyn_11, weights=wi, delays=0.0)

    L = get_leak_matrix(i1)
    Se, te = get_connection_flux_matrices(b0_i0)
    Si, _ = get_connection_flux_matrices(i1_i0)

    return L, Se, Si, te
def test_singlepop():

    # Settings:
    t0 = 0.
    dt = .001
    dv = .001
    v_min = -.01
    v_max = .02
    tf = .2
    verbose = False

    # Create simulation:
    b1 = ExternalPopulation(50)
    b2 = ExternalPopulation(50)
    i1 = InternalPopulation(v_min=v_min,
                            v_max=v_max,
                            dv=dv,
                            update_method='exact')
    b1_i1 = Connection(b1, i1, 1, weights=[.005], probs=[1.])
    b2_i1 = Connection(b2, i1, 1, weights=[.005], probs=[1.])
    simulation = Simulation([b1, b2, i1], [b1_i1, b2_i1], verbose=verbose)
    simulation.run(dt=dt, tf=tf, t0=t0)

    np.testing.assert_almost_equal(i1.t_record[-1], .2, 15)
    np.testing.assert_almost_equal(i1.firing_rate_record[-1],
                                   5.3550005434746355, 12)
    assert i1.n_bins == (v_max - v_min) / dv
    assert i1.n_edges - 1 == i1.n_bins
    assert len(simulation.population_list) == 3

    i1.plot_probability_distribution()
Beispiel #4
0
def test_singlepop():
    
    # Settings:
    t0 = 0.
    dt = .001
    dv = .001
    v_min = -.01
    v_max = .02
    tf = .2
    verbose = False
    
    # Create simulation:
    b1 = ExternalPopulation(50)
    b2 = ExternalPopulation(50)
    i1 = InternalPopulation(v_min=v_min, v_max=v_max, dv=dv, update_method='exact')
    b1_i1 = Connection(b1, i1, 1, weights=[.005], probs=[1.])
    b2_i1 = Connection(b2, i1, 1, weights=[.005], probs=[1.])
    simulation = Simulation([b1, b2, i1], [b1_i1, b2_i1], verbose=verbose)
    simulation.run(dt=dt, tf=tf, t0=t0)
    
    np.testing.assert_almost_equal(i1.t_record[-1], .2, 15)
    np.testing.assert_almost_equal(i1.firing_rate_record[-1], 5.3550005434746355, 12)
    assert i1.n_bins == (v_max - v_min)/dv
    assert i1.n_edges - 1 == i1.n_bins
    assert len(simulation.population_list) == 3
    
    i1.plot_probability_distribution()
Beispiel #5
0
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()
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())
Beispiel #7
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)
def get_simulation(dv=.001,
                   verbose=False,
                   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,
                       delay=0.0,
                       distribution=sps.expon,
                       N=201,
                       scale=.005)
    simulation = Simulation([b1, i1], [b1_i1], verbose=verbose)

    return simulation
Beispiel #9
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)
Beispiel #10
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)
Beispiel #11
0
def test_access_matrices():

    i1 = InternalPopulation(v_min=0, v_max=.02, dv=.0001)
    c1 = Connection(None, i1, 1, weights=.005)

    leak_matrix = get_leak_matrix(i1)
    synaptic_matrix, threshold_vector = get_connection_flux_matrices(c1)
    assert leak_matrix.shape == synaptic_matrix.shape
    assert synaptic_matrix.shape[0] == threshold_vector.shape[0]
Beispiel #12
0
def get_simulation(dt=.001, dv=.001, tf=.2, verbose=False, update_method='exact', approx_order=None, tol=1e-8):

    # 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, weights=[.005], probs=[1.], delay=0.0)
    simulation = Simulation([b1, i1], [b1_i1], dt=dt, tf=tf, verbose=verbose)

    return simulation
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
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
Beispiel #15
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)
Beispiel #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
Beispiel #17
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, checkpoint_callback=None, nsyn=1):
    
    # 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, nsyn, 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, checkpoint_callback=checkpoint_callback)
    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)
Beispiel #18
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
Beispiel #19
0
def test_delay_singlepop():

    # Settings:
    t0 = 0.
    dt = .001
    tf = .005
    verbose = False
    
    # 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], probs=[1.], delay=2*dt)
    simulation = Simulation([b1, i1], [b1_i1], verbose=verbose)
    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)
Beispiel #20
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)
Beispiel #21
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
Beispiel #22
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)
Beispiel #23
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
Beispiel #24
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
Beispiel #25
0
t0 = 0.
dt = 0.0001
dv = 0.1
tf = 1.  #.1 #simulation duration.
update_method = 'approx'
approx_order = 1
tol = 1e-14
verbose = False

# Create simulation:
b1 = ExternalPopulation(p_rate, record=True)
i1 = InternalPopulation(tau_m=t_m * 1e-3,
                        v_min=-0.02,
                        v_max=u_th * 1e-3,
                        dv=dv,
                        update_method=update_method,
                        approx_order=approx_order,
                        tol=tol,
                        record=True,
                        curr_firing_rate=0.0,
                        norm='inf')
i2 = InternalPopulation(tau_m=t_m * 1e-3,
                        v_min=-0.02,
                        v_max=u_th * 1e-3,
                        dv=dv,
                        update_method=update_method,
                        approx_order=approx_order,
                        tol=tol,
                        record=True,
                        curr_firing_rate=0.0,
                        norm='inf')
Beispiel #26
0
def test_internalpopulation_df():
    i1 = InternalPopulation(v_min=0, v_max=.02)
    i2 = InternalPopulation(**dict_from_df(i1.to_df()))
    compare_dicts(i1.to_dict(), i2.to_dict())
Beispiel #27
0
from dipde.internals.internalpopulation import InternalPopulation
from dipde.internals.connection import Connection
from dipde.interfaces.access_matrices import get_leak_matrix, get_connection_flux_matrices
import numpy as np
import numpy.linalg as npla
import logging
logging.disable(logging.CRITICAL)

# Components:
i1 = InternalPopulation(tau_m=.02, v_min=0, v_max=.02, dv=.001)
c1 = Connection(None, i1, 1, weights=.005)

# Get matrices:
leak_matrix = get_leak_matrix(i1)
synaptic_matrix, threshold_vector = get_connection_flux_matrices(c1)

A = leak_matrix + 100 * synaptic_matrix
A[0, :] = 1
b = np.zeros(A.shape[0])
b[0] = 1

# Solve for steady state:
p_star = npla.solve(A, b)

# Steady state firing rate
print np.dot(p_star, 100 * threshold_vector)

# A2 = leak_matrix + 100./(1-np.dot(p_star, threshold_vector))*synaptic_matrix
# w, vl = npla.eig(A2)
#
# # print w[np.argmin(np.abs(w))]
Beispiel #28
0
 def __create_internal_pop(self, params):
     # TODO: use getter methods directly in case arguments are not stored in dynamics params
     # pop = InternalPopulation(**params.dynamics_params)
     pop = InternalPopulation(**params.model_params)
     return pop

def get_infinitesimal_perturbation(t0, sigma, amplitude):
    rv = sps.norm(t0, sigma)
    return lambda t: rv.pdf(t)*sigma*np.sqrt(2*np.pi)*amplitude

dv = .0001
nsyn_bg = 1
bgfr = 600
weight = .03
nsyn_recc = 30 # 16


# Components:
b1 = ExternalPopulation(bgfr, record=True)
i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres')
b1_i1 = Connection(b1, i1, nsyn_bg, weights=weight, delays=0.0)
i1_i1 = Connection(i1, i1, nsyn_recc, weights=weight, delays=0.0)

# Get matrices:
leak_matrix = get_leak_matrix(i1, sparse=True)
# leak_matrix = spsp.csr_matrix(leak_matrix.shape)
synaptic_matrix, threshold_vector = get_connection_flux_matrices(b1_i1, sparse=True)




def f(ss_fr_guess):
      
    A = leak_matrix + (nsyn_bg*bgfr+nsyn_recc*ss_fr_guess)*synaptic_matrix
      
Beispiel #30
0
def test_internalpopulation_df():
    i1 = InternalPopulation(v_min=0, v_max=0.02)
    i2 = InternalPopulation(**dict_from_df(i1.to_df()))
    compare_dicts(i1.to_dict(), i2.to_dict())
Beispiel #31
0
    return np.array([f0_new, f1_new])


# Compute steady state:
f0_ss, f1_ss = sopt.fixed_point(steady_state_function,
                                np.array([14, 9]),
                                args=(bgfr, nsyn_bg, nsyn_00, nsyn_01, nsyn_10,
                                      nsyn_11, delay))

# Compute initial guesses for eigenvector and eigenvalue:
# # Components:
b1 = ExternalPopulation(bgfr, record=True)
i1 = InternalPopulation(tau_m=.05,
                        v_min=0,
                        v_max=1,
                        dv=dv,
                        update_method='gmres')
b1_i1 = Connection(b1, i1, nsyn_bg, weights=we, delays=0.0)
i1_i1 = Connection(i1, i1, 0, weights=wi, delays=0.0)


def cheb(N):
    x = np.cos(np.pi * np.arange(N + 1) / N)
    c = np.array([2] + [1] *
                 (N - 1) + [2]) * np.array([(-1)**ii for ii in range(N + 1)])
    X = npm.repmat(x, 1, N + 1).reshape(N + 1, N + 1).T
    dX = X - X.T
    D = (np.outer(c, 1. / c)) / (dX + (np.eye(N + 1))
                                 )  #      % off-diagonal entries
    return D - np.diag(np.sum(
Beispiel #32
0
 def build(self):
     params = self._nodes[0].dynamics_params
     self._dipde_obj = InternalPopulation(**params)
Beispiel #33
0
def test_internalpopulation_copy():
    i1 = InternalPopulation(v_min=0, v_max=0.02)
    i2 = i1.copy()
    compare(i1, i2)
string, a floating point or integer specification will also work). This external
population is connected to an Internal population (modeled as a population density pde)
via a delta-distributed synaptic weight distribution, with 5 mV strength. The in-degree
(nsyn) of this Connection is set to 1 for this example. In general, this serves as a
multiplier of the input firing rate of the source population. The internal population
has a linearly binned voltage domain from v_min to v_max. No negative bins (i.e. v_min < 0)
are required here, because no negative synaptic inputs ('weights' in the Connection object)
are defined.
"""

# Create simulation
externalPopFreq = '50'
b1 = ExternalPopulation(externalPopFreq, record=True)
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], probs=[1.], delay=0.0)
simulation = Simulation([b1, i1], [b1_i1], verbose=verbose)

# Run simulation
simulation.run(dt=dt, tf=tf, t0=t0)

# Visualize results
i1 = simulation.population_list[1]
plt.figure(figsize=(3, 3))
plt.plot(i1.t_record, i1.firing_rate_record)
plt.xlim([0, tf])
plt.ylim(ymin=0)
plt.xlabel('Time (s)')
}

# Simulation settings:
t0 = 0.
dt = .0002
tf = .1
verbose = True
save = False

# 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)
    internal_population_dict[layer, celltype] = InternalPopulation(
        **internal_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']],
                                 probs=[1.],
Beispiel #36
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()