we have boolean variable x either true or false , alternates @ each time step probability p. i.e. if p 0.2, x alternate once every 5 time steps on average. have time line , observations of value of variable @ various non-uniformly sampled points in time.
how 1 learn, observations, probability after t+n time steps t time x observed , n time in future x has alternated/changed value @ t+n given p unknown , have observations of value of x @ previous times? note count changing true false , true again changing value twice.
i'm going approach problem if on test.
first, let's name variables.
bx
value of boolean variable after x
opportunities flip (and b0
initial state). p
chance of changing different value every opportunity.
given each flip opportunity not related other flip opportunities (there is, example, no minimum number of opportunities between flips) math extremely simple; since events not affected events of past, can consolidate them single computation, works best when considering bx
not boolean value, probability.
here domain of computations use: bx
probability (with value between 0 , 1 inclusive) representing likelyhood of truth. p
probability (with value between 0 , 1 inclusive) representing likelyhood of flipping @ given opportunity.
the probability of falseness, 1 - bx
, , probability of not flipping, 1 - p
, probabilistic identities should quite intuitive.
assuming these simple rules, general probability of truth of boolean value given recursive formula bx+1 = bx*(1-p) + (1-bx)*p
.
code (in c++, because it's favorite language , didn't tag one):
int max_opportunities = 8; // total number of chances flip. float flip_chance = 0.2; // probability of flipping each opportunity. float probability_true = 1.0; // starting probability of truth. // 1.0 "definitely true" , 0.0 // "definitely false", can extend // situations initial value not // (say, 0.8 = 80% true) , // work well. (int opportunities = 0; opportunities < max_opportunities; ++opportunities) { probability_true = probability_true * (1 - flip_chance) + (1 - probability_true) * flip_chance; }
here code on ideone (the answer p=0.2
, b0=1
, x=8
b8=0.508398
). expect, given value becomes less , less predictable more , more opportunities pass, final probability approach bx=0.5
. observe oscillations between more , less true, if chance of flipping high (for instance, p=0.8
, beginning of sequence b={1.0, 0.2, 0.68, 0.392, 0.46112, ...}
.
for more complete solution work more complicated scenarios, consider using stochastic matrix (page 7 has example).