Published
Edited
Feb 10, 2018
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function markov(n, theta) {
let arr = Array(n);
// choose first item randomly
arr[0] = (Math.random() < 0.5) ? "A" : "B";
for (let i = 1; i < n; i++) {
arr[i] = (Math.random() < theta) ? toggle(arr[i-1]) : arr[i-1];
}
return arr;
}
Insert cell
Insert cell
markov(10, 0.5)
Insert cell
markov(10, 0.9)
Insert cell
markov(15, 0.1)
Insert cell
Insert cell
function countTrans(arr) {
let cnt = 0;
for (let i = 1; i < arr.length; i++) {
if (arr[i] != arr[i-1])
cnt++;
}
return cnt;
}
Insert cell
Insert cell
countTrans(["A", "B", "B", "B", "A", "A", "A", "B", "B", "A"])
Insert cell
Insert cell
dataSeq = markov(dataSeqSize, thetaTrue)
Insert cell
Insert cell
function abcInf(nSamples, targetSeq, tolerance) {
let samples = Array(nSamples);
let c = 0
while (c < nSamples) {
let theta = Math.random();
let testSeq = markov(targetSeq.length, theta);
if (Math.abs(countTrans(testSeq) - countTrans(targetSeq)) <= tolerance) {
samples[c] = theta;
c++;
}
}
return samples;
}
Insert cell
Insert cell
abcInf(10, dataSeq, 1)
Insert cell
Insert cell
samples = abcInf(nSamples, dataSeq, 1)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more