sp = zeros(37,round(length(lfp)/1250*1000));
for i=1:length(spikes)
sp(i,round(s{i}*1000))=1;
end

for i =1:length(spikes)
    spp(i,:) = smoothts(sp(i,:),'b',30);
end
count=1;
hold on


for t = 1:length(ts)
    
    sp_sum = sum(sp(cellseq(t,:),:));
    sp_all = spp(cellseq(t,:),:);
    sp_seq = zeros(1,length(sp));
    sp_seq(round(ts{t}(:,2)*1000)) = 1;
    
    sp_sum = smoothts(sp_sum,'b',30);

    sp_seq = smoothts(sp_seq,'b',30);
    
    
    for tt=1:length(spikes)
       if ~ismember(tt,cellseq(t,:))
           [b_sum{t}(tt,:) dev_sum{t}(tt) ] = glmfit(sp_sum',sp(tt,:)','normal');
           yfit_sum = glmval(b_sum{t}(tt,:)',sp_sum','identity');
           p = normpdf(sp_sum,yfit_sum');
           p(p==0)=nan;
           logl{t}(tt,1) = nansum(log(p));
           
           [b_all{t}(tt,:) dev_all{t}(tt) ] = glmfit(sp_all',sp(tt,:)','normal');
           yfit_all = glmval(b_all{t}(tt,:)',sp_all','identity');
           p = normpdf(sp_sum,yfit_all');
           p(p==0)=nan;
           logl{t}(tt,2) = nansum(log(p));
           
           [b_seq{t}(tt,:) dev_seq{t}(tt) ] = glmfit(sp_seq',sp(tt,:)','normal');
           yfit_seq = glmval(b_seq{t}(tt,:)',sp_seq','identity');
           p = normpdf(sp_sum,yfit_seq');
           p(p==0)=nan;
           logl{t}(tt,3) = nansum(log(p));
           clear p
                 
           aic{t}(tt,:) = aicbic([logl{t}(tt,:)],[1 5 1]);
           plot(count,squeeze(aic{t}(tt,1))./mean(aic{t}(tt,:)),'.k')
           plot(count,squeeze(aic{t}(tt,2))./mean(aic{t}(tt,:)),'.g')
           plot(count,squeeze(aic{t}(tt,3))./mean(aic{t}(tt,:)),'.r')
           count=1+count;
           title('AIC scores: green-sum, red-eq, black-all trains')
           hold on
           pause(.1)
       end       
    end
end