Esempio n. 1
0
def test_dog_patch_grating_response():
    response_e = np.array([[0.1017374087, 0.2867197943, 0.5105320011, 0.1666709735],
                          [0.3492268988, 0.3616052645, 0.4750891407, 0.1640082272],
                          [0.4789040160, 0.4328530438, 0.3805594923, 0.1561941696],
                          [0.2884185736, 0.3175258969, 0.2569232750, 0.1437369651],
                          [0.1140384287, 0.1163952049, 0.1390511885, 0.1274369599],
                          [0.0339383730, 0.0179229458, 0.0526124870, 0.1083213337],
                          [0.0074631404, 0.0145706277, 0.0061438229, 0.0875612286],
                          [0.0013737748, 0.0074470223, -0.0077840845, 0.0663789388]]) / pq.s

    k_max_id = 40
    step = 5
    patch_diameter = np.array([3, 1.5, 0.85, 0.3]) * pq.deg
    response = np.zeros([int(k_max_id/step), len(patch_diameter)]) / pq.s

    network = pylgn.Network()

    integrator = network.create_integrator(nt=1, nr=7, dt=1*pq.ms, dr=0.1*pq.deg)
    spatial_angular_freqs = integrator.spatial_angular_freqs[:k_max_id][::step]

    Wg_t = tpl.create_delta_ft()
    Wg_r = spl.create_dog_ft(A=1, a=0.3*pq.deg, B=0.9, b=0.6*pq.deg)

    ganglion = network.create_ganglion_cell(kernel=(Wg_r, Wg_t))

    for j, d in enumerate(patch_diameter):
        for i, k_d in enumerate(spatial_angular_freqs):
            stimulus = pylgn.stimulus.create_patch_grating_ft(wavenumber=k_d,
                                                              patch_diameter=d)
            network.set_stimulus(stimulus)

            network.compute_response(ganglion, recompute_ft=True)
            response[i, j] = ganglion.center_response[0]

    assert (abs(response - response_e) < 1e-10).all()
Esempio n. 2
0
def test_G_patch_grating_response(nt, nr, dt, dr, A_g, a_g, B_g, b_g, delay_g,
                                  w_id, k_id, orient, C, patch_diameter, n):
    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]

    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)

    ganglion = network.create_ganglion_cell(kernel=(Wg_r, Wg_t))

    stimulus = pylgn.stimulus.create_patch_grating_ft(
        angular_freq=w_g,
        wavenumber=k_g,
        orient=orient,
        contrast=C,
        patch_diameter=patch_diameter)
    network.set_stimulus(stimulus)
    network.compute_response(ganglion)

    Rg = C * (X(a_g / patch_diameter, a_g * k_g, n) -
              B_g / A_g * X(b_g / patch_diameter, b_g * k_g, n)) / pq.s
    assert abs(Rg - ganglion.center_response[0]) < complex(1e-10, 1e-10)
Esempio n. 3
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()
Esempio 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()
Esempio n. 5
0
def test_fullfield_grating_with_fft():
    network = pylgn.Network()
    integrator = network.create_integrator(nt=2,
                                           nr=7,
                                           dt=1 * pq.ms,
                                           dr=0.1 * pq.deg)
    t, y, x = integrator.meshgrid()

    stimulus = pylgn.stimulus.create_fullfield_grating(angular_freq=0,
                                                       wavenumber=2,
                                                       orient=33,
                                                       contrast=1)
    network.set_stimulus(stimulus, compute_fft=True)
    assert (abs(
        integrator.compute_inverse_fft(network.stimulus.ft) -
        stimulus(t, x, y)) < 1e-12).all()
Esempio 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()
Esempio n. 7
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()
Esempio n. 8
0
import pylgn
import pylgn.kernels.spatial as spl
import pylgn.kernels.temporal as tpl
import quantities as pq

# create network
network = pylgn.Network()

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

# create kernels
Wg_r = spl.create_dog_ft()
Wg_t = tpl.create_biphasic_ft()

# create neurons
ganglion = network.create_ganglion_cell(kernel=(Wg_r, Wg_t))

# create stimulus
stimulus = pylgn.stimulus.create_natural_image(filenames="natural_scene.png",
                                               delay=40 * pq.ms,
                                               duration=80 * pq.ms)
network.set_stimulus(stimulus, compute_fft=True)

# compute
network.compute_response(ganglion)

# visulize
Esempio 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
Esempio 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
Esempio n. 11
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()