Beispiel #1
0
def run():
    defaults = PaperDefaults()

    #David's globals
    size = 51
    npoints = 64
    cval1 = 0.25
    cval2 = 0.75
    sval = 0.75
    test_contrasts = sp.array([0., 8., 32.])
    mask_contrasts = sp.array([0., 8., 32.])

    # experiment parameters
    idx1 = int(cval1 * npoints)
    idx2 = int(cval2 * npoints)

    # simulate populations
    imc = stim.get_center_surround(size=size, csize=9, cval=cval1, sval=sp.nan)
    ims = stim.get_center_surround(size=size, csize=9, cval=sp.nan, sval=sval)
    x1 = utils.get_population(imc,
                              npoints=npoints,
                              kind='gaussian',
                              scale=0.1,
                              fdomain=(0, 1))
    x2 = sp.roll(x1, int((cval2 - cval1) * npoints), axis=-3)
    xs = utils.get_population(ims,
                              npoints=npoints,
                              kind='gaussian',
                              scale=0.1,
                              fdomain=(0, 1))
    x = []

    for k1 in test_contrasts:
        for k2 in mask_contrasts:
            x.append(k1 / 100. * x1 + k2 / 100. * x2)
    x = sp.array(x) + sp.array([xs])

    # Experimental data
    extra_vars = {}
    extra_vars['size'] = size
    extra_vars['npoints'] = npoints
    extra_vars['sval'] = sval
    extra_vars['figure_name'] = 'cross_orientation_suppression'
    extra_vars['return_var'] = 'O'
    extra_vars['idx1'] = idx1
    extra_vars['idx2'] = idx2
    extra_vars['test_contrasts'] = test_contrasts
    extra_vars['mask_contrasts'] = mask_contrasts
    optimize_model(x, [], extra_vars, defaults)
def run():
    defaults = PaperDefaults()

    #David's globals
    size = 51
    csize = 5
    npoints = 64
    scale = 2.0
    neuron_theta = 0.50
    cval = 0.5
    csvfiles = [ defaults._DATADIR + \
        '/TB2015_Fig1B_%s.csv' % (s,) \
    for s in range(-90, 90, 30) + ['CO']]

    # experiment parameters
    cvals = (sp.arange(-90, 90, 30) + 90.) / 180.
    svals = sp.linspace(0.0, 1.0, 6).tolist() + [sp.nan]

    neuron_thetas = sp.linspace(0.0, 1.0, npoints)
    neuron_idx = sp.argmin(sp.absolute(neuron_thetas - neuron_theta))

    stims = [
        stim.get_center_surround(size=size, csize=csize, cval=cv, sval=sv)
        for cv in cvals for sv in svals
    ]

    x = sp.array([
        model_utils.get_population(im,
                                   npoints=npoints,
                                   kind='circular',
                                   scale=scale,
                                   fdomain=(0, 1)) for im in stims
    ])

    # [Array shapes]
    # trott and born 2015 data
    gt = get_gt(csvfiles)

    extra_vars = {}
    extra_vars['scale'] = scale
    extra_vars['npoints'] = npoints
    extra_vars['cval'] = cval
    extra_vars['cvals'] = cvals
    extra_vars['svals'] = svals
    extra_vars['size'] = size
    extra_vars['csize'] = csize
    extra_vars['neuron_idx'] = neuron_idx
    extra_vars['figure_name'] = 'tbtcso'
    extra_vars['return_var'] = 'O'
    extra_vars['hp_file'] = os.path.join(defaults._FIGURES, 'best_hps.npz')

    optimize_model(x, gt, extra_vars, defaults)
Beispiel #3
0
def run():
    defaults = PaperDefaults()

    # David's globals
    size = 51
    csize = 9
    npoints = 32
    scale = 2.0
    cval = 0.5
    neuron_theta = 0.50
    csvfiles = [[
        defaults._DATADIR + '/TB2015_%i_%s.csv' % (i, s)
        for i in range(-90, 90, 30)
    ] for s in ('PS', 'PO')]

    # experiment parameters
    ppop = {
        'kind': 'circular',
        'npoints': npoints,
        'scale': scale,
        'fdomain': (0, 1),
    }

    vals_ang = sp.array([-90., -60., -30., 0., 30., 60.])
    vals = (vals_ang + 90.) / 180.
    imc1 = stim.get_center_surround(size=size,
                                    csize=csize,
                                    cval=cval,
                                    sval=sp.nan)
    x1 = model_utils.get_population(imc1, **ppop)
    x = sp.zeros((2, len(vals), npoints, size, size))
    cvals = (sp.arange(-90, 90, 30) + 90.) / 180.
    svals = sp.linspace(0.0, 1.0, 6).tolist() + [sp.nan]

    for vdx, v in enumerate(vals):
        imc2 = stim.get_center_surround(size=size,
                                        csize=csize,
                                        cval=v,
                                        sval=sp.nan)
        ims = stim.get_center_surround(size=size,
                                       csize=csize,
                                       cval=sp.nan,
                                       sval=v)
        x2 = model_utils.get_population(imc2, **ppop)
        xs = model_utils.get_population(ims, **ppop)
        x[0, vdx] = (x1 + x2) / 2.
        x[1, vdx] = (x1 + x2) / 2. + xs
    x.shape = (2 * len(vals), npoints, size, size)

    # trott and born 2015 data
    gt = get_gt(npoints, csvfiles)

    extra_vars = {}
    extra_vars['scale'] = scale
    extra_vars['npoints'] = npoints
    extra_vars['cval'] = cval
    extra_vars['cvals'] = cvals
    extra_vars['svals'] = svals
    extra_vars['size'] = size
    extra_vars['csize'] = csize
    extra_vars['vals'] = vals
    extra_vars['neuron_theta'] = neuron_theta
    extra_vars['figure_name'] = 'tbp'
    extra_vars['return_var'] = 'O'
    extra_vars['hp_file'] = os.path.join(defaults._FIGURES, 'best_hps.npz')

    optimize_model(x, gt, extra_vars, defaults)
def create_stims(extra_vars):
    extra_vars = Bunch(extra_vars)
    out_dir = re.split('\.', extra_vars.f4_stimuli_file)[0]
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    #################
    nc = len(extra_vars._DEFAULT_KW2015_SO_PARAMETERS['selected_channels'])

    # build stimuli
    ###############
    all_hues_dkls = sp.linspace(0.0,
                                2 * sp.pi,
                                extra_vars.n_train,
                                endpoint=False)
    test_hues_dklS = all_hues_dkls[::extra_vars.n_train //
                                   extra_vars.n_t_hues][:extra_vars.n_t_hues]
    surr_hues_dklS = test_hues_dklS[::extra_vars.n_t_hues //
                                    extra_vars.n_s_hues][:extra_vars.n_s_hues]
    #sp.linspace(0.0, 2*sp.pi, n_s_hues, endpoint=False)
    test_sat_dklS = 0.2
    surr_sat_dklS = 0.16
    isolum_el = 0.0  # elevation is 0 to get isolumination to background

    stims_all_lms = sp.zeros(
        (extra_vars.n_train, extra_vars.size, extra_vars.size, 3))
    stims_ind_lms = sp.zeros((extra_vars.n_t_hues, extra_vars.n_s_hues,
                              extra_vars.size, extra_vars.size, 3))

    pbar_counter = 0
    pbar = pb((extra_vars.n_s_hues + 1) * extra_vars.n_train,
              'Building isoluminant stimuli [all]')
    for i, azt in enumerate(all_hues_dkls):
        dklS_ = sp.array([test_sat_dklS, azt, isolum_el])
        c_lms_ = dklC2lms(sph2cart(dklS_))
        stims_all_lms[i, ...,
                      0] = stim.get_center_surround(size=extra_vars.size,
                                                    csize=extra_vars.csize,
                                                    cval=c_lms_[0],
                                                    sval=gray_lms[0])
        stims_all_lms[i, ...,
                      1] = stim.get_center_surround(size=extra_vars.size,
                                                    csize=extra_vars.csize,
                                                    cval=c_lms_[1],
                                                    sval=gray_lms[1])
        stims_all_lms[i, ...,
                      2] = stim.get_center_surround(size=extra_vars.size,
                                                    csize=extra_vars.csize,
                                                    cval=c_lms_[2],
                                                    sval=gray_lms[2])

        pbar_counter += 1
        pbar.update(pbar_counter)
    pbar.finish()

    pbar_counter = 0
    pbar = pb((extra_vars.n_s_hues + 1) * extra_vars.n_t_hues,
              'Building isoluminant stimuli [ind]')
    for i, azt in enumerate(test_hues_dklS):
        dklS_ = sp.array([test_sat_dklS, azt, isolum_el])
        c_lms_ = dklC2lms(sph2cart(dklS_))
        for j, azs in enumerate(surr_hues_dklS):
            dklS_ = sp.array([surr_sat_dklS, azs, isolum_el])
            s_lms_ = dklC2lms(sph2cart(dklS_))
            stims_ind_lms[i, j, ...,
                          0] = stim.get_center_surround(size=extra_vars.size,
                                                        csize=extra_vars.csize,
                                                        cval=c_lms_[0],
                                                        sval=s_lms_[0])
            stims_ind_lms[i, j, ...,
                          1] = stim.get_center_surround(size=extra_vars.size,
                                                        csize=extra_vars.csize,
                                                        cval=c_lms_[1],
                                                        sval=s_lms_[1])
            stims_ind_lms[i, j, ...,
                          2] = stim.get_center_surround(size=extra_vars.size,
                                                        csize=extra_vars.csize,
                                                        cval=c_lms_[2],
                                                        sval=s_lms_[2])

            pbar_counter += 1
            pbar.update(pbar_counter)
    pbar.finish()

    # compute vanilla SO features for those stimuli
    ###############################################
    so_all = sp.zeros(
        (extra_vars.n_train, nc, extra_vars.size, extra_vars.size))
    so_ind = sp.zeros((extra_vars.n_t_hues, extra_vars.n_s_hues, nc,
                       extra_vars.size, extra_vars.size))

    pbar = pb(extra_vars.n_train, 'Computing SO features [all]')
    for idx in range(extra_vars.n_train):
        so_all[idx] = GET_SO(stims_all_lms[idx], extra_vars._DEFAULT_FLOATX_NP,
                             extra_vars._DEFAULT_KW2015_SO_PARAMETERS)
        pbar.update(idx)
    pbar.finish()

    pbar = pb(extra_vars.n_t_hues * extra_vars.n_s_hues,
              'Computing SO features [ind]')
    for idx in range(extra_vars.n_t_hues):
        for jdx in range(extra_vars.n_s_hues):
            so_ind[idx, jdx] = GET_SO(stims_ind_lms[idx, jdx],
                                      extra_vars._DEFAULT_FLOATX_NP,
                                      extra_vars._DEFAULT_KW2015_SO_PARAMETERS)
            pbar.update(jdx + idx * extra_vars.n_s_hues)
    pbar.finish()
    so_ind = so_ind.reshape(extra_vars.n_t_hues * extra_vars.n_s_hues, nc,
                            extra_vars.size, extra_vars.size)

    #Final ops
    cs_hue_diff = da2ha(test_hues_dklS.reshape(extra_vars.n_t_hues, 1) - \
        surr_hues_dklS.reshape(1, extra_vars.n_s_hues))
    cs_hue_diff *= (180 / sp.pi)
    np.savez(extra_vars.f4_stimuli_file,
             so_all=so_all,
             so_ind=so_ind,
             stims_all_lms=stims_all_lms,
             cs_hue_diff=cs_hue_diff)
Beispiel #5
0
def run(hps=None):
    defaults = PaperDefaults()

    #David's globals
    size=51
    csize=9
    npoints=37
    scale=1.
    _DEFAULT_BWC_CSV_CTS = sp.array([0.0, .06, .12, .25, .50]) * 100
    csvfiles=sp.array([[os.path.join(defaults._DATADIR, 'BWC2009_%i_%i.csv' \
    % (i, j)) for i in _DEFAULT_BWC_CSV_CTS] for j in _DEFAULT_BWC_CSV_CTS]).T

    # experiment parameters
    im = sp.array([
        stim.get_center_surround(
            size=size, csize=csize, cval=.25, sval=sp.nan),
        stim.get_center_surround(
            size=size, csize=csize, cval=.75, sval=sp.nan)])

    # populations for vertical (masking) and horizontal (driving) stimuli
    #####################################################################
    xv = model_utils.get_population(im[0],
        kind='circular', npoints=npoints, scale=scale)
    xh = model_utils.get_population(im[1],
        kind='circular', npoints=npoints, scale=scale)

    # superimposed populations
    ##########################
    v_contrasts = [0.0, .06, .12, .25, .50]
    h_contrasts = [0.0, .06, .12, .25, .50]
    nv, nh = len(v_contrasts), len(h_contrasts)
    x = sp.array([[h*xh + v*xv for h in h_contrasts] for v in v_contrasts])
    x.shape = (nv * nh,) + x.shape[2:]

    # busse and wade data
    t_paper = sp.zeros((nv, nh, 13))
    y_paper = sp.zeros((nv, nh, 13))

    for idx in range(nv):
        for jdx in range(nh):
            t_paper[idx, jdx], y_paper[idx, jdx] = \
                sp.genfromtxt(csvfiles[idx, jdx], delimiter=',').T

    res_y_paper = sp.zeros((y_paper.shape[0],y_paper.shape[1],npoints))
    for r in range(y_paper.shape[0]):
        for c in range(y_paper.shape[1]):
            res_y_paper[r,c,:] = sp.signal.resample(y_paper[r,c,:],npoints)
    gt = [t_paper,res_y_paper]            

    extra_vars = {}
    extra_vars['scale'] = scale
    extra_vars['npoints'] = npoints
    extra_vars['size'] = size
    extra_vars['csize'] = csize
    extra_vars['nv'] = nv
    extra_vars['nh'] = nh
    extra_vars['figure_name'] = 'bw'
    extra_vars['return_var'] = 'O'

    defaults = adjust_parameters(defaults,hps)
    optimize_model(x,gt,extra_vars,defaults)