AIMA.Core.Probability.Reasoning.FixedLagSmoothing.smooth C# (CSharp) Method

smooth() public method

public smooth ( String perception ) : RandomVariable
perception String
return RandomVariable
        public RandomVariable smooth(String perception)
        {

            evidenceFromSmoothedStepToPresent.Add(perception);
            Matrix O_t = hmm.sensorModel().asMatrix(perception);
            Matrix transitionMatrix = hmm.transitionModel().asMatrix();
            if (time > timelag)
            {

                forwardMessage = hmm.forward(forwardMessage, perception); // This
                // seems
                // WRONG
                // I think this should be
                // forwardMessage = hmm.forward(forwardMessage,
                // evidenceFromSmoothedStepToPresent.get(0));
                // this the perception at t-d. the book's algorithm
                // uses the latest perception.
                evidenceFromSmoothedStepToPresent.RemoveAt(0);
                Matrix O_t_minus_d = hmm.sensorModel().asMatrix(
                        evidenceFromSmoothedStepToPresent[0]);

                B = O_t_minus_d.inverse().times(
                        transitionMatrix.inverse().times(
                                B.times(transitionMatrix.times(O_t))));

            }
            else
            {

                B = B.times(transitionMatrix.times(O_t));

            }
            time += 1;
            if (time > timelag)
            {

                Matrix one = hmm.prior().createUnitBelief().asMatrix();
                Matrix forwardMatrix = forwardMessage.asMatrix();
                RandomVariable result = hmm.prior().duplicate();
                Matrix backwardMessage = (B.times(one));

                result.updateFrom(forwardMatrix.arrayTimes(backwardMessage));

                result.normalize();
                return result;
            }
            else
            {
                return null;
            }
        }
    }

Usage Example

Example #1
0
        public void testTwoStepFixedLagSmoothingOnRainManHmm()
        {
            FixedLagSmoothing fls = new FixedLagSmoothing(rainmanHmm, 2);

            RandomVariable smoothedOne = fls.smooth(HmmConstants.SEE_UMBRELLA); // see
            // umbrella on day one
            Assert.IsNull(smoothedOne);

            smoothedOne = fls.smooth(HmmConstants.SEE_UMBRELLA); // see
            // umbrella on day two
            Assert.AreEqual(0.653, smoothedOne
                    .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);
            Assert.AreEqual(0.346, smoothedOne
                    .getProbabilityOf(HmmConstants.NOT_RAINING), TOLERANCE);

            RandomVariable smoothedTwo = fls.smooth(HmmConstants.SEE_UMBRELLA);// see
            // umbrella on day 3
            Assert.AreEqual(0.894, smoothedTwo
                    .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);
            Assert.AreEqual(0.105, smoothedTwo
                    .getProbabilityOf(HmmConstants.NOT_RAINING), TOLERANCE);
        }
All Usage Examples Of AIMA.Core.Probability.Reasoning.FixedLagSmoothing::smooth