def makeSim(hallwayColors, legalInputs, obsNoise, dynamics, transNoise, title='sim', initialDist=None): """ Make an instance of the simulator with noisy motion and sensing models. @param hallwayColors: A list of the colors of the rooms in the hallway, from left to right. @param legalInputs: A list of the possible action commands @param obsNoise: conditional distribution specifying the probability of observing a color given the actual color of the room @param dynamics: function that takes the robot's current location, action, and hallwaylength, and returns its nominal new location @param transNoise: P(actualResultingLocation | nominalResultingLoc) represented as a function from ideal location to the actual location the robot will end up in @param title: String specifying title for simulator window """ n = len(hallwayColors) if not initialDist: initialDist = dist.UniformDist(range(n)) worldSM = ssm.StochasticSM(initialDist, makeTransitionModel(dynamics, transNoise, n), makeObservationModel(hallwayColors, obsNoise)) return makeSESwithGUI(worldSM, hallwayColors, legalInputs, verbose=True, title=title, initBelief=initialDist)
def hallSE(hallwayColors, legalInputs, obsNoise, dynamics, transNoise, initialDist=None, verbose=True): n = len(hallwayColors) if not initialDist: initialDist = dist.UniformDist(range(n)) worldSM = ssm.StochasticSM(initialDist, makeTransitionModel(dynamics, transNoise, n), makeObservationModel(hallwayColors, obsNoise)) return se.StateEstimator(worldSM, verbose)
def makeRobotNavModel(ideal, xMin, xMax, numStates, numObservations): #! startDistribution = None # redefine this """ Create a model of a robot navigating in a 1 dimensional world with a single sonar. @param ideal: list of ideal sonar readings @param xMin: minimum x coordinate for center of robot @param xMax: maximum x coordinate for center of robot @param numStates: number of discrete states into which to divide the range of x coordinates @param numObservations: number of discrete observations into which to divide the range of good sonar observations, between 0 and C{goodSonarRange} @returns: an instance of {\tt ssm.StochasticSM} that describes the dynamics of the world """ # make initial distribution over states startDistribution = dist.UniformDist(range(numStates)) ###################################################################### ### Define observation model ###################################################################### # real width of triangle distribution, in meters # obsTriangleWidth = sonarStDev * 3 obsTriangleWidth = .05 obsDiscTriangleWidth = max(2, int(obsTriangleWidth * \ (numObservations / sonarDist.sonarMax))) # Part of distribution common to all observations obsBackground = dist.MixtureDist(dist.UniformDist(range(numObservations)), dist.DeltaDist(numObservations - 1), 0.5) #! def observationModel(ix): # ix is a discrete location of the robot # return a distribution over observations in that state #! pass return dist.MixtureDist( dist.triangleDist(ideal[ix], obsDiscTriangleWidth, 0, numObservations), obsBackground, 0.9) ###################################################################### ### Define transition model ###################################################################### # real width of triangle distribution, in meters transTriangleWidth = odoStDev * 3 transDiscTriangleWidth = max( 2, int(transTriangleWidth * (numStates / (xMax - xMin)))) transDiscTriangleWidth = 2 teleportProb = 0 #! def transitionModel(a): # a is a discrete action # returns a conditional probability distribution on the next state # given the previous state #! pass def transitionGivenState(s): # A uniform distribution we mix in to handle teleportation transUniform = dist.UniformDist(range(numStates)) return dist.MixtureDist(dist.triangleDist(\ util.clip(s+a, 0, numStates-1), transDiscTriangleWidth, 0, numStates-1), transUniform, 1 - teleportProb) return transitionGivenState ###################################################################### ### Create and return SSM ###################################################################### #! return ssm.StochasticSM(startDistribution, transitionModel, observationModel)
else: # occ return dist.DDist({'hit': 1 - falseNeg, 'free': falseNeg}) #! # Transition model: P(newState | s | a) def uGivenAS(a): #! pass return lambda s: dist.DDist({s: 1.0}) #! #!cellSSM = None # Your code here cellSSM = ssm.StochasticSM( dist.DDist({ 'occ': initPOcc, 'empty': 1 - initPOcc }), uGivenAS, oGivenS) #! class BayesGridMap(dynamicGridMap.DynamicGridMap): def squareColor(self, (xIndex, yIndex)): p = self.occProb((xIndex, yIndex)) if self.robotCanOccupy((xIndex, yIndex)): return colors.probToMapColor(p, colors.greenHue) elif self.occupied((xIndex, yIndex)): return 'black' else: return 'red'