Fig_2.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. load('data_fig_2.db','-mat');
  2. res={};
  3. bins=(1:300)*.002;
  4. res.allcells.positive=0*bins;
  5. res.allcells.negative=0*bins;
  6. res.allcells.shuff=zeros(1000,numel(bins));
  7. typ='allcells';
  8. delta_r=5.0666667;
  9. delta_l=30.4;
  10. if 1
  11. for i=1:numel(alldata.ts)
  12. data=alldata.pos{i};
  13. ts=alldata.ts{i};
  14. %%
  15. nlaps=min(numel(data.log.end_r),numel(data.log.end_l));
  16. right=(data.log.start_r(1:nlaps)+delta_r)';
  17. left=(data.log.start_l(1:nlaps)+delta_l)';
  18. dwin=.5;
  19. %% speed
  20. selfast=is_inside(ts',data.log.start_r'+1,data.log.start_r'+4) | is_inside(ts',data.log.start_l'+31.5,data.log.start_l'+34.5);
  21. selslow=is_inside(ts',data.log.start_l'+5,data.log.start_l'+25) | is_inside(ts',data.log.start_r'+8,data.log.start_r'+28);
  22. res.(typ).fast(i,:)=hist(autoc2(ts(selfast)),bins)/6;
  23. res.(typ).slow(i,:)=hist(autoc2(ts(selslow)),bins)/40;
  24. %% acceleration
  25. res.(typ).negative=res.(typ).negative + hist(autoc2(ts(is_inside(ts',right,right+dwin))),bins);
  26. res.(typ).positive=res.(typ).positive + hist(autoc2(ts(is_inside(ts',left,left+dwin))),bins);
  27. for j=1:1000
  28. shuff_fast=data.log.start_r'+1+3*rand(1,nlaps);
  29. shuff_slow=data.log.start_l'+5+20*rand(1,nlaps);
  30. shuff=[shuff_fast shuff_slow];
  31. shuff=shuff(randperm(numel(shuff),numel(shuff)/2));
  32. res.(typ).shuff(j,:)=res.(typ).shuff(j,:)+hist(autoc2(ts(is_inside(ts',shuff,shuff+dwin))),bins);
  33. end
  34. end
  35. end
  36. %%
  37. %%
  38. close all
  39. bins=(1:150)*.004;
  40. %%
  41. sel=bins>0.01 & bins<0.3;
  42. types={'allcells'};
  43. nshuf=1000;
  44. sname='shuff_speed.mat';
  45. if exist(sname,'file')
  46. load(sname,'-mat')
  47. else
  48. sh_f1={};sh_f2={};
  49. for ty=1:numel(types)
  50. typ=types{ty};
  51. sh_f1.(typ)=zeros(1,nshuf);
  52. sh_f2.(typ)=zeros(1,nshuf);
  53. for j=1:nshuf
  54. if mod(j,100)==0
  55. disp(j);
  56. end
  57. sel=rand(1,size(res.(typ).fast,1))>.5;
  58. aux1=mean([reshape(res.(typ).fast(sel,:),[],150); reshape(res.(typ).slow(~sel,:),[],150)]);
  59. aux2=mean([reshape(res.(typ).fast(~sel,:),[],150); reshape(res.(typ).slow(sel,:),[],150)]);
  60. aux1(end)=0;
  61. aux2(end)=0;
  62. aux1=aux1/max(aux1);
  63. aux2=aux2/max(aux2);
  64. c1=do_fit(bins,aux1);
  65. c2=do_fit(bins,aux2);
  66. sh_f1.(typ)(j)=c1.f;
  67. sh_f2.(typ)(j)=c2.f;
  68. end
  69. end
  70. save(sname,'sh_f1','sh_f2','-mat');
  71. end
  72. %% speed
  73. for ty=numel(types)
  74. typ=types{ty};
  75. f=figure;
  76. hold on;
  77. aux=mean(reshape(res.(typ).fast,[],150))/8;
  78. aux(end)=0;
  79. mxaux=max(aux);
  80. aux=aux/max(aux);
  81. ffast=do_plot(bins,aux,[0 1 0],[.5 1 .5]);
  82. auxs=mean(reshape(res.(typ).slow,[],150))/40;
  83. auxs(end)=0;
  84. mxauxs=max(auxs);
  85. auxs=auxs/max(auxs);
  86. fslow=do_plot(bins,auxs,[1 0 0],[1 .5*[1 1]]);
  87. subplot(2,2,1)
  88. axis([0 .3 0.3 1.2]);
  89. gl=1.5;
  90. set(gca,'YTick',0:.5:2,'FontName','Arial');
  91. subplot(2,2,2)
  92. axis([0 .3 .15*[-1 1] ]);
  93. set(gca,'YTick',-.6:.1:.6,'FontName','Arial');
  94. subplot(2,2,3)
  95. fbins=7.5:.01:8.5;
  96. h=hist([sh_f1.(typ) sh_f2.(typ)],fbins);
  97. b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
  98. mx=ceil(2*max(h));
  99. hold on;
  100. legend off;
  101. line((fslow)*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
  102. line(ffast*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
  103. axis([7.6 8.0 0 380]);
  104. axis([7.5 9.5 0 380]);
  105. set(gca,'YTick',0:100:300)
  106. subplot(224)
  107. fbins=7.5:.01:8.5;
  108. h=hist([sh_f1.(typ) sh_f2.(typ)],fbins);
  109. b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
  110. mx=ceil(2*max(h));
  111. hold on;
  112. legend off;
  113. line((fslow)*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
  114. line(ffast*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
  115. axis([7.6 8.0 0 300]);
  116. set(gca,'YTick',0:100:300)
  117. end
  118. %% Acceleration
  119. gs=0;
  120. figure;
  121. for ty=numel(types)
  122. typ=types{ty};
  123. hold on;
  124. aux=gauss_boxcar(mean(reshape(res.(typ).negative,2,150)),gs);
  125. aux=aux/max(aux);
  126. fm=do_plot(bins,aux,[0 0 0],.5*[1 1 1]);
  127. aux=gauss_boxcar(mean(reshape(res.(typ).shuff(1,:),2,150)),gs);
  128. aux=aux/max(aux);
  129. fc=do_plot(bins,aux,[0 1 0],[.5 1 .5]);
  130. aux=gauss_boxcar(mean(reshape(res.(typ).positive,2,150)),gs);
  131. aux=aux/max(aux);
  132. fp=do_plot(bins,aux,[1 0 0],[1 .5*[1 1]]);
  133. end
  134. subplot(2,2,1)
  135. axis([0 .3 0.3 1.2]);
  136. set(gca,'YTick',0:.5:2,'FontName','Arial');
  137. subplot(2,2,2)
  138. axis([0 .3 .15*[-1 1] ]);
  139. set(gca,'YTick',-.6:.1:.6,'FontName','Arial');
  140. sname='shuff_acc.mat';
  141. if exist(sname,'file')
  142. load(sname,'-mat')
  143. else
  144. for j=1:nshuf
  145. if mod(j,100)==0
  146. disp(j);
  147. end
  148. acc_f(j)=all_fit(res.(typ).shuff(j,:));
  149. end
  150. save(sname,'acc_f','-mat');
  151. end
  152. %%
  153. subplot(2,2,3)
  154. fbins=7:.05:9;
  155. h=hist(acc_f,fbins);
  156. h=h;%/sum(h);
  157. b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
  158. mx=ceil(2.1*max(h));
  159. gg=fit(fbins',h','gauss1');
  160. hold on;
  161. p1=plot(gg);
  162. set(p1,'Color',[.5 1 .5]-.5);
  163. legend off;
  164. % line(fc*[1 1],[0 mx],'LineWidth',2,'Color',[0 1 0]);
  165. line(fm*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
  166. line(fp*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
  167. axis([7.5 9.5 0 280]);
  168. set(gca,'YTick',0:100:300);
  169. p_n=(1-erf((fm-gg.b1)/gg.c1));
  170. p_p=(1-erf((fp-gg.b1)/gg.c1));
  171. title(['neg: ' num2str(1-erf(abs(fm-gg.b1)/gg.c1)) ' pos: ' num2str(p_p)]);
  172. %%