Example #1
0
def leftSlipTransNoiseModel(nominalLoc, hallwayLength):
    """
    @param nominalLoc: location that the robot would have ended up
    given perfect dynamics
    @param hallwayLength: length of the hallway
    @returns: distribution over resulting locations, modeling noisy
    execution of commands;  in this case, the robot goes to the
    nominal location with probability 0.9, and goes one step too far
    left with probability 0.1.
    If any of these locations are out of bounds, then the associated
    probability mass stays at C{nominalLoc}.
    """
    d = {}
    dist.incrDictEntry(d, util.clip(loc - 1, 0, n - 1), 0.1)
    dist.incrDictEntry(d, util.clip(loc, 0, n - 1), 0.9)
    return dist.DDist(d)
Example #2
0
def leftSlipTransNoiseModel(nominalLoc, hallwayLength):
    """
    @param nominalLoc: location that the robot would have ended up
    given perfect dynamics
    @param hallwayLength: length of the hallway
    @returns: distribution over resulting locations, modeling noisy
    execution of commands;  in this case, the robot goes to the
    nominal location with probability 0.9, and goes one step too far
    left with probability 0.1.
    If any of these locations are out of bounds, then the associated
    probability mass stays at C{nominalLoc}.
    """
    d = {}
    dist.incrDictEntry(d, util.clip(loc-1, 0, n-1), 0.1)
    dist.incrDictEntry(d, util.clip(loc, 0, n-1), 0.9)
    return dist.DDist(d)
Example #3
0
    def getNextValues(self, state, inp):
        """
        @param state: Distribution over states of the subject machine,
        represented as a C{dist.Dist} object
        @param inp: A pair C{(o, a)} of the input and output of the
        subject machine on this time step.  If this parameter is
        C{None}, then no update occurs and the state is returned,
        unchanged. 
        """
        if inp == None:
            return (state, state)

        (o, i) = inp

        total = 0
        afterObs = state.d.copy()
        for s in state.support():
            afterObs[s] *= self.model.observationDistribution(s).prob(o)
            total += afterObs[s]

        if total == 0:
            raise Exception('Observation '+str(o)+\
                            ' has 0 probability in all possible states.')

        # Note: afterObs is not normalized at this point; dividing
        # through by toal during the transition update

        new = {}
        tDist = self.model.transitionDistribution(i)
        for s in state.support():
            tDistS = tDist(s)
            oldP = afterObs[s] / total
            for sPrime in tDistS.support():
                dist.incrDictEntry(new, sPrime, tDistS.prob(sPrime) * oldP)
        dSPrime = dist.DDist(new)

        return (dSPrime, dSPrime)
Example #4
0
    def getNextValues(self, state, inp):
        """
        @param state: Distribution over states of the subject machine,
        represented as a C{dist.Dist} object
        @param inp: A pair C{(o, a)} of the input and output of the
        subject machine on this time step.  If this parameter is
        C{None}, then no update occurs and the state is returned,
        unchanged. 
        """
        if inp == None:
            return (state, state)

        (o, i) = inp

        total = 0
        afterObs = state.d.copy()
        for s in state.support():
            afterObs[s] *= self.model.observationDistribution(s).prob(o)
            total += afterObs[s]

        if total == 0:
            raise Exception('Observation '+str(o)+\
                            ' has 0 probability in all possible states.')

        # Note: afterObs is not normalized at this point; dividing
        # through by toal during the transition update

        new = {}
        tDist = self.model.transitionDistribution(i)
        for s in state.support():
            tDistS = tDist(s)
            oldP = afterObs[s] /total
            for sPrime in tDistS.support():
                dist.incrDictEntry(new, sPrime, tDistS.prob(sPrime) * oldP)
        dSPrime = dist.DDist(new)
            
        return (dSPrime, dSPrime)
Example #5
0
def noisyTransNoiseModel(nominalLoc, hallwayLength):
    """
    @param nominalLoc: location that the robot would have ended up
    given perfect dynamics
    @param hallwayLength: length of the hallway
    @returns: distribution over resulting locations, modeling noisy
    execution of commands;  in this case, the robot goes to the
    nominal location with probability 0.8, goes one step too far left with
    probability 0.1, and goes one step too far right with probability 0.1.
    If any of these locations are out of bounds, then the associated
    probability mass goes is assigned to the boundary location (either
    0 or C{hallwayLength-1}).  
    """
    d = {}
    dist.incrDictEntry(d, util.clip(nominalLoc - 1, 0, hallwayLength - 1), 0.1)
    dist.incrDictEntry(d, util.clip(nominalLoc, 0, hallwayLength - 1), 0.8)
    dist.incrDictEntry(d, util.clip(nominalLoc + 1, 0, hallwayLength - 1), 0.1)
    return dist.DDist(d)
Example #6
0
def noisyTransNoiseModel(nominalLoc, hallwayLength):
    """
    @param nominalLoc: location that the robot would have ended up
    given perfect dynamics
    @param hallwayLength: length of the hallway
    @returns: distribution over resulting locations, modeling noisy
    execution of commands;  in this case, the robot goes to the
    nominal location with probability 0.8, goes one step too far left with
    probability 0.1, and goes one step too far right with probability 0.1.
    If any of these locations are out of bounds, then the associated
    probability mass goes is assigned to the boundary location (either
    0 or C{hallwayLength-1}).  
    """
    d = {}
    dist.incrDictEntry(d, util.clip(nominalLoc-1, 0, hallwayLength-1), 0.1)
    dist.incrDictEntry(d, util.clip(nominalLoc, 0, hallwayLength-1), 0.8)
    dist.incrDictEntry(d, util.clip(nominalLoc+1, 0, hallwayLength-1), 0.1)
    return dist.DDist(d)