Пример #1
0
    def getReadingDistributionGivenObservations(self, observations,
                                                newLocation):
        """ Given a current set of observations and a location, it computes the
    probability of each possibly sensor reading at this position given other sensor readings.
    Thus the return value is a mapping from sensor readings to probabilities. """
        # QUESTION 3
        if (observations.has_key(newLocation) > 0):
            #print "WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
            #print newLocation, observations
            dist = util.listToDistribution([observations[newLocation]])

            #print dist
            #print "WEE"
            return dist

        readingDistribution = util.Counter()
        from ghostbusters import Readings
        currentSetProbability = self.getReadingSetProbability(observations)
        for reading in Readings.getReadings():
            newObservations = observations.copy()
            newObservations[newLocation] = reading
            readingDistribution[reading] = self.getReadingSetProbability(
                newObservations) / currentSetProbability

        return readingDistribution
Пример #2
0
 def observe(self, observation, emissionFn):
   # update beliefs
   # P(X_t | e_1:t, e') ~ P(e'|X_t) * P(X_t | e_1:t)
   for particle in self.particles.keys():
     # reweight each particle by observations
     self.particles[particle] *= emissionFn(observation, particle)
   
   # resample observation
   self.particles.normalize()
   samples = util.sampleMultiple(self.particles, self.numParticles)
   self.particles = util.listToDistribution(samples)
Пример #3
0
    def observe(self, observation, emissionFn):
        # update beliefs
        # P(X_t | e_1:t, e') ~ P(e'|X_t) * P(X_t | e_1:t)
        for particle in self.particles.keys():
            # reweight each particle by observations
            self.particles[particle] *= emissionFn(observation, particle)

        # resample observation
        self.particles.normalize()
        samples = util.sampleMultiple(self.particles, self.numParticles)
        self.particles = util.listToDistribution(samples)
    def getBeliefDistribution(self):
        """
    Return the agent's current belief (approximation) as a distribution
    over ghost tuples.  Note that this distribution can and should be
    sparse in the sense that many tuples may not be represented in the 
    distribution if there are more tuples than particles.  The probability
    over these missing tuples will be treated as zero by the GUI.
    """

        "*** YOUR CODE HERE ***"
        return util.listToDistribution(self.particles)
    def getBeliefDistribution(self):
        """
    Return the agent's current belief (approximation) as a distribution
    over ghost tuples.  Note that this distribution can and should be
    sparse in the sense that many tuples may not be represented in the 
    distribution if there are more tuples than particles.  The probability
    over these missing tuples will be treated as zero by the GUI.
    """

        "*** YOUR CODE HERE ***"
        return util.listToDistribution(self.particles)
 def getReadingDistributionGivenObservations(self, observations, newLocation):
   """ Given a current set of observations and a location, it computes the
   probability of each possibly sensor reading at this position given other sensor readings.
   Thus the return value is a mapping from sensor readings to probabilities. """
   # QUESTION 3
   if (observations.has_key(newLocation) > 0):
       #print "WEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
       #print newLocation, observations
       dist = util.listToDistribution([observations[newLocation]])
       
       #print dist
       #print "WEE"
       return dist
   
   readingDistribution = util.Counter()
   from ghostbusters import Readings
   currentSetProbability = self.getReadingSetProbability(observations)
   for reading in Readings.getReadings():
     newObservations = observations.copy()
     newObservations[newLocation] = reading
     readingDistribution[reading] = self.getReadingSetProbability(newObservations) / currentSetProbability
   
   return readingDistribution