예제 #1
0
        public void testOneStepFixedLagSmoothingOnRainManHmm()
        {
            FixedLagSmoothing fls = new FixedLagSmoothing(rainmanHmm, 1);

            RandomVariable smoothedDayZero = fls.smooth(HmmConstants.SEE_UMBRELLA); // see

            // umbrella on day one
            Assert.AreEqual(0.627, smoothedDayZero
                            .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);

            RandomVariable smoothedDayOne = fls.smooth(HmmConstants.SEE_UMBRELLA); // see

            // umbrella on day two
            Assert.AreEqual(0.883, smoothedDayOne
                            .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);
            Assert.AreEqual(0.117, smoothedDayOne
                            .getProbabilityOf(HmmConstants.NOT_RAINING), TOLERANCE);

            RandomVariable smoothedDayTwo = fls
                                            .smooth(HmmConstants.SEE_NO_UMBRELLA); // see no umbrella on

            // day three
            Assert.AreEqual(0.799, smoothedDayTwo
                            .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);
            Assert.AreEqual(0.201, smoothedDayTwo
                            .getProbabilityOf(HmmConstants.NOT_RAINING), TOLERANCE);
        }
예제 #2
0
        public void testForwardBackwardAndFixedLagSmoothingGiveSameResults()
        {
            List <String> perceptions = new List <String>();

            String dayOnePerception   = HmmConstants.SEE_UMBRELLA;
            String dayTwoPerception   = HmmConstants.SEE_UMBRELLA;
            String dayThreePerception = HmmConstants.SEE_NO_UMBRELLA;

            perceptions.Add(dayOnePerception);
            perceptions.Add(dayTwoPerception);
            perceptions.Add(dayThreePerception);

            List <RandomVariable> fbResults = rainmanHmm
                                              .forward_backward(perceptions);

            Assert.AreEqual(4, fbResults.Count);

            // RandomVariable fbDayOneResult = fbResults.get(1);
            // System.Console.WriteLine(fbDayOneResult);

            FixedLagSmoothing fls = new FixedLagSmoothing(rainmanHmm, 2);

            Assert.IsNull(fls.smooth(dayOnePerception));
            // System.Console.WriteLine(fls.smooth(dayTwoPerception));
            // RandomVariable flsDayoneResult = fls.smooth(dayThreePerception);
            // System.Console.WriteLine(flsDayoneResult);
        }
예제 #3
0
        public List <CategoricalDistribution> AskFixedLagSmoothing(object owner, IContextLookup globalVars)
        {
            var model = HiddenMarkovModel.GetModel(owner, globalVars);

            var stateVar      = model.getStateVariable();
            var evidenceVar   = HiddenMarkovModel.ObservationVariable.GetRandomVariable(owner, globalVars);
            var randomVarDico = new Dictionary <string, RandomVariable> {
                { stateVar.getName(), stateVar }, { evidenceVar.getName(), evidenceVar }
            };

            var objAlgorithm = new FixedLagSmoothing(model, LagLength);

            var objEvidences = new java.util.ArrayList(Evidences.Count);
            var toReturn     = new List <CategoricalDistribution>();

            foreach (List <PropositionInfo> propositions in Evidences)
            {
                var stepEvidences = new java.util.ArrayList(propositions.Count);
                foreach (PropositionInfo proposition in propositions)
                {
                    stepEvidences.add(proposition.GetProposition(owner, globalVars, randomVarDico));
                }
                toReturn.Add(objAlgorithm.fixedLagSmoothing(stepEvidences));
            }
            return(toReturn);
        }
예제 #4
0
        public void testFixedLagSmoothing_lag_2_UmbrellaWorld()
        {
            FixedLagSmoothing uw = new FixedLagSmoothing(HMMExampleFactory.getUmbrellaWorldModel(), 2);

            // Day 1 - Lag 2
            ICollection <AssignmentProposition> e1 = CollectionFactory.CreateQueue <AssignmentProposition>();

            e1.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, true));

            ICategoricalDistribution smoothed = uw.fixedLagSmoothing(e1);

            Assert.IsNull(smoothed);

            // Day 2 - Lag 2
            ICollection <AssignmentProposition> e2 = CollectionFactory.CreateQueue <AssignmentProposition>();

            e2.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, true));

            smoothed = uw.fixedLagSmoothing(e2);
            Assert.IsNull(smoothed);

            // Day 3 - Lag 2
            ICollection <AssignmentProposition> e3 = CollectionFactory.CreateQueue <AssignmentProposition>();

            e3.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, false));

            smoothed = uw.fixedLagSmoothing(e3);

            Assert.IsNotNull(smoothed);
            assertArrayEquals(new double[] { 0.861, 0.138 }, smoothed.getValues(), DELTA_THRESHOLD);
        }
예제 #5
0
        public void testOneStepFixedLagSmoothingOnRainManHmmWithDifferingEvidence()
        {
            FixedLagSmoothing fls = new FixedLagSmoothing(rainmanHmm, 1);

            RandomVariable smoothedDayZero = fls.smooth(HmmConstants.SEE_UMBRELLA);// see

            // umbrella on day one
            Assert.AreEqual(0.627, smoothedDayZero
                            .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);

            RandomVariable smoothedDayOne = fls
                                            .smooth(HmmConstants.SEE_NO_UMBRELLA);// no umbrella on day

            // two
            Assert.AreEqual(0.702, smoothedDayOne
                            .getProbabilityOf(HmmConstants.RAINING), TOLERANCE);
            Assert.AreEqual(0.297, smoothedDayOne
                            .getProbabilityOf(HmmConstants.NOT_RAINING), TOLERANCE);
        }
예제 #6
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);
        }
예제 #7
0
        static void fixedLagSmoothingDemo()
        {
            System.Console.WriteLine("DEMO: Fixed-Lag-Smoothing");
            System.Console.WriteLine("=========================");
            System.Console.WriteLine("Lag = 1");
            System.Console.WriteLine("-------");
            FixedLagSmoothing uw = new FixedLagSmoothing(HMMExampleFactory.getUmbrellaWorldModel(), 1);

            // Day 1 - Lag 1
            ICollection <AssignmentProposition> e1 = CollectionFactory.CreateQueue <AssignmentProposition>();

            e1.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, true));

            ICategoricalDistribution smoothed = uw.fixedLagSmoothing(e1);

            System.Console.WriteLine("Day 1 (Umbrella_t=true) smoothed:\nday 1=" + smoothed);

            // Day 2 - Lag 1
            ICollection <AssignmentProposition> e2 = CollectionFactory.CreateQueue <AssignmentProposition>();

            e2.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, true));

            smoothed = uw.fixedLagSmoothing(e2);

            System.Console.WriteLine("Day 2 (Umbrella_t=true) smoothed:\nday 1=" + smoothed);

            // Day 3 - Lag 1
            ICollection <AssignmentProposition> e3 = CollectionFactory.CreateQueue <AssignmentProposition>();

            e3.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, false));

            smoothed = uw.fixedLagSmoothing(e3);

            System.Console.WriteLine("Day 3 (Umbrella_t=false) smoothed:\nday 2=" + smoothed);

            System.Console.WriteLine("-------");
            System.Console.WriteLine("Lag = 2");
            System.Console.WriteLine("-------");

            uw = new FixedLagSmoothing(HMMExampleFactory.getUmbrellaWorldModel(), 2);

            // Day 1 - Lag 2
            e1 = CollectionFactory.CreateQueue <AssignmentProposition>();
            e1.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, true));

            smoothed = uw.fixedLagSmoothing(e1);

            System.Console.WriteLine("Day 1 (Umbrella_t=true) smoothed:\nday 1=" + smoothed);

            // Day 2 - Lag 2
            e2 = CollectionFactory.CreateQueue <AssignmentProposition>();
            e2.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, true));

            smoothed = uw.fixedLagSmoothing(e2);

            System.Console.WriteLine("Day 2 (Umbrella_t=true) smoothed:\nday 1=" + smoothed);

            // Day 3 - Lag 2
            e3 = CollectionFactory.CreateQueue <AssignmentProposition>();
            e3.Add(new AssignmentProposition(ExampleRV.UMBREALLA_t_RV, false));

            smoothed = uw.fixedLagSmoothing(e3);

            System.Console.WriteLine("Day 3 (Umbrella_t=false) smoothed:\nday 1=" + smoothed);

            System.Console.WriteLine("=========================");
        }