123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- load('data_fig_2.db','-mat');
- res={};
- bins=(1:300)*.002;
- res.allcells.positive=0*bins;
- res.allcells.negative=0*bins;
- res.allcells.shuff=zeros(1000,numel(bins));
- typ='allcells';
- delta_r=5.0666667;
- delta_l=30.4;
- if 1
- for i=1:numel(alldata.ts)
-
-
- data=alldata.pos{i};
- ts=alldata.ts{i};
-
- %%
- nlaps=min(numel(data.log.end_r),numel(data.log.end_l));
-
- right=(data.log.start_r(1:nlaps)+delta_r)';
- left=(data.log.start_l(1:nlaps)+delta_l)';
- dwin=.5;
- %% speed
- 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);
- 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);
- res.(typ).fast(i,:)=hist(autoc2(ts(selfast)),bins)/6;
- res.(typ).slow(i,:)=hist(autoc2(ts(selslow)),bins)/40;
-
- %% acceleration
- res.(typ).negative=res.(typ).negative + hist(autoc2(ts(is_inside(ts',right,right+dwin))),bins);
- res.(typ).positive=res.(typ).positive + hist(autoc2(ts(is_inside(ts',left,left+dwin))),bins);
-
- for j=1:1000
- shuff_fast=data.log.start_r'+1+3*rand(1,nlaps);
- shuff_slow=data.log.start_l'+5+20*rand(1,nlaps);
- shuff=[shuff_fast shuff_slow];
- shuff=shuff(randperm(numel(shuff),numel(shuff)/2));
- res.(typ).shuff(j,:)=res.(typ).shuff(j,:)+hist(autoc2(ts(is_inside(ts',shuff,shuff+dwin))),bins);
- end
-
- end
- end
- %%
- %%
- close all
- bins=(1:150)*.004;
- %%
- sel=bins>0.01 & bins<0.3;
- types={'allcells'};
- nshuf=1000;
- sname='shuff_speed.mat';
- if exist(sname,'file')
- load(sname,'-mat')
- else
- sh_f1={};sh_f2={};
- for ty=1:numel(types)
- typ=types{ty};
- sh_f1.(typ)=zeros(1,nshuf);
- sh_f2.(typ)=zeros(1,nshuf);
- for j=1:nshuf
- if mod(j,100)==0
- disp(j);
- end
- sel=rand(1,size(res.(typ).fast,1))>.5;
-
- aux1=mean([reshape(res.(typ).fast(sel,:),[],150); reshape(res.(typ).slow(~sel,:),[],150)]);
- aux2=mean([reshape(res.(typ).fast(~sel,:),[],150); reshape(res.(typ).slow(sel,:),[],150)]);
- aux1(end)=0;
- aux2(end)=0;
- aux1=aux1/max(aux1);
- aux2=aux2/max(aux2);
- c1=do_fit(bins,aux1);
- c2=do_fit(bins,aux2);
-
- sh_f1.(typ)(j)=c1.f;
- sh_f2.(typ)(j)=c2.f;
-
- end
- end
- save(sname,'sh_f1','sh_f2','-mat');
- end
- %% speed
- for ty=numel(types)
- typ=types{ty};
- f=figure;
- hold on;
- aux=mean(reshape(res.(typ).fast,[],150))/8;
- aux(end)=0;
- mxaux=max(aux);
- aux=aux/max(aux);
- ffast=do_plot(bins,aux,[0 1 0],[.5 1 .5]);
- auxs=mean(reshape(res.(typ).slow,[],150))/40;
- auxs(end)=0;
- mxauxs=max(auxs);
- auxs=auxs/max(auxs);
- fslow=do_plot(bins,auxs,[1 0 0],[1 .5*[1 1]]);
- subplot(2,2,1)
- axis([0 .3 0.3 1.2]);
- gl=1.5;
- set(gca,'YTick',0:.5:2,'FontName','Arial');
- subplot(2,2,2)
- axis([0 .3 .15*[-1 1] ]);
- set(gca,'YTick',-.6:.1:.6,'FontName','Arial');
- subplot(2,2,3)
- fbins=7.5:.01:8.5;
- h=hist([sh_f1.(typ) sh_f2.(typ)],fbins);
- b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
- mx=ceil(2*max(h));
- hold on;
- legend off;
- line((fslow)*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
- line(ffast*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
- axis([7.6 8.0 0 380]);
- axis([7.5 9.5 0 380]);
- set(gca,'YTick',0:100:300)
- subplot(224)
- fbins=7.5:.01:8.5;
- h=hist([sh_f1.(typ) sh_f2.(typ)],fbins);
- b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
- mx=ceil(2*max(h));
- hold on;
- legend off;
- line((fslow)*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
- line(ffast*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
- axis([7.6 8.0 0 300]);
- set(gca,'YTick',0:100:300)
- end
- %% Acceleration
- gs=0;
- figure;
- for ty=numel(types)
- typ=types{ty};
- hold on;
- aux=gauss_boxcar(mean(reshape(res.(typ).negative,2,150)),gs);
- aux=aux/max(aux);
- fm=do_plot(bins,aux,[0 0 0],.5*[1 1 1]);
- aux=gauss_boxcar(mean(reshape(res.(typ).shuff(1,:),2,150)),gs);
- aux=aux/max(aux);
- fc=do_plot(bins,aux,[0 1 0],[.5 1 .5]);
- aux=gauss_boxcar(mean(reshape(res.(typ).positive,2,150)),gs);
- aux=aux/max(aux);
- fp=do_plot(bins,aux,[1 0 0],[1 .5*[1 1]]);
- end
- subplot(2,2,1)
- axis([0 .3 0.3 1.2]);
- set(gca,'YTick',0:.5:2,'FontName','Arial');
- subplot(2,2,2)
- axis([0 .3 .15*[-1 1] ]);
- set(gca,'YTick',-.6:.1:.6,'FontName','Arial');
- sname='shuff_acc.mat';
- if exist(sname,'file')
- load(sname,'-mat')
- else
-
- for j=1:nshuf
- if mod(j,100)==0
- disp(j);
- end
- acc_f(j)=all_fit(res.(typ).shuff(j,:));
- end
- save(sname,'acc_f','-mat');
- end
- %%
- subplot(2,2,3)
- fbins=7:.05:9;
- h=hist(acc_f,fbins);
- h=h;%/sum(h);
- b=bar(fbins,h,'LineStyle','none','FaceColor',.5*[1 2 1],'BarWidth',1.0);
- mx=ceil(2.1*max(h));
- gg=fit(fbins',h','gauss1');
- hold on;
- p1=plot(gg);
- set(p1,'Color',[.5 1 .5]-.5);
- legend off;
- % line(fc*[1 1],[0 mx],'LineWidth',2,'Color',[0 1 0]);
- line(fm*[1 1],[0 mx],'LineWidth',2,'Color',[1 1 1]*.5);
- line(fp*[1 1],[0 mx],'LineWidth',2,'Color',[1 .5 .5]);
- axis([7.5 9.5 0 280]);
- set(gca,'YTick',0:100:300);
- p_n=(1-erf((fm-gg.b1)/gg.c1));
- p_p=(1-erf((fp-gg.b1)/gg.c1));
- title(['neg: ' num2str(1-erf(abs(fm-gg.b1)/gg.c1)) ' pos: ' num2str(p_p)]);
- %%
|