Beispiel #1
0
def spk_contr_var(spk, contr, fn, tl, make = 1, mn=0):
   if(make == 1):
      vr  = var(spk, axis = 1)*1000
      vr = mean(vr,axis=1)
      if(mn == 1):
         spk_avg = mean(mean(spk, axis=1), axis=1)
         contr = spk_avg * 1000
      savetxt("txt/spk_contr_var_vr.txt", vr)
      savetxt("txt/spk_contr_var_contr.txt", contr)
   else:
      vr = loadtxt("txt/spk_contr_var_vr.txt")
      contr = loadtxt("txt/spk_contr_var_contr.txt")
      
   bnr = 100
   l = 10
   vals, bins = bin_means(contr, vr, bnr)
   run_avg = running_mean(vals, l)
   print (run_avg)
   d = len(run_avg)
   print (d)
   plt.clf()
   plt.plot(contr, vr, 'go', alpha=.4)
   plt.plot(bins[l/2:d+l/2], run_avg, lw = 8, color = "red")
#   plt.ylim([0,300])
   if (mn == 1):
      myplot("mean spiking rate", "spike count variance", tl, fn, xlog=False, legend=False)   
   else:
      myplot("inferred contrast", "spike count variance", tl, fn, xlog=False, legend=False)
Beispiel #2
0
def spk_contr_fano(spk, contr, fn, tl, make = 1, mn=0):
   if(make == 1):
      vr  = var(spk, axis = 1)*1000
      vr = mean(vr,axis=1)
      spk_avg = mean(mean(spk, axis=1), axis=1)*1000

      savetxt("txt/vr.txt", vr)
      savetxt("txt/spk_avg.txt", spk_avg)
   else:
      vr = loadtxt("txt/vr.txt")
      spk_avg = loadtxt("txt/spk_avg.txt")
      
   fan = vr/spk_avg
   bnr = 100
   l = 10
   vals, bins = bin_means(spk_avg, fan, bnr)
   run_avg = running_mean(vals, l)
   print (run_avg)
   d = len(run_avg)
   print (d)
   plt.clf()
   plt.plot(spk_avg, fan, 'go', alpha=.4)
   plt.plot(bins[l/2:d+l/2], run_avg, lw = 8, color = "red") # was started from 1, first was buggy
#   plt.ylim([0.7,1.1])
   if (mn == 1):
      myplot("mean spiking rate", "Fano-factor of spiketrains", tl, fn, xlog=False, legend=False)   
   else:
      myplot("inferred contrast", "spike count variance", tl, fn, xlog=False, legend=False)
Beispiel #3
0
def do_it_matched_plot_fano(make=1):
   if(make==1):
      u_i = 1.0
      u_p = 3.3
      c_i = 19.6
      c_p = 0.8
#      u_arr = [1.95, 2.3, 2.9, 3.2, 3.5, 4]
      ui_arr = arange(u_i, u_i*4, u_i*0.3)
      up_arr = arange(u_p, u_p*2, u_p*0.1)
      n = len(ui_arr)
      pfano_arr = zeros(n)
      ifano_arr = zeros(n)
      pmean_arr = zeros(n)
      imean_arr = zeros(n)
      for i in range(0,n):
         print (i)
         pfano_arr[i], ifano_arr[i], pmean_arr[i], imean_arr[i] = do_it_matched_fano(ui_arr[i], up_arr[i], c_i, c_p)
      save("txt/matched_scale_fano.npy", [pfano_arr, ifano_arr, pmean_arr, imean_arr])
   else:
      pfano_arr, ifano_arr, pmean_arr, imean_arr = load("txt/matched_scale_fano.npy")
      
      
   tl = ""
   fn = "images/matched_scale_fano.png"
   plt.clf()
   plt.plot(pmean_arr, pfano_arr, "b.", label = "Poisson", ms = 10)
   [a,b] = polyfit(pmean_arr, pfano_arr, 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="blue")
   plt.plot(imean_arr, ifano_arr, "r.", label = "Integration", ms = 10)
   [a,b] = polyfit(imean_arr, ifano_arr, 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="red")
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   plt.xlim([25,65])
   myplot(r"$Mean_{SC}$", r"$Fano_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
Beispiel #4
0
def do_it_matched_plot(make=1):
   if(make==1):
#      u_arr = [1.95, 2.3, 2.9, 3.2, 3.5, 4]
      u_arr = arange(1.95, 4, 0.1)
      n = len(u_arr)
      pcoeff_arr = zeros(n)
      icoeff_arr = zeros(n)
      pvar_arr = zeros(n)
      pmean_arr = zeros(n)
      ivar_arr = zeros(n)
      imean_arr = zeros(n)
      for i in range(0,n):
         print (i)
         pcoeff_arr[i], icoeff_arr[i], pvar_arr[i], pmean_arr[i], ivar_arr[i], imean_arr[i] = do_it_matched(make=1, u_mean=u_arr[i])
      save("txt/matched_scale.npy", [pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr])
   else:
      pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr = load("txt/matched_scale.npy")
      
      
   tl = ""
   fn = "images/matched_scale.png"
   plt.clf()
   plt.plot(pmean_arr, pcoeff_arr, "b.", label = "Poisson", ms = 10)
   [a,b] = polyfit(pmean_arr, pcoeff_arr, 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="blue")
   plt.plot(imean_arr, icoeff_arr, "r.", label = "Integration", ms = 10)
   [a,b] = polyfit(imean_arr, icoeff_arr, 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="red")
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   plt.xlim([5,50])
   myplot(r"$Mean_{SC}$", r"$\rho_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
Beispiel #5
0
def make_barplot():
#variance(lp,hp,li,hi) [ 0.03763326] [ 0.08509415] [ 0.20487687] [ 0.20641627]
#[0.20641627, 0.20487687,0.08509415, 0.03763326] (hi, li, hp, lp)
#mean(lp,hp,li,hi)     [ 0.0377612]  [ 0.02496299] [ 0.20685853] [ 0.27907393]
#[0.20685853, 0.27907393, 0.0377612, 0.02496299] (li, hi, lp, hp)
   plt.clf()
   tl = ""
   name="tr2tr"
   diff="variance"
   fn = "images/%sdistrib_bar_%s.png"%(name,diff)
   plt.xticks([0.4,0.8], ["I","P"])
   barlist = plt.bar([0.3,0.4,0.7,0.8], [0.20641627, 0.20487687,0.08509415, 0.03763326], alpha = 0.7, width = 0.1, fill=False, lw=8)  
   barlist[0].set_color('b')
   barlist[1].set_color('r')
   barlist[2].set_color('b')
   barlist[3].set_color('r')
   myplot("", "", tl, fn, xlog=False, legend=False, xloc=False, fsax=50, fs = 50)
   
   plt.clf()
   tl = ""
   name="tr2tr"
   diff="mean"
   fn = "images/%sdistrib_bar_%s.png"%(name,diff)
   plt.xticks([0.4,0.8], ["I","P"])
   barlist = plt.bar([0.3,0.4,0.7,0.8], [0.20685853, 0.27907393, 0.0377612, 0.02496299], alpha = 0.7, width = 0.1, fill=False, lw=8)    
   barlist[0].set_color('b')
   barlist[1].set_color('r')
   barlist[2].set_color('b')
   barlist[3].set_color('r')
   myplot("", "", tl, fn, xlog=False, legend=False, xloc=False, fsax=50, fs = 50)
   return 0
Beispiel #6
0
def pairs_rates(rate_arr, fn, tl, b1, b2):
   br1 = rate_arr[:,b1]
   br2 = rate_arr[:,b2]
   plt.clf()
   plt.plot(br1, br2, "b.", ms = 10)
   plt.xlim([0, 80])
   plt.ylim([0, 90])
   myplot("rate of neuron 1", "rate of neuron 2", tl, fn, xlog=False, legend=False)
Beispiel #7
0
def pairs_samples(samp_arr, fn, tl, b1, b2):
   bs1 = samp_arr[:,b1]
   bs2 = samp_arr[:,b2]
   plt.clf()
   plt.plot(bs1, bs2, "b.", ms = 10)
   plt.xlim([-6, 9])
   plt.ylim([-6, 9])
   myplot("potential of neuron 1", "potential of neuron 2", tl, fn, xlog=False, legend=False)
Beispiel #8
0
def do_it_match_plotter3(make = 1):
   imgNr = 3000
   l = 50 # 500
   
   k_p = 10.0
   n_p = 1.1
   ut_p = 1.9
   
   k_i = 2.0
   n_i = 1.1
   ut_i = 1.9

   u_mi = 2.2
   u_mp = 2.2
   u_ci = 1500.0
   u_cp = .1
      
   c1 = 1.5
   c2 = 2.0
   cs = 0.1
   k1 = 0.0
   k2 = 1.0
   ks = 0.1

   if(make == 1):
      
      c_arr = pow(10, arange(c1, c2, cs))
      cl = len(c_arr)
      k_arr = pow(10, arange(k1, k2, ks))
      kl = len(k_arr)
      diff = zeros((cl, kl))
      mnki = 0
      mnci = 0
      
      for ci in range(cl):
         for ki in range(kl):
            print(c_arr[ci], k_arr[ki])
            pvar, pmean, ivar, imean = new_gpairs_match2(u_mi, u_mp, c_arr[ci], u_cp, 0.2, 0.7, l, imgNr, k_arr[k_i], n_i, ut_i, k_p, n_p, ut_p)[2:6]
            print(pvar, pmean, ivar, imean)
            vardiff = abs(pvar-ivar)/max(pvar,ivar)
            meandiff = abs(pmean-imean)/max(pmean, imean)
            print(vardiff, meandiff)
            diff[ci][ki]  = max(vardiff, meandiff) #0.5*vardiff + 0.5*meandiff
            if (diff[ci][ki] < diff[mnci][mnki]):
               mnci=ci
               mnki=ki
      print(c_arr[mnci], k_arr[mnki], diff[mnci][mnki])
      save("txt/match_p_3.npy", diff)
   else:
      diff = load("txt/match_p_3.npy")
   tl = ""
   fn = "images/match_p_3.png"
   plt.clf()
   plt.imshow((diff.T)[::-1, :], interpolation="none", extent=[10**c1-10**(cs/2.0), 10**c2+10**(cs/2.0), 10**k1-10**(ks/2.0), 10**k2+10**(ks/2.0)], aspect = "auto")
   plt.colorbar()
   myplot(r"$c_i$", r"$k_i$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
Beispiel #9
0
def do_it_match_plotter_input(make=1):

   k_p = 4.2
   n_p = 1.1
   ut_p = 1.92
   
   k_i = 10.0
   n_i = 1.1
   ut_i = 1.9

   u_mi = 2.0
   u_mp = 1.7
   u_ci = 1.0
   u_cp = 1.8

   mp1 = 1.5
   mp2 = 2.0
   mps = 0.1
   cp1 = 1.4
   cp2 = 2.0
   cps = 0.1
      
   imgNr = 1500 # 3000
   l = 50 # 500
   if(make == 1):
      
      umps = arange(mp1, mp2, mps)
      umpl = len(umps)
      ucps = arange(cp1, cp2, cps)
      ucpl = len(ucps)
      diff = zeros((umpl, ucpl))
      mnumpi = 0
      mnucpi = 0
      
      for umpi in range(umpl):
         for ucpi in range(ucpl):
            print(umps[umpi], ucps[ucpi])
            pvar, pmean, ivar, imean = new_gpairs_match2(u_mi, umps[umpi], u_ci, ucps[ucpi], 0.2, 0.7, l, imgNr, k_i, n_i, ut_i, k_p, n_p, ut_p)[2:6]
            print(pvar, pmean, ivar, imean)
            vardiff = abs(pvar-ivar)/max(pvar,ivar)
            meandiff = abs(pmean-imean)/max(pmean, imean)
            print(vardiff, meandiff)
            diff[umpi][ucpi]  = max(vardiff, meandiff) #0.5*vardiff + 0.5*meandiff
            if (diff[umpi][ucpi] < diff[mnumpi][mnucpi]):
               mnumpi=umpi
               mnucpi=ucpi
      print(umps[mnumpi], ucps[mnucpi], diff[mnumpi][mnucpi])
      save("txt/match_p.npy", diff)
   else:
      diff = load("txt/match_p.npy")
   tl = ""
   fn = "images/match_p.png"
   plt.clf()
   plt.imshow((diff.T)[::-1, :], interpolation="none", extent=[mp1-mps/2.0, mp2+mps/2.0, cp1-cps/2.0, cp2+cps/2.0], aspect = "auto")
   plt.colorbar()
   myplot(r"$u_{mp}$", r"$u_{cp}$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
Beispiel #10
0
def do_it_1b(make=1, u_mean = 2):
   imgNr = 3000
   l = 50 # 500
   n = imgNr
   ni = l*100
   if(make == 1):
      pspike_arr = zeros((n,2))
      ispike_arr = zeros((n,2))
      pspike_arri = zeros((n,2))
      ispike_arri = zeros((n,2))

      
      pspike_arr, ispike_arr = new_gpairs(u_mean, 0.3, l, imgNr)[6:8]
      pspike_arri, ispike_arri = new_gpairs_small(u_mean, 0.3, ni)[6:8]
         
      save("txt/spikecov%.2f.npy"%u_mean, [pspike_arr, ispike_arr, pspike_arri, ispike_arri])
   else:
      pspike_arr, ispike_arr, pspike_arri, ispike_arri = load("txt/spikecov%.2f.npy"%u_mean)
   
# trial to trial
   tl = "" #"Spike count - Poisson"
   fn = "images/tr2trspkp%.2f.png"%u_mean
   plt.clf()
   plt.plot(pspike_arr[:,0], pspike_arr[:,1], "b.", ms = 10)
   [a,b] = polyfit(pspike_arr[:,0], pspike_arr[:,1], 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="black")
   pspike_arrC = cov(pspike_arr, rowvar=False)
   plt.annotate("r = %0.2f"%(pspike_arrC[0,1]/pspike_arrC[0,0]), xy=(0.05, 0.9), xycoords='axes fraction', fontsize=30)
   pspike_arrm = pspike_arr.mean(axis=0)
   plot_cov_ellipse(pspike_arrC, pspike_arrm, nstd=1.5, color='green', lw=4, zorder=4)
   if(u_mean == 1.95):
      plt.ylim([1,16])
      plt.xlim([1,16])
   else:
      plt.ylim([10,45])
      plt.xlim([10,45])
   myplot(r"$n_1$", r"$n_2$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50)
   
   tl = "" #"Spike count - Integration"
   fn = "images/tr2trspki%.2f.png"%u_mean
   plt.clf()
   plt.plot(ispike_arr[:,0], ispike_arr[:,1], "b.", ms = 10)
   [a,b] = polyfit(ispike_arr[:,0], ispike_arr[:,1], 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="black")
   ispike_arrC = cov(ispike_arr, rowvar=False)
   plt.annotate("r = %0.2f"%(ispike_arrC[0,1]/ispike_arrC[0,0]), xy=(0.05, 0.9), xycoords='axes fraction', fontsize=30)
   ispike_arrm = ispike_arr.mean(axis=0)
   plot_cov_ellipse(ispike_arrC, ispike_arrm, nstd=1.5, color='green', lw=4, zorder=4)
   if(u_mean == 1.95):
      plt.ylim([1,16])
      plt.xlim([1,16])
   else:
      plt.ylim([10,45])
      plt.xlim([10,45])
   myplot(r"$n_1$", r"$n_2$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50)
Beispiel #11
0
def correlation_maximum_line(make = 1): 
   # surface for spike count mean and variance -- spkc corr. derivative
   l = 50
   imgNr = 30000 #30000
   k = 10
   ne = 1.4
   ut = 0
   corr_i = 0.15
   corr_p = 0.85

   ui_arr = arange(-1.5, 8, 2)
   ui_cov = arange(1, 5, 1)
   up_arr = arange(-1.5, 8, 2)
   up_cov = arange(1, 5, 1)
   n = len(ui_arr)
   m = len(ui_cov)
   
   if(make==1):
      pcoeff_arr = zeros((n,m))
      icoeff_arr = zeros((n,m))
      pvar_arr = zeros((n,m))
      pmean_arr = zeros((n,m))
      ivar_arr = zeros((n,m))
      imean_arr = zeros((n,m))
      for i in range(0,n):
         for j in range (0,m):
            print (i, j)
            pcoeff_arr[i,j], icoeff_arr[i,j], pvar_arr[i,j], pmean_arr[i,j], ivar_arr[i,j], imean_arr[i,j] = new_gpairs_match2(ui_arr[i], up_arr[i], ui_cov[j], up_cov[j], corr_i, corr_p, l, imgNr, k, ne, ut, k, ne, ut)[0:6]
            print(pcoeff_arr[i,j], icoeff_arr[i,j])
      save("txt/corrderiv4.npy", [pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr])
   else:
      pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr = load("txt/corrderiv4.npy")
      # other one was made with 3 -- 
   
#   return


   mn = up_arr[argmax((100*pcoeff_arr).astype(int), 0)]
   mn2 = up_arr[n-1-argmax((100*pcoeff_arr[::-1]).astype(int), 0)]
   cv = up_cov
   fn = "images/corrderiv_max.png"
   tl = ""
   plt.clf()
   plt.plot(mn, cv, "w--", lw=5)
   plt.plot(mn2, cv, "w--", lw=5)
   plt.xlim([-1.5, 6])
   extra = plt.text(5.8, 4.1, r"Mean$_{SC}$ (k)", fontsize=20)
   plt.contourf(up_arr,up_cov,pmean_arr.T/10,250,cmap=plt.cm.jet)
   plt.clim(0, 10)
   plt.colorbar()
   myplot(r"Mean$_{mb}$ (mV)", r"Var$_{mb}$ (mV$^2$)", tl, fn, fs=15, fsl=15, xlog=False, extra=(extra,), legend=False, fsax=20, xloc=False)
Beispiel #12
0
def pairs_spikec(spike_arr, fn, tl, b1, b2, l):
   bs1 = spike_arr[:,b1].astype(float)
   bs2 = spike_arr[:,b2].astype(float)
#   sl = len(bs1)
#   vals1, bins1 = bin_means(range(0,sl), bs1, l)
#   vals2, bins2 = bin_means(range(0,sl), bs2, l)
#   vals1 = vals1*sl/l
#   vals2 = vals2*sl/l
#   plt.clf()
#   plt.plot(vals1, vals2, "o")

   print(sum(bs1), sum(bs2))
   sl = len(bs1)
   delta = 0.23
   vals1, bins1 = bin_means(range(0,sl), bs1, l)
   vals2, bins2 = bin_means(range(0,sl), bs2, l)
   vals1 = vals1*sl/l
   vals2 = vals2*sl/l
   xedges = arange(min(vals1), min(vals1) + int((max(vals1)-min(vals1))/delta)*delta + 2* delta, delta)-delta/2
   yedges = arange(min(vals2), min(vals2)+ int((max(vals2)-min(vals2))/delta)*delta + 2 * delta, delta)-delta/2
   h, xedges, yedges = histogram2d(vals1, vals2, bins = [xedges, yedges])
   xmids = arange(min(vals1), min(vals1) + int((max(vals1)-min(vals1))/delta)*delta + delta, delta)
   ymids = arange(min(vals2), min(vals2) + int((max(vals2)-min(vals2))/delta)*delta + delta, delta)
   X, Y = meshgrid(xmids, ymids)
   plt.clf()
   plt.scatter(X, Y, s = h*20)
#   plt.xlim([0, 24])
#   plt.ylim([0, 28])
   print(corrcoef(vals1, vals2))

#   print(sum(bs1), sum(bs2))
#   sl = len(bs1)
#   vals1, bins1 = bin_means(range(0,sl), bs1, l)
#   vals2, bins2 = bin_means(range(0,sl), bs2, l)
#   vals1 = (vals1*sl/l).astype(int)
#   vals2 = (vals2*sl/l).astype(int)
#   xedges = arange(int(min(vals1)), int(max(vals1))+2)-0.5
#   yedges = arange(int(min(vals2)), int(max(vals2))+2)-0.5
#   h, xedges, yedges = histogram2d(vals1, vals2, bins = [xedges, yedges])
#   xmids = arange(int(min(vals1)), int(max(vals1))+1)
#   ymids = arange(int(min(vals2)), int(max(vals2))+1)
#   X, Y = meshgrid(xmids, ymids)
#   plt.clf()
#   plt.scatter(X, Y, s = h*20)
#   plt.xlim([0, 21])
#   plt.ylim([0, 21])
#   plt.xlim([int(min(vals1))-0.1, int(max(vals1))+0.1])
#   plt.ylim([int(min(vals2))-0.1, int(max(vals2))+0.1])
   myplot("spike count of neuron 1", "spike count of neuron 2", tl, fn, xlog=False, legend=False)
Beispiel #13
0
def do_it_2(make = 1): 

   if(make == 1):
      new_g_pairs(make)
   a3 = load("txt/t2t_potcorr3.npy")
   a6 = load("txt/t2t_potcorr6.npy")
   a9 = load("txt/t2t_potcorr9.npy")
   
   tl = ""#"Trial-to-trial correlations"
   fn = "images/tr2trpairs.png"
   lw = 7
   plt.plot(a3[0], a3[1], label = "Poisson, c=0.3", color="blue", linestyle="--", lw=lw);
   plt.plot(a3[0], a3[2], label = "Integration, c=0.3", color="blue", linestyle="-", lw=lw);
   plt.plot(a6[0], a6[1], label = "Poisson, c=0.6", color="red", linestyle="--", lw=lw);
   plt.plot(a6[0], a6[2], label = "Integration, c=0.6", color="red", linestyle="-", lw=lw);
   plt.plot(a9[0], a9[1], label = "Poisson, c=0.9", color="green", linestyle="--", lw=lw);
   plt.plot(a9[0], a9[2], label = "Integration, c=0.9", color="green", linestyle="-", lw=lw);
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$Mean(u)$", r"$\rho_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
Beispiel #14
0
def spk_contr_mean(spk, contr, fn, tl, make=1):
   if(make == 1):
      mn  = mean(mean(spk, axis = 1)*1000,axis=1)
      savetxt("txt/spk_contr_mean_mn.txt", mn)
      savetxt("txt/spk_contr_mean_contr.txt", contr)
   else:
      mn = loadtxt("txt/spk_contr_mean_mn.txt")
      contr = loadtxt("txt/spk_contr_mean_contr.txt")
   bnr = 100
   l = 10
   vals, bins = bin_means(contr, mn, bnr)
   run_avg = running_mean(vals, l)
   print (run_avg)
   d = len(run_avg)
   print (d)
   plt.clf()
   plt.plot(contr, mn, 'go', alpha=.4)
   plt.plot(bins[l/2:d+l/2], run_avg, lw = 8, color = "red")
   myplot("inferred contrast", "mean spiking rate", tl, fn, xlog=False, legend=False)
Beispiel #15
0
def fig1b(make):
   imgNr = 1500 # 3000
   l = 50 # 500
   
   # input ranges
   u1 = 1.0
   u2 = 10.0
   ud = 1.0
   c = 1.0
   
   us = arange(u1, u2, ud)
   ul = len(us)
   
   pmeans = zeros(ul)
   imeans = zeros(ul)
   
   if(make == 1):
   
   # nonlinearity parameters
      k = 10.0
      n = 1.1
      ut = 1.9
      
      for ui in range(ul):
         print(ui)
         pmeans[ui], haha, imeans[ui] = new_gpairs_match2(us[ui], us[ui], c, c, 0.2, 0.7, l, imgNr, k, n, ut, k, n, ut)[3:6]
      save("txt/fig1b.npy", [pmeans, imeans])
   else:
      pmeans, imeans = load("txt/fig1b.npy")
      
      
   tl = r"$Mean_{SC}$"
   fn = "images/fig1b.png"
   plt.clf()
   plt.plot(us, pmeans, "b.", label = "Poisson", ms = 10)
#   [a,b] = polyfit(pmean_arr, pfano_arr, 1)
#   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="blue")
   plt.plot(us, imeans, "r.", label = "Integration", ms = 10)
#   [a,b] = polyfit(imean_arr, ifano_arr, 1)
#   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="red")
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$Mean_{u} (mV)$", r"$Mean_{SC} (sp/s)$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
Beispiel #16
0
def spk_contr_corr(spk, contr, fn, tl, make = 1, mn=0):

   if(make==1):
   
      imgNr = size(spk,0)
      avg_cv = zeros(imgNr)
      
      if(mn == 1):
         spk_avg = mean(mean(spk, axis=1), axis=1)
         contr = spk_avg * 1000


      for i in range(0,imgNr):
         cv = cov(spk[i], rowvar=0)
         corr = nan_to_num(correlate_cov(cv))
         a = abs(corr-diag(diag(corr)))
         avg_cv[i] = mean(a)
      
      savetxt("txt/spk_contr_corr_avg_cv.txt", avg_cv)
      savetxt("txt/spk_contr_corr_contr_cv.txt", contr)
   
   else:
      avg_cv = loadtxt("txt/spk_contr_corr_avg_cv.txt")
      contr = loadtxt("txt/spk_contr_corr_contr_cv.txt")

   bnr = 100
   l = 10
   vals, bins = bin_means(contr, avg_cv, bnr)
   run_avg = running_mean(vals, l)
   d = len(run_avg)
   plt.clf()
   plt.plot(contr, avg_cv, 'go', alpha=.4)
   plt.plot(bins[l/2:d+l/2], run_avg, lw = 8, color = "red")
#   plt.ylim([0,0.035])
   if(mn == 1):
      myplot("mean spiking rate", "average correlations", tl, fn, xlog=False, legend=False)   
   else:
      myplot("inferred contrast", "average correlations", tl, fn, xlog=False, legend=False)
    features = np.random.random((n_features, n_data))

    for i in range(10000):

        weights = weights - d_weights * 0.001 * 0.1**(0.25 * np.log10(i + 1.0))

        #print(weights)

        #myplot(1, np.linspace(1,n_neurons,n_neurons), neurons, '-g', 2.0, None)
        beta = MyNN.nn.predict(act_fn, np.asfortranarray(n_neurons_layer),
                               np.asfortranarray(weights),
                               np.asfortranarray(neurons),
                               np.asfortranarray(features))

        if i == 0:
            myplot("ML_init", np.linspace(1, n_data, n_data), beta, '-b', 2.0,
                   None)

        print("ML Iteration: %6d\t\tLoss: %E" % (i, eval_loss(beta)))

        #print("predicted")

        d_beta = 2.0 * (beta - 1.0)
        d_weights = MyNN.nn.get_sens(act_fn,
                                     np.asfortranarray(n_neurons_layer),
                                     np.asfortranarray(weights),
                                     np.asfortranarray(neurons),
                                     np.asfortranarray(features),
                                     np.asfortranarray(d_beta))

        d_weights = d_weights / np.max(np.abs(d_weights))
Beispiel #18
0
def correlation_derivative(make = 1): 
   # surface for spike count mean and variance -- spkc corr. derivative
   l = 50
   imgNr = 30000 #30000
   k = 10
   ne = 1.4
   ut = 0
   corr_i = 0.15
   corr_p = 0.85

# not exactly these params, but almost
   ui_arr = arange(-1.5, 8, 0.8)
   ui_cov = arange(1, 5, 0.7)
   up_arr = arange(-1.5, 8, 0.8)
   up_cov = arange(1, 5, 0.7)
   
   if(make==1):
      n = len(ui_arr)
      m = len(ui_cov)
      pcoeff_arr = zeros((n,m))
      icoeff_arr = zeros((n,m))
      pvar_arr = zeros((n,m))
      pmean_arr = zeros((n,m))
      ivar_arr = zeros((n,m))
      imean_arr = zeros((n,m))
      for i in range(0,n):
         for j in range (0,m):
            print (i, j)
            pcoeff_arr[i,j], icoeff_arr[i,j], pvar_arr[i,j], pmean_arr[i,j], ivar_arr[i,j], imean_arr[i,j] = new_gpairs_match2(ui_arr[i], up_arr[i], ui_cov[j], up_cov[j], corr_i, corr_p, l, imgNr, k, ne, ut, k, ne, ut)[0:6]
            print(pcoeff_arr[i,j], icoeff_arr[i,j])
      save("txt/corrderiv2.npy", [pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr])
   else:
      pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr = load("txt/corrderiv2.npy")


   pcoeff_arr = pcoeff_arr.flatten()
   pmean_arr = pmean_arr.flatten()
   pvar_arr = pvar_arr.flatten()
   m1 = 10
   m2 = 25
   v1 = 10
   v2 = 50

   from scipy.interpolate import griddata
   from scipy.signal import convolve2d
   meani = arange(m1,m2,1)
   vari = arange(v1,v2,1)
   coeffi = griddata((pmean_arr, pvar_arr), pcoeff_arr, (meani[None,:], vari[:,None]), method='linear') 
   
   #coeffi = convolve2d(coeffi, ones((3,3)), "same");
   
   print(coeffi)
   # make the derivative calculation here
   coeffim = diff(coeffi,1,1)
   meani = arange(m1+0.5, m2-0.5,1)
   #vari = arange(v1+0.5, v2-0.5,1)
#   print (coeffi.shape)
   tl = ""
   fn = "images/corrderiv_pmf.png"
   plt.clf()
   #plt.contour(meani,vari,coeffim,15,linewidths=0.5,colors='k')
   M, V = meshgrid(meani,vari)
   M = M.flatten()
   V = V.flatten()
   coeffim=coeffim.flatten()
   
   F = V/M
   fanos = arange(0.9,2.7, 0.1)
   coeffis = griddata((M, F), coeffim, (meani[None,:], fanos[:,None]), method='linear') 
   
   #plt.contourf(meani,vari,coeffim,150,cmap=plt.cm.jet)
   plt.contourf(meani/10,fanos,coeffis,150,cmap=plt.cm.jet)
   #plt.imshow(coeffim,cmap=plt.cm.jet, interpolation = "bilinear")
   plt.clim(-0.1, 0.1)
   plt.colorbar()
   extra = plt.text(2.6, 2.25, r"$\frac{d\rho_{SC}}{dMean_{SC}}$ (1/k)", fontsize=20)
   #plt.scatter(pmean_arr,pvar_arr,marker='o',c='b',s=5)
   plt.xlim([m1/10,m2/10])
   plt.ylim([1.2,2.2])
   myplot(r"Mean$_{SC}$ (k)", r"Fano$_{SC}$ (k/Hz)", tl, fn, xlog=False, extra = (extra,), legend=False, fsax=20)
Beispiel #19
0
def do_it_match_plotter(make=1, u_mean = 2):
   imgNr = 1500 # 3000
   l = 50 # 500
   n = imgNr
   if(make == 1):
      pspike_arr = zeros((n,2))
      ispike_arr = zeros((n,2))
      
      k_p = 4.2
      n_p = 1.1
      ut_p = 1.92
      
      k_i = 10.0
      n_i = 1.1
      ut_i = 1.9

      u_mi = 2.0
      u_mp = 1.7
      u_ci = 1.0
      u_cp = 1.8
         
      u1 = 1.8
      u2 = 2.1
      us = 0.04
      k1 = 4.1
      k2 = 4.5
      ks = 0.1
      
      # for the same input mean and variance
      # 5, 1.05, 1.4, 11, 2.0, 1.7 -- 0.27%
      # 6, 1.1, 1.6, 11, 1.9, 1.7 -- 0.36%
      # 3.5, 1.05, 0.7, 11, 2.1, 1.9 -- 0.2%, 0.13%
      # 8.5, 1.05, 1.8, 11, 2.1, 1.9 -- 0.22%
      
      utps = arange(u1, u2, us)
      utpl = len(utps)
      kps = arange(k1, k2, ks)
      kpl = len(kps)
      diff = zeros((kpl, utpl))
      mnkpi = 0
      mnutpi = 0
      
      for utpi in range(utpl):
         for kpi in range(kpl):
            print(kps[kpi], utps[utpi])
            pvar, pmean, ivar, imean = new_gpairs_match2(u_mi, u_mp, u_ci, u_cp, 0.2, 0.7, l, imgNr, k_i, n_i, ut_i, kps[kpi], n_p, utps[utpi])[2:6]
            print(pvar, pmean, ivar, imean)
            vardiff = abs(pvar-ivar)/max(pvar,ivar)
            meandiff = abs(pmean-imean)/max(pmean, imean)
            print(vardiff, meandiff)
            diff[kpi][utpi]  = max(vardiff, meandiff) #0.5*vardiff + 0.5*meandiff
            if (diff[kpi][utpi] < diff[mnkpi][mnutpi]):
               mnkpi=kpi
               mnutpi=utpi
      print(kps[mnkpi], utps[mnutpi], diff[mnkpi][mnutpi])
      save("txt/match_p_sameinp.npy", diff)
   else:
      diff = load("txt/match_p_sameinp.npy")
   tl = ""
   fn = "images/match_p_sameinp.png"
   plt.clf()
   plt.imshow((diff.T)[::-1, :], interpolation="none", extent=[k1-ks/2.0, k2+ks/2.0, u1-us/2.0, u2+us/2.0], aspect = "auto")
   plt.colorbar()
   myplot(r"$kp$", r"$utp$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
Beispiel #20
0
def do_it_0(make=1):
# fano-factors
# trial to trial
   imgNr = 3000
   l = 500
   if(make == 1):
      u_means = arange(0,10,0.5)
      n = size(u_means)
      pvar = zeros((n,1))
      pmean = zeros((n,1))
      ivar = zeros((n,1))
      imean = zeros((n,1))
      pvari = zeros((n,1))
      pmeani = zeros((n,1))
      ivari = zeros((n,1))
      imeani = zeros((n,1))
      
      for i in range(0,n):
         pvar[i], pmean[i], ivar[i], imean[i] = new_gpairs(u_means[i], 0.3, l, imgNr)[2:6]
         pvari[i], pmeani[i], ivari[i], imeani[i] = new_gpairs_small(u_means[i], 0.3, l*100)[2:6]
         
      save("txt/tr2trfano.npy", [pvar, pmean, ivar, imean, pvari, pmeani, ivari, imeani])
   else:
      pvar, pmean, ivar, imean, pvari, pmeani, ivari, imeani = load("txt/tr2trfano.npy")

# rescaling to one second bins (fano factors stay, means rescaled)     
   t = l*0.02
   ti = 0.02
   pvar/=t
   pmean/=t
   ivar/=t
   imean/=t
   pvari/=ti
   pmeani/=ti
   ivari/=ti
   imeani/=ti
   
# trial to trial
   tl = "" #"Trial to trial Fano-factor"
   fn = "images/tr2trfanop.png"
   plt.ylim([0,1.3])
   plt.xlim([10,100])
   plt.plot(pmean, pvar/pmean, label="Poisson", linestyle="--", lw=10)
   plt.plot(imean, ivar/imean, label="Integration", linestyle="-", lw=10)
#   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 15)
   plt.xticks([20,60, 100])
   myplot(r"$Mean(n)$", r"$Fano(n)$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50, xloc=False) #extra=(extra,), 

# instantaneous   
   plt.clf()
   plt.ylim([0,1.5])
   plt.xlim([10,100])
   tl = "" #"Instantaneous Fano-factor"
   fn = "images/instafanop.png"
   plt.plot(pmeani, pvari/pmeani, label="Poisson", linestyle="--", lw=10)
   plt.plot(imeani, ivari/imeani, label="Integration", linestyle="-", lw=10)
  # extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 15)
   plt.xticks([20,60, 100])
   myplot(r"$Mean(n)$", r"$Fano(n)$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50, xloc=False) #extra=(extra,), 
   
   plt.clf()
   plt.ylim([0,30])
   plt.xlim([0,20])
   tl = "" #"Instantaneous Fano-factor"
   fn = "images/instavarp.png"
   plt.plot(pmeani, pvari, label="Poisson", linestyle="--", lw=10)
   plt.plot(imeani, ivari, label="Integration", linestyle="-", lw=10)
  # extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 15)
   plt.xticks([5, 15])
   myplot(r"$Mean(n)$", r"$Var(n)$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50, xloc=False) #extra=(extra,), 
Beispiel #21
0
def match_to_fixed(make=1):
   imgNr = 1000 # 3000
   l = 50 # 500
   # input ranges
   u1 = 0.8
   u2 = 1.2
   ud = 0.05
   c1 = 2
   c2 = 2.5
   cd = 0.1
   
   aimed_mean = 30
   aimed_var = 31
   
#   m_p = 1.2
#   v_p = 0.2
#   m_i = 0.9
#   v_i = 2.3
   corr_i = 0.15
   corr_p = 0.85

# Gergo case
#poisson 1.28, 0.31
#integration 

# the case of 8, 8.5
# for poisson 
#2.3 0.1
#8.13959375 7.7525
# for integration
#0.15 8.0
#6.78831875 9.1075
# 21%

# the case of 10, 10.5
# for poisson 
#2.35 0.3
#10.62259375 9.9825
# for integration
#0.1 10.5
#9.41051875 12.0125
# 20%


# the case of 30, 31.5
# for poisson 
#3.3 0.8
#31.9687644444 30.136
# for integration
#1.0 19.6
#31.1467831111 30.3
# saved with name_fit
# 2%




   
   us = arange(u1, u2, ud)
   ul = len(us)
   cs = arange(c1, c2, cd)
   cl = len(cs)
   pvars = zeros((ul, cl))
   pmeans = zeros((ul, cl))
   ivars = zeros((ul, cl))
   imeans = zeros((ul, cl))
   
   if(make == 1):
   
   # nonlinearity parameters
#      k = 10.0
#      n = 1.1
#      ut = 1.9
      
      k = 10
      n = 1.4
      ut = 0
      
      for ui in range(ul):
         for ci in range(cl):
            print(ui, ci)
            pvars[ui][ci], pmeans[ui][ci], ivars[ui][ci], imeans[ui][ci] = new_gpairs_match2(us[ui], us[ui], cs[ci], cs[ci], corr_i, corr_p, l, imgNr, k, n, ut, k, n, ut)[2:6]
      save("txt/match_p_sameinp.npy", [pvars, pmeans, ivars, imeans])
   else:
      pvars, pmeans, ivars, imeans = load("txt/match_p_sameinp.npy")
      
   a = argmin(abs(pvars - aimed_var)+abs(pmeans - aimed_mean))
   i = int(a/cl)
   j = a%cl
   print ("poisson")
   print (i,j)
   print (us[i], cs[j])
   print (pvars[i][j], pmeans[i][j])
   
   a = argmin(abs(ivars - aimed_var)+abs(imeans - aimed_mean))
   i = int(a/cl)
   j = a%cl
   print ("integration")
   print (i,j)
   print (us[i], cs[j])
   print (ivars[i][j], imeans[i][j])


   print ((pmeans.T)[::-1, :])
   tl = ""
   fn = "images/match_m_p.png"
   plt.clf()
   plt.imshow((pmeans.T)[::-1, :], interpolation="none", extent=[u1-ud/2.0, u2+ud/2.0, c1-cd/2.0, c2+cd/2.0], aspect = "auto")
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
   
   tl = ""
   fn = "images/match_v_p.png"
   plt.clf()
   plt.imshow((pvars.T)[::-1, :], interpolation="none", extent=[u1-ud/2.0, u2+ud/2.0, c1-cd/2.0, c2+cd/2.0], aspect = "auto")
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
   
   tl = ""
   fn = "images/match_m_i.png"
   plt.clf()
   plt.imshow((imeans.T)[::-1, :], interpolation="none", extent=[u1-ud/2.0, u2+ud/2.0, c1-cd/2.0, c2+cd/2.0], aspect = "auto")
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
   
   tl = ""
   fn = "images/match_v_i.png"
   plt.clf()
   plt.imshow((ivars.T)[::-1, :], interpolation="none", extent=[u1-ud/2.0, u2+ud/2.0, c1-cd/2.0, c2+cd/2.0], aspect = "auto")
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50, xloc=False)
Beispiel #22
0
def fig3b_o(make=1):
# orientation changes: variances stay, means increase then decresase. (in membrane potentials)

# the case of 30, 31.5
# for poisson 
#3.3 0.8
#31.9687644444 30.136
# for integration
#1.0 19.6
#31.1467831111 30.3
# saved with name_fit
# 2%

   times = 3

#   m_p = 3.3
#   v_p = 0.8
#   m_i = 1.0
#   v_i = 19.6

   m_p = 1.2
   v_p = 0.2
   m_i = 0.9
   v_i = 2.3

   if(make==1):
      l = 50
      imgNr = 30000 #30000
      k = 10
#      ne = 1.1
#      ut = 1.9
#      corr_i = 0.15
#      corr_p = 0.95

      ne = 1.4
      ut = 0
      corr_i = 0.15
      corr_p = 0.85
      
      i_fano = v_i/m_i;
      p_fano = v_p/m_p;
      
      ui_arr = arange(m_i/2, 1.05*m_i, m_i/10) #make just a part of it, then at plotting symmetry
      ui_cov = repeat([v_i],6)
      up_arr = arange(m_p/2, 1.05*m_p, m_p/10)
      up_cov = repeat([v_p],6)

      n = len(ui_arr)
      pcoeff_arr = zeros((n, times))
      icoeff_arr = zeros((n, times))
      pvar_arr = zeros((n, times))
      pmean_arr = zeros((n, times))
      ivar_arr = zeros((n, times))
      imean_arr = zeros((n, times))
      # o1 is for Gergo's params
      # o2 for mine
      for i in range(n):
         print (i)
         for j in range(times):
            pcoeff_arr[i][j], icoeff_arr[i][j], pvar_arr[i][j], pmean_arr[i][j], ivar_arr[i][j], imean_arr[i][j] = new_gpairs_match2(ui_arr[i], up_arr[i], ui_cov[i], up_cov[i], corr_i, corr_p, l, imgNr, k, ne, ut, k, ne, ut)[0:6]
      save("txt/fig3b_o1.npy", [pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr])
   else:
      pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr = load("txt/fig3b_o1.npy")
   print(icoeff_arr)
   print(pcoeff_arr)
   
   orient = [-150, -130, -105, -75, -40 ,0, 40, 75, 105, 130, 150]
   pmean_arr = concatenate([pmean_arr[:-1], pmean_arr[::-1]])
   imean_arr = concatenate([imean_arr[:-1], imean_arr[::-1]])
   pvar_arr = concatenate([pvar_arr[:-1], pvar_arr[::-1]])
   ivar_arr = concatenate([ivar_arr[:-1], ivar_arr[::-1]])
   pcoeff_arr = concatenate([pcoeff_arr[:-1], pcoeff_arr[::-1]])
   icoeff_arr = concatenate([icoeff_arr[:-1], icoeff_arr[::-1]])
   pfano_arr = divide(pvar_arr, pmean_arr)
   ifano_arr = divide(ivar_arr, imean_arr)
   
   
   tl = ""#r"$Mean_{SC}$"
   fn = "images/fig3b_o1_m.png"
   plt.clf()
   plt.plot(orient, pmean_arr[:,0], "r.", label = "Poisson", ms = 10)
   plt.plot(orient, imean_arr[:,0], "b.", label = "Integration", ms = 10)
   plt.plot(orient, pmean_arr[:,1:], "r.", ms = 10)
   plt.plot(orient, imean_arr[:,1:], "b.", ms = 10)
   plt.xticks([-160, -80, 0, 80, 160])
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$orientation (deg)$", r"$Mean_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
   
   tl = ""#r"$Fano_{SC}$"
   fn = "images/fig3b_o1_f.png"
   plt.clf()
   plt.plot(orient, pfano_arr[:,0], "r.", label = "Poisson", ms = 10)
   plt.plot(orient, ifano_arr[:,0], "b.", label = "Integration", ms = 10)
   plt.plot(orient, pfano_arr[:,1:], "r.", ms = 10)
   plt.plot(orient, ifano_arr[:,1:], "b.", ms = 10)
   plt.xticks([-160, -80, 0, 80, 160])
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$orientation (deg)$", r"$Fano_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
   
   
   tl = ""#r"$\rho_{SC}$"
   fn = "images/fig3b_o1_c.png"
   plt.clf()
   plt.plot(orient, pcoeff_arr[:,0], "r.", label = "Poisson", ms = 10)
   plt.plot(orient, icoeff_arr[:,0], "b.", label = "Integration", ms = 10)
   plt.plot(orient, pcoeff_arr[:,1:], "r.", ms = 10)
   plt.plot(orient, icoeff_arr[:,1:], "b.", ms = 10)
   plt.xticks([-160, -80, 0, 80, 160])
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$orientation (deg)$", r"$\rho_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
Beispiel #23
0
def new_pairs_spikec(contrasts, pcoeffs, icoeffs, fn, tl):

   plt.plot(contrasts, pcoeffs, label = "Poisson");
   plt.plot(contrasts, icoeffs, label = "Integration");
   myplot("potential means", "Trial to trial correlations", tl, fn, xlog=False, legend=True)
Beispiel #24
0
def do_it_matched_plot2(make=1):
   # what if we fit a plane through these points and plot that?

   # surface for spike count mean and variance -- spkc corr.
   if(make==1):
      l = 50
      imgNr = 30000 #30000
      k = 10
      ne = 1.1
      ut = 1.9
      corr_i = 0.15
      corr_p = 0.95
      #Mean(u_p) = 3.3, Var(u_p) = 0.8, Mean(u_i) = 1.0, Var(u_i) = 19.6
      ui_arr = arange(1, 2.5, 0.3)
      ui_cov = arange(17, 20, 0.3)
      up_arr = arange(3.3, 3.55, 0.05)
      up_cov = arange(0.3, 0.8, 0.05)
#      ui_arr = arange(1.0, 1.1, 0.3)
#      ui_cov = arange(19.6, 20, 4)
#      up_arr = arange(3.3, 3.5, 0.9)
#      up_cov = arange(0.8, 0.9, 0.2)
      n = len(ui_arr)
      m = len(ui_cov)
      pcoeff_arr = zeros((n,m))
      icoeff_arr = zeros((n,m))
      pvar_arr = zeros((n,m))
      pmean_arr = zeros((n,m))
      ivar_arr = zeros((n,m))
      imean_arr = zeros((n,m))
      for i in range(0,n):
         for j in range (0,m):
            print (i, j)
            pcoeff_arr[i,j], icoeff_arr[i,j], pvar_arr[i,j], pmean_arr[i,j], ivar_arr[i,j], imean_arr[i,j] = new_gpairs_match2(ui_arr[i], up_arr[i], ui_cov[j], up_cov[j], corr_i, corr_p, l, imgNr, k, ne, ut, k, ne, ut)[0:6]
            print(pcoeff_arr[i,j], icoeff_arr[i,j])
      save("txt/matched_scale2.npy", [pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr])
   else:
      pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr = load("txt/matched_scale2.npy")
#   print(imean_arr)
#   print(pmean_arr)
#   print(ivar_arr)
#   print(pvar_arr)
   print(icoeff_arr)
   print(pcoeff_arr)

   pcoeff_arr = pcoeff_arr.flatten()
   icoeff_arr = icoeff_arr.flatten()
   pmean_arr = pmean_arr.flatten()
   imean_arr = imean_arr.flatten()
   pvar_arr = pvar_arr.flatten()
   ivar_arr = ivar_arr.flatten()
   
#   m1 = max(amin(pmean_arr), amin(imean_arr))
#   m2 = min(amax(pmean_arr), amax(imean_arr))
#   v1 = max(amin(pvar_arr), amin(ivar_arr))
#   v2 = min(amax(pvar_arr), amax(ivar_arr))
#   print(m1,m2,v1,v2)
   m1 = 30
   m2 = 33
   v1 = 31
   v2 = 35
   
   from scipy.interpolate import griddata
   meani = arange(m1,m2,0.3)
   vari = arange(v1,v2,0.3)
   
   # poisson
#   print (shape(pmean_arr), shape(pvar_arr), shape(pcoeff_arr), shape(meani), shape(vari))
   coeffi = griddata((pmean_arr, pvar_arr), pcoeff_arr, (meani[None,:], vari[:,None]), method='linear') 
#   print (coeffi.shape)
   tl = r"Poisson: $\rho_{SC}$"
   fn = "images/matched_scale2p.png"
   plt.clf()
   plt.contour(meani,vari,coeffi,15,linewidths=0.5,colors='k')
   plt.contourf(meani,vari,coeffi,15,cmap=plt.cm.jet)
   plt.clim(0.03, 0.125)
   plt.colorbar()
   plt.scatter(pmean_arr,pvar_arr,marker='o',c='b',s=5)
   plt.xlim([m1,m2])
   plt.ylim([v1,v2])
   myplot(r"$Mean_{SC} (spk/s)$", r"$Var_{SC} (spk/s)^2$", tl, fn, xlog=False, legend=False, fsax=50)
   
   # integration
   coeffi = griddata((imean_arr, ivar_arr), icoeff_arr, (meani[None,:], vari[:,None]), method='linear') 
#   print (coeffi.shape)
   tl = r"Integration: $\rho_{SC}$"
   fn = "images/matched_scale2i.png"
   plt.clf()
   plt.contour(meani,vari,coeffi,15,linewidths=0.5,colors='k')
   plt.contourf(meani,vari,coeffi,15,cmap=plt.cm.jet)
   plt.clim(0.03, 0.125)
   plt.colorbar()
   plt.scatter(imean_arr,ivar_arr,marker='o',c='b',s=5)
   plt.xlim([m1,m2])
   plt.ylim([v1,v2])
   myplot(r"$Mean_{SC} (spk/s)$", r"$Var_{SC} (spk/s)^2$", tl, fn, xlog=False, legend=False, fsax=50)
Beispiel #25
0
def do_it_1(u_mean = 2): 
# ou-process potentials, rates and spike count correlations
   dt = 0.001
   tau = 0.02   # time constant of the ou process
   samples = 300
   corr = 0.3
#   u_mean = 6
   C = array([[1, corr],[corr,1]]) # covariance
   m = u_mean * array([1.0, 1.0])       # center
   
   k  = 10 # 10 Hz
   n  = 1.1 # the exponent of nonlinearity
   ut = 1.9 # the treshold potential

   samps = evolve_ou(m, C, tau, dt, samples-1) # samples - 1 steps are needed in the process
   rates = rate_from_pot(samps, k, ut, n)

   #plot the samples
   tl = "" #"Potentials with covariance ellipse"
   fn = "images/poster_samples%.2f.png"%u_mean
   plt.clf()
   plt.plot(samps[:,0], samps[:,1], "b.", ms = 10)
   plt.plot(samps[:,0], samps[:,1], lw = 1)
   plt.ylim([-1,9])
   plt.xlim([-1,9])
   yl = [min(plt.ylim()[0], 1.9), max(plt.ylim()[1], 1.9)]
   xl = [min(plt.xlim()[0], 1.9), max(plt.xlim()[1], 1.9)]
   plt.plot([1.9,1.9], yl, lw=2, color="red") # the treshold potential lines
   plt.plot(xl, [1.9,1.9], lw=2, color="red")
   [a,b] = polyfit(samps[:,0], samps[:,1], 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="black")
   sampsC = cov(samps, rowvar=False)
#   plt.text(left, top, "r = %0.2f"%(sampsC[0,1]/sampsC[0,0]))
   plt.annotate("r = %0.2f"%(sampsC[0,1]/sampsC[0,0]), xy=(0.05, 0.9), xycoords='axes fraction', fontsize=30)
   sampsm = samps.mean(axis=0)
   plot_cov_ellipse(sampsC, sampsm, nstd=1.5, color='green', lw=4)
   myplot(r"$u_1$", r"$u_2$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50)
   
   
   #plot time series
   tl = "" #"Potentials with covariance ellipse"
   fn = "images/poster_samplest%.2f.png"%u_mean
   plt.clf()
   plt.plot(samps[:,0], lw=5)
   plt.plot(samps[:,1], lw=5) #arange(0, samples*dt*1000, dt*1000), 
#   plt.axes().set_aspect((10,20))
   myplot(r"$t(ms)$", r"$u_2$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, xloc=False, fsax=50)
   
   #plot the rates
   plt.clf()
   tl = "" #"Spiking rates"
   fn = "images/poster_rates%.2f.png"%u_mean
   plt.plot(rates[:,0], rates[:,1], "b.", ms = 10)
   plt.plot(rates[:,0], rates[:,1], lw = 1)
   plt.ylim([0,80])
   plt.xlim([0,80])
   [a,b] = polyfit(rates[:,0], rates[:,1], 1)
   plt.plot(plt.xlim(), a*array(plt.xlim())+b, lw=5, color="black")
#   plt.ylim(0, plt.ylim()[1])
#   plt.xlim(0, plt.xlim()[1])
   ratesC = cov(rates, rowvar=False)
   plt.annotate("r = %0.2f"%(ratesC[0,1]/ratesC[0,0]), xy=(0.05, 0.9), xycoords='axes fraction', fontsize=30)
   ratesm = rates.mean(axis=0)
   plot_cov_ellipse(ratesC, ratesm, nstd=1.5, color='green', lw=4)
   myplot(r"$R_1$", r"$R_2$", tl, fn, xlog=False, legend=False, fs=30, fsl=30, fsax=50)
Beispiel #26
0
def do_it_4(make=1):
# heatmaps
   if(make==1):
      corr = 0.3
      start = 0.3
      stop = 10
      step = 0.5
      potmeans = arange(start, stop, step)
      nrm = size(potmeans)
      start = 1
      stop = 11
      step = 1
      covs = arange(start, stop, step)
      nrc = size(covs)
      icoeffs = zeros((nrm, nrc))
      pcoeffs = zeros((nrm, nrc))
      ifanos = zeros((nrm, nrc))
      pfanos = zeros((nrm, nrc))
      icoeffsi = zeros((nrm, nrc))
      pcoeffsi = zeros((nrm, nrc))
      ifanosi = zeros((nrm, nrc))
      pfanosi = zeros((nrm, nrc))
      l  = 500 # number of samples for each patch (trial) # 1000
      imgNr = 5000 # 10000
      
      for i in range(0, nrm):  
         for j in range(0,nrc):
            pcoeffs[i,j], icoeffs[i,j], pv, pm, iv, im = new_gpairs(potmeans[i], corr, l, imgNr, cov=covs[j])[0:6]  
            pfanos[i,j], ifanos[i,j] = pv/pm, iv/im 
            pcoeffsi[i,j], icoeffsi[i,j], pv, pm, iv, im = new_gpairs_small(potmeans[i], corr, l*100, cov=covs[j])[0:6]  
            pfanosi[i,j], ifanosi[i,j] = pv/pm, iv/im 
      a = [potmeans, covs, pcoeffs, icoeffs, pfanos, ifanos, pcoeffsi, icoeffsi, pfanosi, ifanosi]
      save("txt/heatmaps.npy", a)
   else:
      potmeans, covs, pcoeffs, icoeffs, pfanos, ifanos, pcoeffsi, icoeffsi, pfanosi, ifanosi = load("txt/heatmaps.npy")
      
      
      
   step = potmeans[1] - potmeans[0]
   p1, p2 = potmeans[0]-step/2.0, potmeans[-1]+step/2.0
   step = covs[1] - covs[0]
   c1, c2 = covs[0]-step/2.0, covs[-1]+step/2.0
   
# trial to trial      
   tl = "" #"Trial-to-trial correlations - Poisson"
   fn = "images/heattr2trp.png"
   plt.imshow(pcoeffs.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
#   plt.clim(0,0.35)
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50)
      
   tl = "" #"Trial-to-trial correlations - Integration"
   fn = "images/heattr2tri.png"
   plt.clf()
   plt.imshow(icoeffs.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
#   plt.clim(0,0.35)
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50)
   
#   tl = "" #"Trial-to-trial Fano-factors - Poisson"
#   fn = "images/heattr2trpf.png"
#   plt.clf()
#   plt.imshow(pfanos.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
#   plt.clim(0,1.5)
#   plt.colorbar()
#   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50)
#      
#   tl = "" #"Trial-to-trial Fano-factors - Integration"
#   fn = "images/heattr2trif.png"
#   plt.clf()
#   plt.imshow(ifanos.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
#   plt.clim(0,1.5)
#   plt.colorbar()
#   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50)
   
## instantaneous
#   tl = "Instantaneous correlations - Poisson"
#   fn = "images/heatinstap.png"
#   plt.clf()
#   plt.imshow(pcoeffsi.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
#   plt.clim(0,0.35)
#   plt.colorbar()
#   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False)
#      
#   tl = "Instantaneous correlations - Integration"
#   fn = "images/heatinstai.png"
#   plt.clf()
#   plt.imshow(icoeffsi.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
#   plt.clim(0,0.35)
#   plt.colorbar()
#   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False)
#
   tl = ""
   fn = "images/heatinstapf.png"
   plt.clf()
   plt.imshow(pfanosi.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
   plt.clim(0,2)
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50)
      
   tl = ""
   fn = "images/heatinstaif.png"
   plt.clf()
   plt.imshow(ifanosi.T[ ::-1,:], interpolation='none', extent=[p1,p2,c1,c2])
   plt.clim(0,2)
   plt.colorbar()
   myplot(r"$Mean(u)$", r"$Var(u)$", tl, fn, xlog=False, legend=False, fsax=50)
Beispiel #27
0
def fig3b_c(make=1):
# contrast changes: variances decrease, means increase. (in membrane potentials)

# the case of 30, 31.5
# for poisson 
#3.3 0.8
#31.9687644444 30.136
# for integration
#1.0 19.6
#31.1467831111 30.3
# saved with name_fit
# 2%

# check out with these parameters; what rates are needed to make the fano-s parallel?
# maybe make a search around these parameters for a better match!
# try to balance the things out
#muRG=0.9;
#muP=1.2;
#cRG=.15;
#cP=.85;
#vRG=2.3;
#vP=.2;
#k=20;   % ezt elosztja 50-nel
#m=1.4;
#threshold = 0;

#   m_p = 3.3
#   v_p = 0.8
#   m_i = 1.0
#   v_i = 19.6

   m_p = 1.2
   v_p = 0.2
   m_i = 0.9
   v_i = 2.3

   if(make==1):
      
      l = 50
      imgNr = 30000 #30000
#      k = 10
#      ne = 1.1
#      ut = 1.9
#      corr_i = 0.15
#      corr_p = 0.95

      k = 10
      ne = 1.4
      ut = 0
      corr_i = 0.15
      corr_p = 0.85
      
      # 1 is the other version, with fig3b_c
      # maybe make it free to choose other variance-changing stuff
      # 3 is the version with Gergo's params
      ui_arr = arange(m_i/2, 1.05*m_i, m_i/10) #make just a part of it, then at plotting symmetry
      ui_cov = arange(v_i, 1.42*v_i, v_i*0.08)[::-1]
      up_arr = arange(m_p/2, 1.05*m_p, m_p/10)
      up_cov = arange(v_p, 3.42*v_p, v_p*0.48)[::-1]
      
      #3.4 for Poisson
      #1.4 for Integration
      times = 3

      n = len(ui_arr)
      pcoeff_arr = zeros((n,times))
      icoeff_arr = zeros((n,times))
      pvar_arr = zeros((n,times))
      pmean_arr = zeros((n,times))
      ivar_arr = zeros((n,times))
      imean_arr = zeros((n,times))
      for i in range(0,n):
         print (i)
         for j in range(times):
            pcoeff_arr[i][j], icoeff_arr[i][j], pvar_arr[i][j], pmean_arr[i][j], ivar_arr[i][j], imean_arr[i][j] = new_gpairs_match2(ui_arr[i], up_arr[i], ui_cov[i], up_cov[i], corr_i, corr_p, l, imgNr, k, ne, ut, k, ne, ut)[0:6]
      save("txt/fig3b_c3.npy", [pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr])
   else:
      pcoeff_arr, icoeff_arr, pvar_arr, pmean_arr, ivar_arr, imean_arr = load("txt/fig3b_c3.npy")
   print(icoeff_arr)
   print(pcoeff_arr)
   
   contr = arange(0,1.05,0.2)
   pfano_arr = divide(pvar_arr, pmean_arr)
   ifano_arr = divide(ivar_arr, imean_arr)
   
   tl = ""#r"$Mean_{SC}$"
   fn = "images/fig3b_c2_m.png"
   plt.clf()
   plt.plot(contr, pmean_arr[:,0], "r.", label = "Poisson", ms = 10)
   plt.plot(contr, imean_arr[:,0], "b.", label = "Integration", ms = 10)
   plt.plot(contr, pmean_arr[:,1:], "r.", ms = 10)
   plt.plot(contr, imean_arr[:,1:], "b.", ms = 10)
   plt.xticks([0.2, 0.5, 0.8])
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$contrast$", r"$Mean_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
   
   tl = ""#r"$Fano_{SC}$"
   fn = "images/fig3b_c2_f.png"
   plt.clf()
   plt.plot(contr, pfano_arr[:,0], "r.", label = "Poisson", ms = 10)
   plt.plot(contr, ifano_arr[:,0], "b.", label = "Integration", ms = 10)
   plt.plot(contr, pfano_arr[:,1:], "r.", ms = 10)
   plt.plot(contr, ifano_arr[:,1:], "b.", ms = 10)
   plt.xticks([0.2, 0.5, 0.8])
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$contrast$", r"$Fano_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
   
   
   tl = ""#r"$\rho_{SC}$"
   fn = "images/fig3b_c2_c.png"
   plt.clf()
   plt.plot(contr, pcoeff_arr[:,0], "r.", label = "Poisson", ms = 10)
   plt.plot(contr, icoeff_arr[:,0], "b.", label = "Integration", ms = 10)
   plt.plot(contr, pcoeff_arr[:,1:], "r.", ms = 10)
   plt.plot(contr, icoeff_arr[:,1:], "b.", ms = 10)
   plt.xticks([0.2, 0.5, 0.8])
   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 30)
   myplot(r"$contrast$", r"$\rho_{SC}$", tl, fn, xlog=False, legend=False, extra=(extra,), fsax=50, xloc=False)
            while batch_start<=train_end:

                batch_end = (batch_start - 1) + batch_size

                if batch_end > train_end:
                    batch_end = train_end + 0

                #weights = weights - d_weights * alpha * 0.1**(0.35*np.log10(i_epoch+1.0))

                weights, m_adam, v_adam = OptimizationUpdate(weights,d_weights,m_adam,v_adam,alpha,i_epoch)

                beta = nn.nn.nn_predict(network, act_fn_name, loss_fn_name, opt_name, weights, features, opt_params)

                if i_epoch==0 and batch_start==1:
                    myplot("ML_init", np.linspace(1,n_data,n_data), beta, '-ob', 2.0, None)
                
                d_beta    = eval_loss_deriv(features, beta)
                d_weights = nn.nn.nn_get_weights_sens(network, act_fn_name, loss_fn_name, opt_name, weights, features, batch_start, batch_end, d_beta, opt_params)

                #print(np.linalg.norm(d_weights))

                batch_start = batch_end + 1

                #d_weights = d_weights / np.max(np.abs(d_weights))

            print("ML Iteration: %6d\t\tLoss: %E"%(i_epoch,eval_loss(features, beta)))

    t2 = time.time()

    print("Time = %E"%(t2-t1))
Beispiel #29
0
def do_it_3(make = 1, mode = 0, diff = "variance"):
   # correlations sampled from Gaussian
   # how does it change with poisson and integartion process
   # mode: 0 - trial-to-trial, 1 - instantaneous
   
   # the first part is not general for variance/mean yet!!!!
   name = "tr2tr"
   if(mode == 1):
      name = "insta"
   if(make == 1):
      stdd = 0.3
      N = 250
      u_mean = 2
      u_meanh = 6
      l  = 150 #0
      imgNr = 3000 # 0
      cov = 1.0
      icoeffs = zeros((N, 1))
      pcoeffs = zeros((N, 1))
      icoeffsh = zeros((N, 1))
      pcoeffsh = zeros((N, 1))
      
      correlations = normal(0, stdd, N)
      for i in range(0,N):
         if(mode == 0):
            pcoeffs[i], icoeffs[i] = new_gpairs(u_mean, correlations[i], l, imgNr, cov)[0:2]
         else:
            pcoeffs[i], icoeffs[i] = new_gpairs_small(u_mean, correlations[i], l*10, cov)[0:2]
      for i in range(0,N):
         if(mode == 0):
            pcoeffsh[i], icoeffsh[i] = new_gpairs(u_meanh, correlations[i], l, imgNr, cov)[0:2]
         else:
            pcoeffsh[i], icoeffsh[i] = new_gpairs_small(u_meanh, correlations[i], l*10, cov)[0:2]
      save("txt/%sdistribc.npy"%name, [pcoeffs, icoeffs, pcoeffsh, icoeffsh, correlations])
   else:
      pcoeffs, icoeffs, pcoeffsh, icoeffsh, correlations = load("txt/%sdistrib_%s.npy"%(name,diff))
    
   print (diff, std(pcoeffs), std(pcoeffsh), std(icoeffs), std(icoeffsh) )
          
       #plot.tick_params(axis='both', which='major', labelsize=10)
   tl = "" #"Trial-to-trial correlations distribution - Poisson"
   if(mode == 1):
      tl = "Instantaneous correlations distribution - Poisson"
   fn = "images/%sdistrib_p1_%s.png"%(name,diff)
   binwidth = 0.03
   ticks = arange(-0.9,1.2,0.3)
   alpha = 0.8
   lw = 4
   xmin = amin([pcoeffs, icoeffs, pcoeffsh, icoeffsh, correlations])
   xmax = amax([pcoeffs, icoeffs, pcoeffsh, icoeffsh, correlations])
   bins=arange(xmin, xmax + binwidth, binwidth)
   plt.clf()
   plt.xticks(ticks)
   if(diff=="mean"):
      plt.hist(pcoeffs, bins=bins, histtype="step", label="Low %s"%diff, color="blue", alpha=alpha, lw=lw)
      plt.hist(pcoeffsh, bins=bins, histtype="step", label="High %s"%diff, color="red", alpha=alpha, lw=lw)
   else:
      plt.hist(pcoeffsh, bins=bins, histtype="step", label="High %s"%diff, color="blue", alpha=alpha, lw=lw)
      plt.hist(pcoeffs, bins=bins, histtype="step", label="Low %s"%diff, color="red", alpha=alpha, lw=lw)
   #yspan = plt.ylim()
#   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 15)
   myplot(r"$\rho_{SC}$", "", tl, fn, xlog=False, legend=False, xloc=False, fsax=50)   #, extra=(extra,)
      
     
   fn = "images/%sdistrib_p_%s.png"%(name,diff)
   binwidth = 0.1
#   if(mode==1):
#      binwidth = 0.05
   alpha = 0.8
   lw = 4
   bins=arange(xmin, xmax + binwidth, binwidth)
   plt.clf()
   plt.xticks(ticks)
   if(diff=="mean"):
      plt.hist(pcoeffs, bins=bins, histtype="step", label="Low %s"%diff, color="blue", alpha=alpha, lw=lw)
      plt.hist(pcoeffsh, bins=bins, histtype="step", label="High %s"%diff, color="red", alpha=alpha, lw=lw)
   else:
      plt.hist(pcoeffsh, bins=bins, histtype="step", label="High %s"%diff, color="blue", alpha=alpha, lw=lw)
      plt.hist(pcoeffs, bins=bins, histtype="step", label="Low %s"%diff, color="red", alpha=alpha, lw=lw)
   #yspan = plt.ylim()
#   extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 15)
   myplot(r"$\rho_{SC}$", "", tl, fn, xlog=False, legend=False, xloc=False, fsax=50) #, extra=(extra,)
   
   tl = "" #"Trial-to-trial correlations distribution - Integration"
   if(mode == 1):
      tl = "Instantaneous correlations distribution - Integration"
   fn = "images/%sdistrib_i_%s.png"%(name,diff)
   plt.clf()
   plt.xticks(ticks)
   if(diff=="mean"):
      plt.hist(icoeffs, bins=bins, histtype="step", label="Low %s"%diff, color="blue", alpha=alpha, lw=lw)
      plt.hist(icoeffsh, bins=bins, histtype="step", label="High %s"%diff, color="red", alpha=alpha, lw=lw)
   else:
      plt.hist(icoeffsh, bins=bins, histtype="step", label="High %s"%diff, color="blue", alpha=alpha, lw=lw)
      plt.hist(icoeffs, bins=bins, histtype="step", label="Low %s"%diff, color="red", alpha=alpha, lw=lw)
   #plt.ylim(yspan)
   #extra = plt.legend(bbox_to_anchor=(1, 0.5), loc='center left', ncol=1, fontsize = 15)
   myplot(r"$\rho_{SC}$", "", tl, fn, xlog=False, legend=False, xloc=False, fsax=50) #, extra=(extra,))
   
   tl = ""#"Trial-to-trial correlations distribution - Potentials"
   if(mode == 1):
      tl = "Instantaneous correlations distribution - Potentials"
   fn = "images/%sdistrib_o_%s.png"%(name,diff)
   plt.clf()
   plt.xticks(ticks)
   plt.hist(correlations, bins=bins, histtype="step", color="green", alpha=alpha, lw=lw)
   #plt.ylim(yspan)
   myplot(r"$\rho_{u}$", "", tl, fn, xlog=False, legend=False, xloc=False, fsax=50)
   return 0