function pr_fluctuation_rd_hd %(detection_matrix,hy,epochal_dividers)
%this function looks at the synaptic current measured in the postsynaptic cell in response to short trains of action potentials in the presynaptic cell
%it considers each response as either a success or a failure (the decision is made using template-matching with a threshold, done during analysis of the raw data)
%it assesses: 
%the overall probablity of success of a given pulse
%fluctuations in the probability of success of a given pulse, and how likely these fluctuations are (by finding the most unlikely streaks and seeing how unlikely they are)
%the dependence of a given pulse's success on the response to the previous pulse (release dependence), and fluctuations of this dependence
%the dependence of a given pulse's success on earlier pulses (history dependence), and fluctuations of this dependence
%finally, it can also compare across epochs if that is of use

%for example, for PSC_a, there are 3 possibilities in terms of release dependence:  PSC_o failed, PSC_o succeeded, or PSC_o either failed or succeeded
%another approach:  seeing that c succeeds, if this allows to predict whether b succeeded at better than chance, then we know the dependence of c on b's release

% for ipi=1:length(hy)
%     psuccess_psco=length(find(psco))/length(psco)
%     
% end

%fluctuations over time  %finding the most improbable string(s) of conscecutive successes, and determining just how improbable they were

a=rand(1,10000);
a=a/3;
a(find(a<.3))=0;
a(find(a))=1;
%plot(a)
mean_a=length(find(a))/length(a)
yesno=[0 a 0];

beginnings=~yesno(1:end-1)&yesno(2:end);
endings=yesno(1:end-1)&~yesno(2:end);
streak_starts=find(beginnings);
streak_ends=find(endings);
streak_lengths=streak_ends-streak_starts;
longest_streak=max(streak_lengths')
%contingencies:  what about multiple streaks tied for maximal length?  what about improbably long streaks shorter than the max?  does a single break in a streak nec mean the streak is over?
probb=(mean_a^(longest_streak-1))%*(length(a)-longest_streak)