コード例 #1
0
 public FixedLagSmoothing(HiddenMarkovModel hmm, int timelag)
 {
     this.hmm = hmm;
     this.timelag = timelag;
     this.evidenceFromSmoothedStepToPresent = new List<String>();
     this.time = 1;
     this.forwardMessage = hmm.prior();
     this.B = hmm.transitionModel().unitMatrix();
 }
コード例 #2
0
 public FixedLagSmoothing(HiddenMarkovModel hmm, int timelag)
 {
     this.hmm     = hmm;
     this.timelag = timelag;
     this.evidenceFromSmoothedStepToPresent = new List <String>();
     this.time           = 1;
     this.forwardMessage = hmm.prior();
     this.B = hmm.transitionModel().unitMatrix();
 }
コード例 #3
0
        public void testTransitionModelGeneratesNewStateWhenGivenOldStateAndProbability()
        {
            TransitionModel tm       = rainman.transitionModel();
            String          oldState = HmmConstants.RAINING;
            String          state1   = tm.getStateForProbability(oldState, randomizer
                                                                 .nextDouble());
            String state2 = tm.getStateForProbability(oldState, randomizer
                                                      .nextDouble());

            Assert.AreEqual(state1, HmmConstants.RAINING);
            Assert.AreEqual(state2, HmmConstants.NOT_RAINING);
        }
コード例 #4
0
        public ParticleSet generateParticleSetForPredictedState(String action,
                                                                Randomizer randomizer)
        {
            ParticleSet predictedParticleSet = new ParticleSet(this.hmm);

            foreach (Particle p in particles)
            {
                String newState = hmm.transitionModel().getStateForProbability(
                    p.getState(), action, randomizer.nextDouble());

                Particle generatedParticle = new Particle(newState);
                predictedParticleSet.add(generatedParticle);
            }
            return(predictedParticleSet);
        }
コード例 #5
0
        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);
            }
        }