예제 #1
0
        public List <RandomVariable> forward_backward(List <String> perceptions)
        {
            RandomVariable[] forwardMessages = new RandomVariable[perceptions
                                                                  .Count + 1];
            RandomVariable backwardMessage = priorDistribution.createUnitBelief();

            RandomVariable[] smoothedBeliefs = new RandomVariable[perceptions
                                                                  .Count + 1];

            forwardMessages[0] = priorDistribution;
            smoothedBeliefs[0] = null;

            // populate forward messages
            for (int i = 0; i < perceptions.Count; i++)
            { // N.B i starts at 1,
                // not zero
                forwardMessages[i + 1] = forward(forwardMessages[i], perceptions[i]);
            }
            for (int i = perceptions.Count; i > 0; i--)
            {
                RandomVariable smoothed = priorDistribution.duplicate();
                smoothed.updateFrom(forwardMessages[i].asMatrix().arrayTimes(
                                        backwardMessage.asMatrix()));
                smoothed.normalize();
                smoothedBeliefs[i] = smoothed;
                backwardMessage    = calculate_next_backward_message(
                    forwardMessages[i], backwardMessage, perceptions[i - 1]);
            }

            return(new List <RandomVariable>(smoothedBeliefs));
        }