Beispiel #1
0
            for j in np.unique(which_neuron[session_st==i])] for k in stim_on[these_trials]]
    pseudopop.append(act)

binned = np.concatenate(pseudopop, axis=1).transpose((1, 0, 2))

print('Binned the data')

#%%
nT = binned.shape[2]
nTri = binned.shape[1]

labels = (np.arange(nTri) > (nTri // 2)).astype(int)
# labels = np.random.permutation(np.arange(nTri)>(nTri//2)).astype(int)
times = (np.arange(nT)[None, :] * np.ones((nTri, 1))).astype(int)

clf = assistants.LinearDecoder(binned.shape[0], 1, svm.LinearSVC)
clf.fit(binned[:, :70, :].transpose(1, 2, 0),
        labels[:70, None, None] * np.ones((1, nT, 1)),
        t_=(np.arange(nT)[None, :] * np.ones((70, 1))).astype(int))

perf = clf.test(binned[:, 70:, :].transpose(1, 2, 0),
                labels[70:, None, None] * np.ones((1, nT, 1)),
                t_=(np.arange(nT)[None, :] * np.ones(
                    (nTri - 70, 1))).astype(int))

#%%

data = gio.Dataset.from_readfunc(swa.load_buschman_data,
                                 BASE_DIR,
                                 max_files=np.inf,
                                 seconds=True)
Beispiel #2
0
     else:
         task_dics.append(list(np.setdiff1d(range(num_cond),d)))
 # if num_cond>8:
 Q = len(task_dics)
 D_fake = assistants.Dichotomies(num_cond, task_dics, extra=50)
 mi = np.array([fake_task.information(p) for p in D_fake])
 midx = np.append(range(Q),np.flip(np.argsort(mi[Q:]))+Q)
 # these_dics = args['dichotomies'] + [D_fake.combs[i] for i in midx]
 D = assistants.Dichotomies(num_cond, [D_fake.combs[i] for i in midx], extra=0)
 # else:
     # Q = len(args['dichotomies'])
     # D = assistants.Dichotomies(num_cond)
     # mi = np.array([fake_task.information(p) for p in D])
     # midx = np.arange(D.ntot, dtype=int)
 
 clf = assistants.LinearDecoder(z.shape[1], 1, assistants.MeanClassifier)
 gclf = assistants.LinearDecoder(z.shape[1], 1, svm.LinearSVC)
 dclf = assistants.LinearDecoder(z.shape[1], D.ntot, svm.LinearSVC)
 # clf = LinearDecoder(this_exp.dim_input, 1, MeanClassifier)
 # gclf = LinearDecoder(this_exp.dim_input, 1, svm.LinearSVC)
 # dclf = LinearDecoder(this_exp.dim_input, D.ntot, svm.LinearSVC)
 
 # K = int(num_cond/2) - 1 # use all but one pairing
 K = int(num_cond/4) # use half the pairings
 
 PS = np.zeros(D.ntot)
 CCGP = [] #np.zeros((D.ntot, 100))
 out_corr = []
 spec = []
 d = np.zeros((n_compute, D.ntot))
 pos_conds = []
Beispiel #3
0
    # z = linreg.predict(this_exp.train_data[0])@W1.T
    n_compute = np.min([5000, z.shape[0]])

    idx = np.random.choice(z.shape[0], n_compute, replace=False)
    # idx_tst = idx[::4] # save 1/4 for test set
    # idx_trn = np.setdiff1d(idx, idx_tst)

    cond = this_exp.train_conditions[idx]
    # cond = util.decimal(this_exp.train_data[1][idx,...])
    num_cond = len(np.unique(cond))

    xor = np.where(~(np.isin(range(8), args['dichotomies'][0])
                     ^ np.isin(range(8), args['dichotomies'][1])))[0]
    # Loop over dichotomies
    D = assistants.Dichotomies(num_cond, args['dichotomies'] + [xor], extra=50)
    clf = assistants.LinearDecoder(N, 1, assistants.MeanClassifier)
    gclf = assistants.LinearDecoder(N, 1, svm.LinearSVC)
    dclf = assistants.LinearDecoder(N, D.ntot, svm.LinearSVC)
    # clf = LinearDecoder(this_exp.dim_input, 1, MeanClassifier)
    # gclf = LinearDecoder(this_exp.dim_input, 1, svm.LinearSVC)
    # dclf = LinearDecoder(this_exp.dim_input, D.ntot, svm.LinearSVC)

    # K = int(num_cond/2) - 1 # use all but one pairing
    K = int(num_cond / 4)  # use half the pairings

    PS = np.zeros(D.ntot)
    CCGP = np.zeros(D.ntot)
    d = np.zeros((n_compute, D.ntot))
    pos_conds = []
    for i, pos in enumerate(D):
        pos_conds.append(pos)
    z = emb(this_exp.train_data[1], newf=f)
       
    centroids = np.stack([z[cond==i,:].mean(0) for i in np.unique(cond)])

    _, S, _ = la.svd(centroids-centroids.mean(0)[None,:],full_matrices=False)
    pr_.append(((S**2).sum()**2)/(S**4).sum())
    
    # # U = [email protected]()@V.T
    # U = (z[:ndat,:]+eps1)@V.T
    # U = [email protected]
    # pcs.append(U)
    
    eps1 = np.random.randn(ndat, dim)*noise
    eps2 = np.random.randn(ndat, dim)*noise
    
    clf = assistants.LinearDecoder(dim, 1, assistants.MeanClassifier)
    gclf = assistants.LinearDecoder(dim, 1, svm.LinearSVC)
    # rclf = svm.LinearSVC()
    rclf = linear_model.LogisticRegression()
    
    D_fake = assistants.Dichotomies(len(np.unique(this_exp.train_conditions)), this_exp.task.positives, extra=50)
    Q = len(this_exp.task.positives)
    mi = np.array([this_exp.task.information(p) for p in D_fake])
    midx = np.append(range(Q),np.flip(np.argsort(mi[Q:]))+Q)
    # these_dics = args['dichotomies'] + [D_fake.combs[i] for i in midx]
    D = assistants.Dichotomies(len(np.unique(cond)), [D_fake.combs[i] for i in midx], extra=0)
    
    PS = []
    DCorr_res = []
    DCorr_proj = []
    DCorr_marg = []