def run_KW(k, w): resp1.append([]) resp2.append([]) resp3.append([]) nresp1.append([]) nresp2.append([]) nresp3.append([]) W = w CC = cov(N, .6) NC = cov(N, .6 * w) NC = NC * np.linalg.norm(CC) / np.linalg.norm(NC) NN = 0 * np.random.multivariate_normal(np.zeros(len(NC)), NC, [3, NUM_CON]) stim1 = np.array([cc * I1 for cc in con]) stim2 = np.array([cc * I2 for cc in con]) stim3 = np.array([cc * I3 for cc in con]) resp1[-1].append(MGSM.gexp(0, stim1 + NN[0] / (k), CC, NC / (k * k))) resp2[-1].append(MGSM.gexp(0, stim2 + NN[1] / (k), CC, NC / (k * k))) resp3[-1].append(MGSM.gexp(0, stim3 + NN[2] / (k), CC, NC / (k * k))) nresp1[-1].append(MGSM.gnn(stim1 + 0 * NN[0] / (k), CC)[:, 0]) nresp2[-1].append(MGSM.gnn(stim2 + 0 * NN[0] / (k), CC)[:, 0]) nresp3[-1].append(MGSM.gnn(stim3 + 0 * NN[0] / (k), CC)[:, 0])
def make_GSM_resp(filt, quenched, K, mgs, tag, COR, ncor, n_trial=1): #make sure everything is the right type assert quenched in (True, False) assert type(ncor) == np.ndarray GV = [] GVnn = [] #generate samples for each filter set if quenched: nftemp = np.tile(filt, [n_trial, 1]) print(nftemp.shape) noise = np.reshape( np.random.multivariate_normal(np.zeros(np.prod(nftemp.shape[1:])), ncor, n_trial * filt.shape[0]), tuple([n_trial * filt.shape[0]]) + filt.shape[1:]) nftemp += noise else: nftemp = filt #run it for each value of k for k in K: GV.append( np.array([ MGSM.gexp(i, nftemp, COR, k * k * ncor, precom=True) for i in range(filt.shape[1]) ]).transpose()) GVnn.append(MGSM.gnn(filt, COR)) print(GV[-1].shape) GV = np.concatenate(GV) GVnn = np.concatenate(GVnn) print(tag) print(GV.shape) print(GVnn.shape) np.savetxt(tag + "_noisy.csv", GV) np.savetxt(tag + "_clean.csv", GVnn)
def run(): #what it is that we want to do here? We want to look at COS resp1 = [] resp2 = [] resp3 = [] nresp1 = [] nresp2 = [] nresp3 = [] NUM_CURVE = 20 NUM_CON = 50 CMAX = 2.5 CMIN = -2 N = 8 I1 = inp(N, float(N) / 5, 1, 1, -1 + N / 2) I2 = inp(N, float(N) / 5, 1, 0, -1 + N / 2) I3 = inp(N, float(N) / 5, 0, 1, -1 + N / 2) KK = np.logspace(-1, 1, NUM_CURVE) for k in KK: print(k) W = float(N) / (5) CC = cov(N, W) NC = CC np.savetxt("./covariance_test.csv", CC) stim1 = np.array([cc * I1 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim2 = np.array([cc * I2 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim3 = np.array([cc * I3 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) resp1.append(MGSM.gexp(0, stim1, CC, NC / (k * k), precom=False)) resp2.append(MGSM.gexp(0, stim2, CC, NC / (k * k), precom=False)) resp3.append(MGSM.gexp(0, stim3, CC, NC / (k * k), precom=False)) nresp1.append(MGSM.gnn(stim1, CC)[:, 0]) nresp2.append(MGSM.gnn(stim2, CC)[:, 0]) nresp3.append(MGSM.gnn(stim3, CC)[:, 0]) resp1 = np.array(resp1) resp2 = np.array(resp2) resp3 = np.array(resp3) nresp1 = np.array(nresp1) nresp2 = np.array(nresp2) nresp3 = np.array(nresp3) AI = resp1 / (resp2 + resp3) nAI = nresp1 / (nresp2 + nresp3) fig = plt.figure() ax = fig.add_subplot(111) ax.set_prop_cycle("color", [cm(1. * i / NUM_CURVE) for i in range(NUM_CURVE)]) K = np.linspace(.5, 5, NUM_CURVE) cc = np.logspace(CMIN, CMAX, NUM_CON) / (10**CMAX) for k in range(0, len(AI), 1): ax.plot(cc, AI[k], label=str(K[k])) ax.plot(cc, nAI[k], '--') handles, labels = ax.get_legend_handles_labels() # ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, # ncol=2, mode="expand", borderaxespad=0.) ax.plot(cc, [1 for k in range(len(cc))], 'k--') plt.xscale('log') fig.savefig("./paramfig.pdf") MAX = np.array([[KK[k], np.max(AI[k])] for k in range(len(AI))]) plt.figure() plt.plot(MAX[:, 0], MAX[:, 1], "r") plt.xscale('log') plt.savefig("./max_AI_by_k.pdf") pts = [] for k in range(len(AI)): print(np.argmax(AI[k])) for j in range(np.argmax(AI[k]), len(AI[k]) - 1): if AI[k][j] >= 1 and AI[k][j + 1] <= 1: pts.append([KK[k], cc[j]]) break pts = np.array(pts) plt.figure() plt.plot(pts[:, 0], pts[:, 1]) plt.xscale('log') plt.yscale('log') plt.savefig("./trans_by_K.pdf")
def run(): def c2(c): return np.array([[1., c], [c, 1.]]) def cov(n, w, dr=0): distance = np.array([[((i - j + (n / 2.)) % n) - n / 2. for i in range(n)] for j in range(n)]) gauss = np.exp(-(distance**2) / (2. * w * w)) - dr out = np.dot(gauss, gauss) return out / out[0, 0] def inp(n, w, c1, c2, i): stim1 = np.array([((j + (n / 2.)) % n) - (n / 2.) for j in range(n)]) stim2 = np.array([(((j - (i % n)) + (n / 2.)) % n) - (n / 2.) for j in range(n)]) gauss1 = np.exp(-(stim1**2) / (2. * w * w)) gauss2 = np.exp(-(stim2**2) / (2. * w * w)) return c1 * gauss1 + c2 * gauss2 LO = [] HI = [] nnLO = [] nnHI = [] ip = np.array([[1, 0], [0, 1], [1, 1]]) for c in np.linspace(-.9, .9, 20): cov = c2(c) nc = np.identity(2) * (1 + c) sHI = GSM.gexp(0, 20 * ip, cov, nc * (2 * 2), precom=True) sLO = GSM.gexp(0, ip, cov, nc * (2 * 2), precom=False) snnLO = GSM.gnn(ip, cov)[:, 0] snnHI = GSM.gnn(20 * ip, cov)[:, 0] HI.append([c, sHI[2] / (sHI[0])]) LO.append([c, sLO[2] / (sLO[0])]) nnHI.append([c, snnHI[2] / (snnHI[0])]) nnLO.append([c, snnLO[2] / (snnLO[0])]) HI = np.array(HI) LO = np.array(LO) nnHI = np.array(nnHI) nnLO = np.array(nnLO) plt.plot(HI[:, 0], [1 for x in HI], 'k--', linewidth=1) plt.plot(HI[:, 0], HI[:, 1], 'k') plt.plot(nnHI[:, 0], nnHI[:, 1], 'k--') plt.plot(LO[:, 0], LO[:, 1], 'r') plt.plot(nnLO[:, 0], nnLO[:, 1], 'r--') plt.xlabel("Correlation") plt.ylabel("Modulation Ratio") plt.xlim(-1, 1) plt.ylim(0, 2) plt.xticks([-.5, 0, .5]) plt.tight_layout() plt.savefig("./2DAIparam.pdf") print("done with AI") #what it is that we want to do here? We want to look at COS con = 20 * np.logspace(-2, 0, 50) NN = 2 WW = np.array([.15]) out1 = [] out2 = [] nnout1 = [] nnout2 = [] out12 = [] out22 = [] nnout12 = [] nnout22 = [] NCOV = np.identity(2) k = .75 I1 = np.array([[c1, c1 / 10] for c1 in con]) I2 = np.array([[c1 + con[-1] / 10, con[-1] + c1 / 10] for c1 in con]) I12 = np.array([[c1, 0] for c1 in con]) I22 = np.array([[c1, con[-1]] for c1 in con]) print(I1.shape) print(I2.shape) CC = c2(.6) NCOV = np.identity(2) out1 = GSM.gexp(0, I1, CC, NCOV / (k * k), precom=False) out2 = GSM.gexp(0, I2, CC, NCOV / (k * k), precom=False) nnout1 = GSM.gnn(I1, CC).T nnout2 = GSM.gnn(I2, CC).T out12 = GSM.gexp(0, I12, CC, NCOV / (k * k), precom=False) out22 = GSM.gexp(0, I22, CC, NCOV / (k * k), precom=False) nnout12 = GSM.gnn(I12, CC).T nnout22 = GSM.gnn(I22, CC).T print(nnout2) plt.figure() plt.plot(con / con[-1], out1, 'r') plt.plot(con / con[-1], out2, 'k') plt.plot(con / con[-1], nnout1[0], 'r--') plt.plot(con / con[-1], nnout2[0], 'k--') plt.xlabel("contrast") plt.ylabel("Respose") # plt.yscale("log") plt.xscale("log") plt.tight_layout() plt.savefig("./2Dssfig_0.pdf") plt.figure() plt.plot(con / con[-1], out12, 'r') plt.plot(con / con[-1], out22, 'k') plt.plot(con / con[-1], nnout12[0], 'r--') plt.plot(con / con[-1], nnout22[0], 'k--') plt.xlabel("contrast") plt.ylabel("Respose") # plt.yscale("log") plt.xscale("log") plt.tight_layout() plt.savefig("./2Dssfig_1.pdf")
def run_k(): #what it is that we want to do here? We want to look at COS resp1 = [] resp2 = [] resp3 = [] nresp1 = [] nresp2 = [] nresp3 = [] NUM_CURVE = 10 NUM_CON = 50 NUM_W = 20 CMAX = 1. CMIN = -2. N = 8 I1 = inp(N, .6, 1, 1, -1 + N / 2) I2 = inp(N, .6, 1, 0, -1 + N / 2) I3 = inp(N, .6, 0, 1, -1 + N / 2) KK = np.logspace(0, 1, NUM_CURVE) con = np.logspace(CMIN, CMAX, NUM_CON) WW = np.linspace(.1, 2, NUM_W) for w in range(len(WW)): resp1.append([]) resp2.append([]) resp3.append([]) nresp1.append([]) nresp2.append([]) nresp3.append([]) for k in KK: print(k) W = WW[w] CC = cov(N, W) NC = CC np.savetxt("./covariance_test.csv", CC) stim1 = np.array( [cc * I1 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim2 = np.array( [cc * I2 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim3 = np.array( [cc * I3 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) resp1[w].append(MGSM.gexp(0, stim1, CC, NC / (k * k))) #,precom = False)) resp2[w].append(MGSM.gexp(0, stim2, CC, NC / (k * k))) #,precom = False)) resp3[w].append(MGSM.gexp(0, stim3, CC, NC / (k * k))) #,precom = False)) nresp1[w].append(MGSM.gnn(stim1, CC)[:, 0]) nresp2[w].append(MGSM.gnn(stim2, CC)[:, 0]) nresp3[w].append(MGSM.gnn(stim3, CC)[:, 0]) resp1 = np.array(resp1) resp2 = np.array(resp2) resp3 = np.array(resp3) nresp1 = np.array(nresp1) nresp2 = np.array(nresp2) nresp3 = np.array(nresp3) AI = resp1 / (resp2 + resp3) nAI = nresp1 / (nresp2 + nresp3) fig = plt.figure() ax = fig.add_subplot(111) ax.set_prop_cycle("color", [cm(1. * i / NUM_CURVE) for i in range(NUM_CURVE)]) K = np.linspace(.5, 5, NUM_CURVE) cc = 100 * np.logspace(CMIN, CMAX, NUM_CON) / (10**CMAX) for w in [1]: for k in range(0, len(AI[w]), len(AI[w]) / 5): ax.plot(100 * con / np.max(con), AI[w, k], label=str(K[k])) ax.plot(100 * con / np.max(con), nAI[w, k], '--') handles, labels = ax.get_legend_handles_labels() # ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, # ncol=2, mode="expand", borderaxespad=0.) ax.plot(cc, [1 for k in range(len(cc))], 'k--') plt.xlabel("Contrast") plt.ylabel("A.I.") plt.tight_layout() fig.savefig("./paramfig_K.pdf") fig = plt.figure() ax = fig.add_subplot(111) ax.set_prop_cycle("color", [cm(1. * i / NUM_CURVE) for i in range(NUM_CURVE)]) WW = np.linspace(.1, 2, NUM_W) cc = 100 * np.logspace(CMIN, CMAX, NUM_CON) / (10**CMAX) for k in [5]: for w in range(0, len(AI), len(AI) / 5): ax.plot(100 * con / np.max(con), AI[w, k], label=str(WW[w])) ax.plot(100 * con / np.max(con), nAI[w, k], '--') handles, labels = ax.get_legend_handles_labels() # ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, # ncol=2, mode="expand", borderaxespad=0.) ax.plot(cc, [1 for k in range(len(cc))], 'k--') plt.xlim([0, 20]) plt.xlabel("Contrast") plt.ylabel("A.I.") plt.tight_layout() fig.savefig("./paramfig_W.pdf") plt.figure() for w in [5]: MAX = np.array([[1. / KK[k], np.max(AI[w, k])] for k in range(len(AI[w]))]) plt.plot(MAX[:, 0], MAX[:, 1], colortab[0]) # plt.xscale('log') plt.xlabel("1/SNR") plt.ylabel("A.I.") plt.tight_layout() plt.savefig("./max_AI_by_k.pdf") plt.figure() for k in [5]: MAX = np.array([[WW[w] * 180. / np.pi, np.max(AI[w, k])] for w in range(len(AI))]) plt.plot(MAX[:, 0], MAX[:, 1], colortab[0]) plt.xlabel("Width (deg.)") plt.ylabel("A.I.") plt.tight_layout() plt.savefig("./max_AI_by_W.pdf") plt.figure() for w in [5]: pts = [] for k in range(len(AI[w])): pts.append( [1. / KK[k], get_trans(AI[w, k], 100 * con / np.max(con))]) pts = np.array(pts) plt.plot(pts[:, 0], pts[:, 1], colortab[0]) plt.xlabel("1/SNR") plt.ylabel("Contrast") plt.xscale('log') plt.yscale('linear') plt.tight_layout() plt.savefig("./trans_by_K.pdf") plt.figure() for k in [5]: pts = [] for w in range(len(AI)): pts.append([ WW[w] * 180. / np.pi, get_trans(AI[w, k], 100 * con / np.max(con)) ]) pts = np.array(pts) plt.plot(pts[:, 0], pts[:, 1], colortab[0]) plt.xlabel("Width (deg.)") plt.ylabel("Contrast") plt.yscale('linear') plt.tight_layout() plt.savefig("./trans_by_W.pdf")
def run_cov(): #what it is that we want to do here? We want to look at COS resp1 = [] resp2 = [] resp3 = [] nresp1 = [] nresp2 = [] nresp3 = [] NUM_CURVE = 10 NUM_CON = 50 NUM_W = 10 CMAX = 1. CMIN = -1. N = 8 I1 = inp(N, .6, 1, 1, -1 + N / 2) I2 = inp(N, .6, 1, 0, -1 + N / 2) I3 = inp(N, .6, 0, 1, -1 + N / 2) KK = np.logspace(0, 1, NUM_CURVE) con = np.logspace(CMIN, CMAX, NUM_CON) WW = [.1, .5, 1.] for k in WW: print(k) CC = cov(N, .5) if k == WW[0]: NC = np.identity(N) else: NC = cov(N, k) NC = NC * np.linalg.norm(CC) / (np.linalg.norm(NC) * 4) sn = 1 stim1 = np.array([cc * I1 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim2 = np.array([cc * I2 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim3 = np.array([cc * I3 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) resp1.append(sn * MGSM.gexp(0, stim1 / sn, CC, NC, precom=False)) resp2.append(sn * MGSM.gexp(0, stim2 / sn, CC, NC, precom=False)) resp3.append(sn * MGSM.gexp(0, stim3 / sn, CC, NC, precom=False)) nresp1.append(MGSM.gnn(stim1, CC)[:, 0]) nresp2.append(MGSM.gnn(stim2, CC)[:, 0]) nresp3.append(MGSM.gnn(stim3, CC)[:, 0]) resp1 = np.array(resp1) resp2 = np.array(resp2) resp3 = np.array(resp3) nresp1 = np.array(nresp1) nresp2 = np.array(nresp2) nresp3 = np.array(nresp3) AI = resp1 / (resp2 + resp3) nAI = nresp1 / (nresp2 + nresp3) print(AI[-1]) fig = plt.figure() ax = fig.add_subplot(111) ax.set_prop_cycle("color", [cm(1. * i / NUM_CURVE) for i in range(NUM_CURVE)]) K = np.linspace(.5, 5, NUM_CURVE) cc = 100 * np.logspace(CMIN, CMAX, NUM_CON) / (10**CMAX) for k in range(0, len(AI)): ax.plot(100 * con / np.max(con), AI[k], colortab[k], label=str(K[k])) ax.plot(100 * con / np.max(con), nAI[k], colortab[k] + '--') handles, labels = ax.get_legend_handles_labels() # ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, # ncol=2, mode="expand", borderaxespad=0.) ax.plot(cc, [1 for k in range(len(cc))], 'k--') plt.xlabel("Contrast") plt.ylabel("A.I.") plt.tight_layout() fig.savefig("./paramfig_NC.pdf")
0, 16, 0, 5 * 16, int(np.max(np.linalg.norm(sites, axis=1))), get_grat=True) inp = np.array([get_grating_data(g, sites, RF) / fac for g in grat]) nc = CNS f = .5 * np.identity(len(CNS)) q = inf.Q_self_con(CNS, f) inp += np.random.multivariate_normal(np.zeros_like(inp[0]), nc, len(inp)) aI = np.tile(np.expand_dims(inp, 1), [1, 3, 1]) resp = inf.gnn(inp, CNS) iresp = inf.att_gexp(0, aI, CNS, nc, q, f) f = .75 * np.identity(len(CNS)) q = inf.Q_self_con(CNS, f) aresp = inf.att_gexp(0, aI, CNS, nc, q, f) print(oris) np.savetxt("./random_gsm_resp.csv", resp) np.savetxt("./a_random_gsm_resp.csv", aresp) np.savetxt("./i_random_gsm_resp.csv", iresp)
def run_k(): #what it is that we want to do here? We want to look at COS resp1 = [] resp2 = [] resp3 = [] nresp1 = [] nresp2 = [] nresp3 = [] NUM_CURVE = 10 NUM_CON = 50 CMAX = 1. CMIN = -2. N = 8 I1 = inp(N, .6, 1, 1, -1 + N / 2) I2 = inp(N, .6, 1, 0, -1 + N / 2) I3 = inp(N, .6, 0, 1, -1 + N / 2) KK = np.logspace(0, 1, NUM_CURVE) con = np.logspace(CMIN, CMAX, NUM_CON) if 0: for k in KK: print(k) W = .6 CC = cov(N, W) NC = CC np.savetxt("./covariance_test.csv", CC) stim1 = np.array( [cc * I1 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim2 = np.array( [cc * I2 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim3 = np.array( [cc * I3 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) resp1.append(MGSM.gexp(0, stim1, CC, NC / (k * k), precom=False)) resp2.append(MGSM.gexp(0, stim2, CC, NC / (k * k), precom=False)) resp3.append(MGSM.gexp(0, stim3, CC, NC / (k * k), precom=False)) nresp1.append(MGSM.gnn(stim1, CC)[:, 0]) nresp2.append(MGSM.gnn(stim2, CC)[:, 0]) nresp3.append(MGSM.gnn(stim3, CC)[:, 0]) np.savetxt("./param_files/kresp1.csv", resp1) np.savetxt("./param_files/kresp2.csv", resp2) np.savetxt("./param_files/kresp3.csv", resp3) np.savetxt("./param_files/knnresp1.csv", nresp1) np.savetxt("./param_files/knnresp2.csv", nresp2) np.savetxt("./param_files/knnresp3.csv", nresp3) else: resp1 = np.loadtxt("./param_files/kresp1.csv") resp2 = np.loadtxt("./param_files/kresp2.csv") resp3 = np.loadtxt("./param_files/kresp3.csv") nresp1 = np.loadtxt("./param_files/knnresp1.csv") nresp2 = np.loadtxt("./param_files/knnresp2.csv") nresp3 = np.loadtxt("./param_files/knnresp3.csv") resp1 = np.array(resp1) resp2 = np.array(resp2) resp3 = np.array(resp3) nresp1 = np.array(nresp1) nresp2 = np.array(nresp2) nresp3 = np.array(nresp3) AI = resp1 / (resp2 + resp3) nAI = nresp1 / (nresp2 + nresp3) fig = plt.figure() ax = fig.add_subplot(111) K = np.linspace(.5, 5, NUM_CURVE) cc = np.logspace(CMIN, CMAX, NUM_CON) / (10**CMAX) for k in range(0, len(AI), 2): ax.plot(con / np.max(con), AI[k], label=str(K[k])) ax.plot(con / np.max(con), nAI[k], '--') ax.plot(cc, [1 for k in range(len(cc))], 'k--') plt.tight_layout() plt.xlabel("contrast") plt.ylabel("AI") plt.ylim(0, 1.5) fig.savefig("./paramfig_K.pdf") MAX = np.array([[1. / KK[k], np.max(AI[k])] for k in range(len(AI))]) plt.figure() plt.plot(MAX[:, 0], MAX[:, 1], "r") plt.xscale('log') plt.tight_layout() plt.xlabel("1/SNR") plt.ylabel("Max AI") plt.savefig("./max_AI_by_k.pdf") plt.figure() plt.plot(con / np.max(con), resp2[NUM_CURVE / 2, :], "r") plt.plot(con / np.max(con), nresp2[NUM_CURVE / 2, :], "r--") plt.xscale('log') plt.tight_layout() plt.xlabel("Contrast") plt.ylabel("Response") plt.savefig("./param_CRF.pdf") pts = [] for k in range(len(AI)): pts.append([KK[k], get_trans(AI[k], con)]) pts = np.array(pts) plt.figure() plt.plot(1. / pts[:, 0], pts[:, 1]) plt.xscale('log') # plt.yscale('log') plt.tight_layout() plt.xlabel("1/SNR") plt.ylabel("Transition (con.)") plt.savefig("./trans_by_K.pdf")
def run_w(): #what it is that we want to do here? We want to look at COS resp1 = [] resp2 = [] resp3 = [] nresp1 = [] nresp2 = [] nresp3 = [] NUM_CURVE = 20 NUM_CON = 50 CMAX = 1 CMIN = -2 N = 8 I1 = inp(N, .6, 1, 1, -1 + N / 2) I2 = inp(N, .6, 1, 0, -1 + N / 2) I3 = inp(N, .6, 0, 1, -1 + N / 2) KK = np.linspace(.27, .75, NUM_CURVE) con = np.logspace(CMIN, CMAX, NUM_CON) if 0: for k in KK: print(k) W = k CC = cov(N, W) NC = cov(N, W) np.savetxt("./covariance_test.csv", CC) stim1 = np.array( [cc * I1 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim2 = np.array( [cc * I2 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) stim3 = np.array( [cc * I3 for cc in np.logspace(CMIN, CMAX, NUM_CON)]) resp1.append(MGSM.gexp(0, stim1, CC, NC / (2 * 2), precom=False)) resp2.append(MGSM.gexp(0, stim2, CC, NC / (2 * 2), precom=False)) resp3.append(MGSM.gexp(0, stim3, CC, NC / (2 * 2), precom=False)) nresp1.append(MGSM.gnn(stim1, CC)[:, 0]) nresp2.append(MGSM.gnn(stim2, CC)[:, 0]) nresp3.append(MGSM.gnn(stim3, CC)[:, 0]) np.savetxt("./param_files/wresp1.csv", resp1) np.savetxt("./param_files/wresp2.csv", resp2) np.savetxt("./param_files/wresp3.csv", resp3) np.savetxt("./param_files/wnnresp1.csv", nresp1) np.savetxt("./param_files/wnnresp2.csv", nresp2) np.savetxt("./param_files/wnnresp3.csv", nresp3) else: resp1 = np.loadtxt("./param_files/wresp1.csv") resp2 = np.loadtxt("./param_files/wresp2.csv") resp3 = np.loadtxt("./param_files/wresp3.csv") nresp1 = np.loadtxt("./param_files/wnnresp1.csv") nresp2 = np.loadtxt("./param_files/wnnresp2.csv") nresp3 = np.loadtxt("./param_files/wnnresp3.csv") resp1 = np.array(resp1) resp2 = np.array(resp2) resp3 = np.array(resp3) nresp1 = np.array(nresp1) nresp2 = np.array(nresp2) nresp3 = np.array(nresp3) AI = resp1 / (resp2 + resp3) nAI = nresp1 / (nresp2 + nresp3) fig = plt.figure() ax = fig.add_subplot(111) cc = con / np.max(con) for k in range(0, len(AI), 2): ax.plot(cc, AI[k], label=str(KK[k])) ax.plot(cc, nAI[k], '--') ax.plot(con / np.max(con), [1 for k in range(len(cc))], 'k--') plt.xlabel("contrast") plt.ylabel("A.I.") plt.ylim(.5, 1.25) plt.tight_layout() fig.savefig("./paramfig_W.pdf") MAX = np.array([[KK[k] * 180 / np.pi, np.max(AI[k])] for k in range(len(AI))]) plt.figure() plt.plot(MAX[:, 0], MAX[:, 1], "r") plt.xscale('log') plt.tight_layout() plt.xlabel("w") plt.ylabel("Max AI") plt.savefig("./max_AI_by_W.pdf") pts = [] for k in range(len(AI)): pts.append([KK[k], get_trans(AI[k], con)]) pts = np.array(pts) plt.figure() plt.plot(pts[:, 0], pts[:, 1]) plt.xscale('log') plt.yscale('log') plt.tight_layout() plt.xlabel("w") plt.ylabel("Transition (con)") plt.savefig("./trans_by_W.pdf") plt.figure() plt.plot(KK, AI[:, -6]) plt.tight_layout() plt.title("con. = {}".format(KK[-6])) plt.xlabel("w") plt.ylabel("High Contrast AI") plt.savefig("./HighAI_by_W.pdf")
def run_WDIFF_plots(): #what it is that we want to do here? We want to look at COS resp1 = [] resp2 = [] resp3 = [] nresp1 = [] nresp2 = [] nresp3 = [] NUM_CURVE = 10 NUM_CON = 50 NUM_W = 20 CMAX = 1. CMIN = -2. N = 8 I1 = inp(N,.6,1,1,-1 + N/2) I2 = inp(N,.6,1,0,-1 + N/2) I3 = inp(N,.6,0,1,-1 + N/2) WW = np.logspace(.1,10,NUM_CURVE) con = np.logspace(CMIN,CMAX,NUM_CON) for w in [0,1,-1]: resp1.append([]) resp2.append([]) resp3.append([]) nresp1.append([]) nresp2.append([]) nresp3.append([]) for k in WW: W = w CC = cov(N,.6) if W == 0 or W == -1: NC = cov_special(N,W) else: NC = CC.copy() NC = NC*np.linalg.norm(CC)/np.linalg.norm(NC) np.savetxt("./covariance_test.csv",CC) stim1 = np.array([cc * I1 for cc in np.logspace(CMIN,CMAX,NUM_CON)]) stim2 = np.array([cc * I2 for cc in np.logspace(CMIN,CMAX,NUM_CON)]) stim3 = np.array([cc * I3 for cc in np.logspace(CMIN,CMAX,NUM_CON)]) resp1[-1].append(MGSM.gexp(0,stim1,CC,NC/(k*k))) resp2[-1].append(MGSM.gexp(0,stim2,CC,NC/(k*k))) resp3[-1].append(MGSM.gexp(0,stim3,CC,NC/(k*k))) nresp1[-1].append(MGSM.gnn(stim1,CC)[:,0]) nresp2[-1].append(MGSM.gnn(stim2,CC)[:,0]) nresp3[-1].append(MGSM.gnn(stim3,CC)[:,0]) resp1 = np.array(resp1) resp2 = np.array(resp2) resp3 = np.array(resp3) nresp1 = np.array(nresp1) nresp2 = np.array(nresp2) nresp3 = np.array(nresp3) AI = resp1/(resp2+resp3) nAI = nresp1/(nresp2+nresp3) for w in range(len(AI)): fig = plt.figure() ax = fig.add_subplot(111) ax.set_prop_cycle("color",[cm(1.*i/NUM_CURVE) for i in range(NUM_CURVE)]) K = np.linspace(.5,5,NUM_CURVE) cc = 100*np.logspace(CMIN,CMAX,NUM_CON)/(10**CMAX) for k in range(0,len(AI[w]),len(AI[w])/5): ax.plot(100*con/np.max(con),AI[w,k],label=str(K[k])) ax.plot(100*con/np.max(con),nAI[w,k],'--') handles, labels = ax.get_legend_handles_labels() # ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, # ncol=2, mode="expand", borderaxespad=0.) ax.plot(cc,[1 for k in range(len(cc))],'k--') plt.xlim([0,20]) plt.xlabel("Contrast") plt.ylabel("A.I.") plt.tight_layout() fig.savefig("./paramfig_K_{}_by_W.pdf".format(w))