Algorithm 2:
kdq bayes KL (for homogeneity of adjacent windows)
data: a binary array of [Ndatapoints by Nvariables]; data.sh ← a time-shuffled copy of data (null distribution); γ: sets the number of data points within a window; stepsize: sets the number of data points between comparisons; α sets the value of the parameters of the Dirichlet prior; T ← Construct Binary kdq-tree (data, splitmin); i ← 1; while not at the end of the data do Load adjacent samples W1 and W2 of γ samples from data; Likewise load W1.sh and W2.sh from data.sh; n1 ← multinomial sample generated by filtering W1 through T; n2 ← multinomial sample generated by filtering W2 through T; n1.sh ← multinomial sample generated by filtering W1.sh through T; n2.sh ← multinomial sample generated by filtering W2.sh through T; KLs[i+γ-1] ← bayes KL(n1, n2, α); KLs.sh[i+γ−1] ← bayes KL(n1.sh, n2.sh, α); Slide windows W1, W2, W1.sh and W2.sh by stepsize; i ← i+1; end while null.mode ← mode(KLs.sh[γ to end- γ by stepsize]); null.std ← standard deviation(KLs.sh[γ to end- γ by stepsize]);