Exemplo n.º 1
0
        public List <RandomVariable> ForwardBackward(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] = this.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    = this.CalculateNextBackwardMessage(
                    forwardMessages[i], backwardMessage, perceptions[i - 1]);
            }

            return(smoothedBeliefs.ToList());
        }