// // START-ForwardBackwardInference public virtual ICollection <ICategoricalDistribution> forwardBackward(ICollection <ICollection <AssignmentProposition> > ev, ICategoricalDistribution prior) { // local variables: fv, a vector of forward messages for steps 0,...,t ICollection <Matrix> fv = CollectionFactory.CreateQueue <Matrix>(); // b, a representation of the backward message, initially all 1s Matrix b = hmm.createUnitMessage(); // sv, a vector of smoothed estimates for steps 1,...,t ICollection <Matrix> sv = CollectionFactory.CreateQueue <Matrix>(); // fv[0] <- prior fv.Add(hmm.convert(prior)); // for i = 1 to t do for (int i = 0; i < ev.Size(); ++i) { // fv[i] <- FORWARD(fv[i-1], ev[i]) fv.Add(forward(fv.Get(i), hmm.getEvidence(ev.Get(i)))); } // for i = t downto 1 do for (int i = ev.Size() - 1; i >= 0; i--) { // sv[i] <- NORMALIZE(fv[i] * b) sv.Insert(0, hmm.normalize(fv.Get(i + 1).ArrayTimes(b))); // b <- BACKWARD(b, ev[i]) b = backward(b, hmm.getEvidence(ev.Get(i))); } // return sv return(hmm.convert(sv)); }
/** * Algorithm for smoothing with a fixed time lag of d steps, implemented as * an online algorithm that outputs the new smoothed estimate given the * observation for a new time step. * * @param et * the current evidence from time step t * @return a distribution over <b>X</b><sub>t-d</sub> */ public ICategoricalDistribution fixedLagSmoothing(ICollection <AssignmentProposition> et) { // local variables: <b>O</b><sub>t-d</sub>, <b>O</b><sub>t</sub>, // diagonal matrices containing the sensor model information Matrix O_tmd, O_t; // add e<sub>t</sub> to the end of e<sub>t-d:t</sub> e_tmd_to_t.Add(hmm.getEvidence(et)); // <b>O</b><sub>t</sub> <- diagonal matrix containing // <b>P</b>(e<sub>t</sub> | X<sub>t</sub>) O_t = e_tmd_to_t.Get(e_tmd_to_t.Size() - 1); // if t > d then if (t > d) { // remove e<sub>t-d-1</sub> from the beginning of e<sub>t-d:t</sub> e_tmd_to_t.RemoveAt(0); // <b>O</b><sub>t-d</sub> <- diagonal matrix containing // <b>P</b>(e<sub>t-d</sub> | X<sub>t-d</sub>) O_tmd = e_tmd_to_t.Get(0); // <b>f</b> <- FORWARD(<b>f</b>, e<sub>t-d</sub>) f = forward(f, O_tmd); // <b>B</b> <- // <b>O</b><sup>-1</sup><sub>t-d</sub><b>B</b><b>T</b><b>O</b><sub>t</sub> B = O_tmd.Inverse().Times(hmm.getTransitionModel().Inverse()).Times(B).Times(hmm.getTransitionModel()).Times(O_t); } else { // else <b>B</b> <- <b>BTO</b><sub>t</sub> B = B.Times(hmm.getTransitionModel()).Times(O_t); } // if t > d then return NORMALIZE(<b>f</b> * <b>B1</b>) else return null ICategoricalDistribution rVal = null; if (t > d) { rVal = hmm.convert(hmm.normalize(f.ArrayTimes(B.Times(unitMessage)))); } // t <- t + 1 t = t + 1; return(rVal); }