public ParticleSet PerceptionUpdate(string perception, IRandomizer r) { // compute Particle Weight foreach (Particle p in particles) { double particleWeight = hmm.SensorModel.Get(p.State, perception); p.Weight = particleWeight; } // weighted sample to create new ParticleSet ParticleSet result = new ParticleSet(hmm); while (result.Count != Count) { foreach (Particle p in particles) { double probability = r.NextDouble(); if (probability <= p.Weight) { if (result.Count < Count) { result.Add(new Particle(p.State, p.Weight)); } } } } return(result); }
public ParticleSet GenerateParticleSetForPredictedState(string action, IRandomizer randomizer) { ParticleSet predictedParticleSet = new ParticleSet(this.hmm); foreach (Particle p in particles) { string newState = hmm.TransitionModel.GetStateForProbability( p.State, action, randomizer.NextDouble()); Particle generatedParticle = new Particle(newState); predictedParticleSet.Add(generatedParticle); } return(predictedParticleSet); }