Exemplo n.º 1
0
def test_biphasic_delta():
    integrator = pylgn.Integrator(nt=10, nr=5, dt=0.1, dr=1)

    t_vec, x_vec, y_vec = integrator.meshgrid()
    w_vec, kx_vec, ky_vec = integrator.freq_meshgrid()

    delay_W = t_vec.flatten()[6]
    delay_K = t_vec.flatten()[10]

    shift_x = x_vec.flatten()[-3]
    shift_y = y_vec.flatten()[8]

    phase, damping = 42.5 * pq.ms, 0.38

    W_ft = tpl.create_biphasic_ft(phase=phase, damping=damping,
                                  delay=delay_W)(w_vec) * spl.create_delta_ft(
                                      shift_x=shift_x)(kx_vec, ky_vec)
    K_ft = tpl.create_delta_ft(delay_K)(w_vec) * spl.create_delta_ft(
        shift_y=shift_y)(kx_vec, ky_vec)
    G = integrator.compute_inverse_fft(W_ft * K_ft)

    F = tpl.create_biphasic(phase=phase, damping=damping,
                            delay=delay_W)(t_vec - delay_K) * spl.create_delta(
                                1, shift_x=shift_x)(x_vec, y_vec - shift_y)

    assert (abs(G - F) < complex(1e-3, 1e-12)).all()
Exemplo n.º 2
0
def test_nonlagged_x_cells():
    R_g_e = np.array([36.8000000000, 105.5231755992, 80.5607155005, 60.1117829282, 56.7461598311, 56.5031395446, 56.4951231072, 56.4950008690, 56.4950000029, 56.4950000000])/pq.s

    R_r_e = np.array([9.1000000000, 48.9839667670, 20.1915848052, 11.3884937007, 13.2064761119, 13.9269478889, 14.0176607852, 14.0235290468, 14.0237452461, 14.0237499389])/pq.s

    patch_diameter = np.linspace(0, 14, 10) * pq.deg
    R_g = np.zeros(len(patch_diameter)) / pq.s
    R_r = np.zeros(len(patch_diameter)) / pq.s

    network = pylgn.Network()
    integrator = network.create_integrator(nt=1, nr=7, dt=1*pq.ms, dr=0.2*pq.deg)
    ganglion = network.create_ganglion_cell(background_response=36.8/pq.s)
    relay = network.create_relay_cell(background_response=9.1/pq.s)

    Wg_r = spl.create_dog_ft(A=-1, a=0.62*pq.deg, B=-0.85, b=1.26*pq.deg)
    Krig_r = spl.create_gauss_ft(A=1, a=0.88*pq.deg)
    Krg_r = spl.create_delta_ft()

    ganglion.set_kernel((Wg_r, tpl.create_delta_ft()))
    network.connect(ganglion, relay, (Krg_r, tpl.create_delta_ft()), weight=0.81)
    network.connect(ganglion, relay, (Krig_r, tpl.create_delta_ft()), weight=-0.56)

    for i, d in enumerate(patch_diameter):
        stimulus = pylgn.stimulus.create_patch_grating_ft(patch_diameter=d, contrast=-131.3)
        network.set_stimulus(stimulus)

        network.compute_response(ganglion, recompute_ft=True)
        network.compute_response(relay, recompute_ft=True)

        R_g[i] = ganglion.center_response[0]
        R_r[i] = relay.center_response[0]

    assert (abs(R_g - R_g_e) < 1e-9).all()
    assert (abs(R_r - R_r_e) < 1e-9).all()
Exemplo n.º 3
0
def test_spl_delta_ft():
    delta_ft = spl.create_delta_ft(0.5, 0.1)

    assert abs(
        delta_ft(kx=2.5, ky=-3.1) -
        complex(0.5897880250310923, -0.8075581004051077)) < complex(
            1e-12, 1e-12)
Exemplo n.º 4
0
def test_G_R_C_grating_response(nt, nr, dt, dr, A_g, a_g, B_g, b_g, delay_g,
                                A_rc, a_rc, B_rc, b_rc, delay_rc, w_rc, a_rg,
                                delay_rg, w_rg, w_id, k_id, orient, C):

    network = pylgn.Network()
    integrator = network.create_integrator(nt=nt, nr=nr, dt=dt, dr=dr)

    w_g = integrator.temporal_angular_freqs[w_id].rescale(1. / pq.ms)
    k_g = integrator.spatial_angular_freqs[k_id]
    kx_g = k_g * np.cos(orient.rescale(pq.rad))
    ky_g = k_g * np.sin(orient.rescale(pq.rad))

    t, y, x = integrator.meshgrid()

    Wg_r = spl.create_dog_ft(A=A_g, a=a_g, B=B_g, b=b_g)
    Wg_t = tpl.create_delta_ft(delay=delay_g)

    Krg_r = spl.create_gauss_ft(a=a_rg)
    Krg_t = tpl.create_delta_ft(delay=delay_rg)

    Krc_r = spl.create_dog_ft(A=A_rc, a=a_rc, B=B_rc, b=b_rc)
    Krc_t = tpl.create_delta_ft(delay=delay_rc)

    Kcr_r = spl.create_delta_ft()
    Kcr_t = tpl.create_delta_ft()

    ganglion = network.create_ganglion_cell(kernel=(Wg_r, Wg_t))
    relay = network.create_relay_cell()
    cortical = network.create_cortical_cell()

    network.connect(ganglion, relay, (Krg_r, Krg_t), weight=w_rg)
    network.connect(cortical, relay, (Krc_r, Krc_t), weight=w_rc)
    network.connect(relay, cortical, (Kcr_r, Kcr_t), weight=1)

    stimulus = pylgn.stimulus.create_fullfield_grating_ft(angular_freq=w_g,
                                                          wavenumber=k_g,
                                                          orient=orient,
                                                          contrast=C)
    network.set_stimulus(stimulus)
    network.compute_response(ganglion)
    network.compute_response(relay)
    network.compute_response(cortical)

    Wg = ganglion.evaluate_irf_ft(w=w_g, kx=kx_g, ky=ky_g)
    Wr = relay.evaluate_irf_ft(w=w_g, kx=kx_g, ky=ky_g)
    Wc = cortical.evaluate_irf_ft(w=w_g, kx=kx_g, ky=ky_g)

    Rg = C * abs(Wg) * np.cos(kx_g * x + ky_g * y - w_g * t +
                              np.angle(Wg)) / pq.s
    Rr = C * abs(Wr) * np.cos(kx_g * x + ky_g * y - w_g * t +
                              np.angle(Wr)) / pq.s
    Rc = C * abs(Wc) * np.cos(kx_g * x + ky_g * y - w_g * t +
                              np.angle(Wc)) / pq.s

    assert (abs(Rg - ganglion.response) < complex(1e-12, 1e-12)).all()
    assert (abs(Rr - relay.response) < complex(1e-12, 1e-12)).all()
    assert (abs(Rc.clip(min=0 / pq.s) - cortical.response) < complex(
        1e-12, 1e-12)).all()
Exemplo n.º 5
0
def test_delta_delta():
    integrator = pylgn.Integrator(nt=5, nr=5, dt=1, dr=1)

    t_vec, x_vec, y_vec = integrator.meshgrid()
    w_vec, kx_vec, ky_vec = integrator.freq_meshgrid()

    delay_W = t_vec.flatten()[6]
    delay_K = t_vec.flatten()[10]

    shift_x = x_vec.flatten()[-3]
    shift_y = y_vec.flatten()[8]

    W_ft = tpl.create_delta_ft(delay_W)(w_vec) * spl.create_delta_ft(
        shift_x=shift_x)(kx_vec, ky_vec)
    K_ft = tpl.create_delta_ft(delay_K)(w_vec) * spl.create_delta_ft(
        shift_y=shift_y)(kx_vec, ky_vec)
    G = integrator.compute_inverse_fft(W_ft * K_ft)

    F = tpl.create_delta(1, delay_W)(t_vec - delay_K) * spl.create_delta(
        1, shift_x=shift_x)(x_vec, y_vec - shift_y)

    assert (abs(G - F) < complex(1e-12, 1e-12)).all()
Exemplo n.º 6
0
def test_edog_spot_response():
    response_e = np.array([[0.0000000000, 0.0000000000],
                           [0.5255489103, 0.3077428042],
                           [0.1824324695, 0.0174985410],
                           [0.1505469275, 0.0632031066],
                           [0.1500017999, 0.0601939846]]) / pq.s
    fb_weights = [0, -1.5]

    patch_diameter = np.linspace(0, 6, 5) * pq.deg
    response = np.zeros([len(patch_diameter), len(fb_weights)]) / pq.s

    for j, w_c in enumerate(fb_weights):
        network = pylgn.Network()
        integrator = network.create_integrator(nt=1, nr=7, dt=1*pq.ms, dr=0.1*pq.deg)

        delta_t = tpl.create_delta_ft()
        delta_s = spl.create_delta_ft()
        Wg_r = spl.create_dog_ft(A=1, a=0.25*pq.deg, B=0.85, b=0.83*pq.deg)
        Krc_r = spl.create_gauss_ft(A=1, a=0.83*pq.deg)

        ganglion = network.create_ganglion_cell(kernel=(Wg_r, delta_t))
        relay = network.create_relay_cell()
        cortical = network.create_cortical_cell()

        network.connect(ganglion, relay, (delta_s, delta_t), 1.0)
        network.connect(cortical, relay, (Krc_r, delta_t), w_c)
        network.connect(relay, cortical, (delta_s, delta_t), 1.0)

        for i, d in enumerate(patch_diameter):
            stimulus = pylgn.stimulus.create_patch_grating_ft(wavenumber=0./pq.deg,
                                                              patch_diameter=d)
            network.set_stimulus(stimulus)
            network.compute_response(relay, recompute_ft=True)
            response[i, j] = relay.center_response[0]

        network.clear()

    assert (abs(response - response_e) < 1e-10).all()
Exemplo n.º 7
0
def test_gauss_delta():
    integrator = pylgn.Integrator(nt=3, nr=8, dt=0.1, dr=0.1)

    t_vec, x_vec, y_vec = integrator.meshgrid()
    w_vec, kx_vec, ky_vec = integrator.freq_meshgrid()

    delay_W = t_vec.flatten()[0]
    delay_K = t_vec.flatten()[0]

    shift_x = x_vec.flatten()[2**5]
    shift_y = y_vec.flatten()[-37]

    W_ft = tpl.create_delta_ft(delay_W)(w_vec) * spl.create_gauss_ft(
        a=0.62 * pq.deg)(kx_vec, ky_vec)
    K_ft = tpl.create_delta_ft(delay_K)(w_vec) * spl.create_delta_ft(
        shift_x, shift_y)(kx_vec, ky_vec)
    G = integrator.compute_inverse_fft(W_ft * K_ft)

    F = tpl.create_delta(1. / integrator.dt,
                         delay_W)(t_vec - delay_K) * spl.create_gauss(
                             a=0.62 * pq.deg)(x_vec - shift_x, y_vec - shift_y)

    assert (abs(G - F.magnitude) < complex(1e-10, 1e-12)).all()
Exemplo n.º 8
0
def test_edog_patch_grating_response():
    response_e = np.array([[0.0000000000, 0.0000000000],
                           [0.5694814680, 0.3933539871],
                           [0.4933473520, 0.3005140715],
                           [0.5038172723, 0.2842527074],
                           [0.5039615741, 0.2843698815]]) / pq.s
    fb_weights = [0, -1.5]

    patch_diameter = np.linspace(0, 6, 5) * pq.deg
    response = np.zeros([len(patch_diameter), len(fb_weights)]) / pq.s

    for j, w_c in enumerate(fb_weights):
        network = pylgn.Network()
        integrator = network.create_integrator(nt=1, nr=7, dt=1*pq.ms, dr=0.1*pq.deg)

        delta_t = tpl.create_delta_ft()
        delta_s = spl.create_delta_ft()
        Wg_r = spl.create_dog_ft(A=1, a=0.25*pq.deg, B=0.85, b=0.83*pq.deg)
        Krc_r = spl.create_gauss_ft(A=1, a=0.83*pq.deg)

        ganglion = network.create_ganglion_cell(kernel=(Wg_r, delta_t))
        relay = network.create_relay_cell()
        cortical = network.create_cortical_cell()

        network.connect(ganglion, relay, (delta_s, delta_t), 1.0)
        network.connect(cortical, relay, (Krc_r, delta_t), w_c)
        network.connect(relay, cortical, (delta_s, delta_t), 1.0)

        for i, d in enumerate(patch_diameter):
            stimulus = pylgn.stimulus.create_patch_grating_ft(wavenumber=integrator.spatial_angular_freqs[4], patch_diameter=d)
            network.set_stimulus(stimulus)
            network.compute_response(relay, recompute_ft=True)
            response[i, j] = relay.center_response[0]

        network.clear()

    assert (abs(response - response_e) < 1e-10).all()
Exemplo n.º 9
0
def create_dynamicnetwork(params=None):
    """
    Create PyLGN network with temporal kernels.
    
    Parameters
    ----------
    params : None, dict, str
        passed to util._parse_parameters
    """

    params = util.parse_parameters(params)

    # network
    network = pylgn.Network()
    integrator = network.create_integrator(nt=params['nt'],
                                           nr=params['nr'],
                                           dt=params['dt'],
                                           dr=params['dr'])

    # neurons
    ganglion = network.create_ganglion_cell()
    relay = network.create_relay_cell()
    cortical = network.create_cortical_cell()

    # RGC impulse-response function
    Wg_r = spl.create_dog_ft(A=params['A_g'],
                             a=params['a_g'],
                             B=params['B_g'],
                             b=params['b_g'])
    Wg_t = tpl.create_biphasic_ft(phase=params['phase_g'],
                                  damping=params['damping_g'])
    ganglion.set_kernel((Wg_r, Wg_t))

    # excitatory FF connection
    Krg_r = spl.create_gauss_ft(A=params['A_rg_ex'], a=params['a_rg_ex'])
    Krg_t = tpl.create_exp_decay_ft(tau=params['tau_rg_ex'],
                                    delay=params['delay_rg_ex'])
    network.connect(ganglion, relay, (Krg_r, Krg_t), weight=params['w_rg_ex'])

    # inhibitory FF
    Krig_r = spl.create_gauss_ft(A=params['A_rg_in'], a=params['a_rg_in'])
    Krig_t = tpl.create_exp_decay_ft(tau=params['tau_rg_in'],
                                     delay=params['delay_rg_in'])
    network.connect(ganglion,
                    relay, (Krig_r, Krig_t),
                    weight=params['w_rg_in'])

    # excitatory FB
    Krc_ex_r = spl.create_gauss_ft(A=params['A_rc_ex'], a=params['a_rc_ex'])
    Krc_ex_t = tpl.create_exp_decay_ft(tau=params['tau_rc_ex'],
                                       delay=params['delay_rc_ex'])
    network.connect(cortical,
                    relay, (Krc_ex_r, Krc_ex_t),
                    weight=params['w_rc_ex'])

    # inhibitory FB
    Krc_in_r = spl.create_gauss_ft(A=params['A_rc_in'], a=params['a_rc_in'])
    Krc_in_t = tpl.create_exp_decay_ft(tau=params['tau_rc_in'],
                                       delay=params['delay_rc_in'])
    network.connect(cortical,
                    relay, (Krc_in_r, Krc_in_t),
                    weight=params['w_rc_in'])

    # TC feed-forward
    Kcr_r = spl.create_delta_ft()
    Kcr_t = tpl.create_delta_ft()
    network.connect(relay, cortical, (Kcr_r, Kcr_t), weight=params['w_cr'])

    return network
Exemplo n.º 10
0
def create_staticnetwork(params=None):
    """
    Create a PyLGN network where all temporal kernels are delta functions.
    
    Parameters
    ----------
    params : None, dict, str
        passed to util._parse_parameters
    """

    params = util.parse_parameters(params)

    # network
    network = pylgn.Network()
    integrator = network.create_integrator(nt=0,
                                           nr=params['nr'],
                                           dt=params['dt'],
                                           dr=params['dr'])

    # neurons
    ganglion = network.create_ganglion_cell()
    relay = network.create_relay_cell()
    cortical = network.create_cortical_cell()

    # RGC impulse-response function
    delta_t = tpl.create_delta_ft()
    Wg_r = spl.create_dog_ft(A=params['A_g'],
                             a=params['a_g'],
                             B=params['B_g'],
                             b=params['b_g'])
    ganglion.set_kernel((Wg_r, delta_t))

    # excitatory FF connection
    Krg_r = spl.create_gauss_ft(A=params['A_rg_ex'], a=params['a_rg_ex'])
    network.connect(ganglion,
                    relay, (Krg_r, delta_t),
                    weight=params['w_rg_ex'])

    # inhibitory FF
    Krig_r = spl.create_gauss_ft(A=params['A_rg_in'], a=params['a_rg_in'])
    network.connect(ganglion,
                    relay, (Krig_r, delta_t),
                    weight=params['w_rg_in'])

    # excitatory FB
    Krc_ex_r = spl.create_gauss_ft(A=params['A_rc_ex'], a=params['a_rc_ex'])
    network.connect(cortical,
                    relay, (Krc_ex_r, delta_t),
                    weight=params['w_rc_ex'])

    # inhibitory FB
    Krc_in_r = spl.create_gauss_ft(A=params['A_rc_in'], a=params['a_rc_in'])
    network.connect(cortical,
                    relay, (Krc_in_r, delta_t),
                    weight=params['w_rc_in'])

    # TC feed-forward
    Kcr_r = spl.create_delta_ft()
    network.connect(relay, cortical, (Kcr_r, delta_t), weight=1)

    return network
Exemplo n.º 11
0
for w_fb in fb_weights:

    # create network
    network = pylgn.Network()

    # create integrator
    integrator = network.create_integrator(nt=10,
                                           nr=7,
                                           dt=1 * pq.ms,
                                           dr=0.1 * pq.deg)

    # create spatial kernels
    Wg_s = spl.create_dog_ft(A=1, a=0.62 * pq.deg, B=0.85, b=1.26 * pq.deg)
    Krg_s = spl.create_gauss_ft(A=1, a=0.1 * pq.deg)
    Kcr_s = spl.create_delta_ft()
    Krcr_cen_s = spl.create_gauss_ft(A=1, a=(0.1) * pq.deg)
    Krcr_sur_s = spl.create_gauss_ft(A=2, a=(0.9) * pq.deg)

    # create temporal kernels
    Wg_t = tpl.create_biphasic_ft(phase_duration=42.5 * pq.ms,
                                  damping_factor=0.38,
                                  delay=0 * pq.ms)
    Krg_t = tpl.create_exp_decay_ft(18 * pq.ms, delay=0 * pq.ms)
    Kcr_t = tpl.create_delta_ft()
    Krcr_cen_t = tpl.create_exp_decay_ft(1 * pq.ms, delay=0 *
                                         pq.ms)  # decay: 10 ms, delay: 30 ms
    Krcr_sur_t = tpl.create_exp_decay_ft(1 * pq.ms, delay=30 *
                                         pq.ms)  # decay: 20 ms, delay: 30 ms

    # create neurons
Exemplo n.º 12
0
def test_core():
    dt = 5 * pq.ms
    dr = 0.1 * pq.deg

    # create network
    network = pylgn.Network()

    # create integrator
    integrator = network.create_integrator(nt=10, nr=7, dt=dt, dr=dr)

    # create neurons
    ganglion = network.create_ganglion_cell()
    relay = network.create_relay_cell(2. / pq.s)
    cortical = network.create_cortical_cell(0 / pq.s)

    # connect neurons
    Wg_r = spl.create_dog_ft(A=1, a=0.62 * pq.deg, B=0.83, b=1.26 * pq.deg)
    Wg_t = tpl.create_biphasic_ft(phase=43 * pq.ms,
                                  damping=0.38,
                                  delay=0 * pq.ms)

    Krg_r = spl.create_delta_ft(shift_x=0 * pq.deg, shift_y=0 * pq.deg)
    Krg_t = tpl.create_delta_ft(delay=0 * pq.ms)

    Krc_r = spl.create_dog_ft(A=1 * 0.9,
                              a=0.1 * pq.deg,
                              B=2 * 0.9,
                              b=0.9 * pq.deg)
    Krc_t = tpl.create_delta_ft(delay=20 * pq.ms)

    Kcr_r = spl.create_delta_ft(shift_x=0 * pq.deg, shift_y=0 * pq.deg)
    Kcr_t = tpl.create_delta_ft(delay=0 * pq.ms)

    ganglion.set_kernel((Wg_r, Wg_t))
    network.connect(ganglion, relay, (Krg_r, Krg_t))
    network.connect(cortical, relay, (Krc_r, Krc_t))
    network.connect(relay, cortical, (Kcr_r, Kcr_t))

    print(ganglion.annotations["kernel"], "\n")

    # create stimulus
    k_g = integrator.spatial_angular_freqs[2]
    w_g = -integrator.temporal_angular_freqs[40]
    # stimulus = pylgn.stimulus.create_patch_grating_ft(angular_freq=w_g,
    #                                                   wavenumber=k_g,
    #                                                   orient=0.0,
    #                                                   patch_diameter=3,
    #                                                   contrast=4)
    stimulus = pylgn.stimulus.create_flashing_spot_ft(patch_diameter=4 *
                                                      pq.deg,
                                                      contrast=4,
                                                      delay=4 * pq.ms,
                                                      duration=20 * pq.ms)
    network.set_stimulus(stimulus, compute_fft=False)
    # network.set_stimulus(stimulus)

    # print(pylgn.closure_params(stimulus))
    #
    # # compute
    # network.compute_irf(relay)
    network.compute_response(relay)
    # network.compute_response(ganglion)
    #
    # # write
    # print("shape cube: ", relay.irf_ft.shape)
    # print("Unit irf:", relay.irf.units)
    # # print("Units irf_ft: ", relay.irf_ft.units)
    # print("Units resp: ", relay.response.units)

    # visulize
    # import matplotlib.pyplot as plt
    # # import matplotlib.animation as animation
    # # plt.imshow(relay.irf[0, :, :].real)
    #
    # plt.figure()
    # # plt.plot(integrator.times, relay.response[:, 64, 64])
    # w_g = w_g.rescale(pq.Hz) * integrator.times/integrator.times.max()
    # plt.plot(w_g/2./np.pi, relay.response[:, 64, 64])
    # plt.show()
    # pylgn.plot.animate_cube(relay.response)

    # clear network
    network.clear()