Module coloredHall
[frames] | no frames]

Module coloredHall

State estimation example: localization in a colored hallway

Classes
  TextInputSM
Machine that prompts a user for an input on each step.
Functions
 
makeObservationModel(hallwayColors, obsNoise)
Returns: conditional distribution specifying probability of observing a color given the robot's location
 
perfectObsNoiseModel(actualColor)
Returns: DDist over observed colors when in a room that has actualColor.
 
noisyObsNoiseModel(actualColor)
Returns: DDist over observed colors when in a room that has actualColor.
 
makeTransitionModel(dynamics, noiseDist, hallwayLength)
Returns: P(actualResultingLoc | previousLoc, action) represented as a function that takes an action and returns a function that takes a previous location and returns a distribution over actual resulting locations.
 
standardDynamics(loc, act, hallwayLength)
Returns: new loc of the robot assuming perfect execution.
 
ringDynamics(loc, act, hallwayLength)
Returns: new loc of the robot, assuming perfect execution where the hallway is actually a ring (so that location 0 is next to location hallwayLength -1).
 
perfectTransNoiseModel(nominalLoc, hallwayLength)
Returns: distribution over resulting locations, modeling noisy execution of commands; in this case, the robot goes to the nominal location with probability 1.0
 
noisyTransNoiseModel(nominalLoc, hallwayLength)
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.
 
leftSlipTransNoiseModel(nominalLoc, hallwayLength)
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.
 
textOutput(result)
 
wrapTextUI(m)
Returns: A composite machine that prompts the user for input to, and prints the output of m on each step.
 
wrapWindowUI(m, worldColors, legalInputs, windowName='Belief', initBelief=None)
Returns: A composite machine that prompts the user for input to, and graphically displays the output of m on each step.
 
drawBelief(belief, window, numStates, drawNums=True)
 
makeSESwithGUI(worldSM, realColors, legalInputs, initBelief=None, verbose=False, title='hallway')
Makes a colored hallway simulator and state estimator.
 
makeSim(hallwayColors, legalInputs, obsNoise, dynamics, transNoise, title='sim', initialDist=None)
Make an instance of the simulator with noisy motion and sensing models.
 
hallSE(hallwayColors, legalInputs, obsNoise, dynamics, transNoise, initialDist=None, verbose=True)
Variables
  possibleColors = ('black', 'white', 'red', 'green', 'blue', 'p...
Possible colors for rooms in our hallway
  standardHallway = ['white', 'white', 'green', 'white', 'white']
Our favorite configuration of hallway colors
  __package__ = None
Function Details

makeObservationModel(hallwayColors, obsNoise)

 
Parameters:
  • hallwayColors - list of colors, one for each room in the hallway, from left to right
  • obsNoise - conditional distribution specifying the probability of observing a color given the actual color of the room
Returns:
conditional distribution specifying probability of observing a color given the robot's location

Remember that a conditional distribution P(A | B) is represented as a function from values of b to distributions over A.

perfectObsNoiseModel(actualColor)

 
Parameters:
  • actualColor - actual color in a location
Returns:
DDist over observed colors when in a room that has actualColor. In this case, we observe the actual color with probability 1.

noisyObsNoiseModel(actualColor)

 
Parameters:
  • actualColor - actual color in a location
Returns:
DDist over observed colors when in a room that has actualColor. In this case, we observe the actual color with probability 0.8, and the remaining 0.2 probability is divided uniformly over the other possible colors in this world.

makeTransitionModel(dynamics, noiseDist, hallwayLength)

 
Parameters:
  • dynamics - function that takes the robot's current location, action, and hallwaylength, and returns its nominal new location
  • noiseDist - P(actualResultingLocation | nominalResultingLoc) represented as a function from ideal location to the actual location the robot will end up in
  • hallwayLength - number of rooms in the hallway
Returns:
P(actualResultingLoc | previousLoc, action) represented as a function that takes an action and returns a function that takes a previous location and returns a distribution over actual resulting locations.

standardDynamics(loc, act, hallwayLength)

 
Parameters:
  • loc - current loc (integer index) of the robot
  • act - a positive or negative integer (or 0) indicating the nominal number of squares moved
  • hallwayLength - number of cells in the hallway
Returns:
new loc of the robot assuming perfect execution. If the action would take it out of bounds, the robot stays where it is.

ringDynamics(loc, act, hallwayLength)

 
Parameters:
  • loc - current loc (integer index) of the robot
  • act - positive or negative integer offset
  • hallwayLength - number of cells in the hallway
Returns:
new loc of the robot, assuming perfect execution where the hallway is actually a ring (so that location 0 is next to location hallwayLength -1).

perfectTransNoiseModel(nominalLoc, hallwayLength)

 
Parameters:
  • nominalLoc - location that the robot would have ended up given perfect dynamics
  • 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 1.0

noisyTransNoiseModel(nominalLoc, hallwayLength)

 
Parameters:
  • nominalLoc - location that the robot would have ended up given perfect dynamics
  • 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 hallwayLength-1).

leftSlipTransNoiseModel(nominalLoc, hallwayLength)

 
Parameters:
  • nominalLoc - location that the robot would have ended up given perfect dynamics
  • 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 nominalLoc.

wrapTextUI(m)

 
Parameters:
  • m - An instance of sm.SM
Returns:
A composite machine that prompts the user for input to, and prints the output of m on each step.

wrapWindowUI(m, worldColors, legalInputs, windowName='Belief', initBelief=None)

 
Parameters:
  • m - A machine created by applying se.makeStateEstimationSimulation to a hallway world, which take movement commands as input and generates as output structures of the form (b, (o, a)), where b is a belief state, a is the action command, and o is the observable output generated by the world.
  • worldColors - A list of the colors of the rooms in the hallway, from left to right.
Returns:
A composite machine that prompts the user for input to, and graphically displays the output of m on each step.

makeSESwithGUI(worldSM, realColors, legalInputs, initBelief=None, verbose=False, title='hallway')

 

Makes a colored hallway simulator and state estimator. Text input for actions and graphical display of world and belief state.

Parameters:
  • worldSM - instance of ssm.StochasticSM representing the world
  • realColors - A list of the colors of the rooms in the hallway, from left to right.
  • legalInputs - A list of the possible action commands
  • verbose - if True then print out belief state after each update
  • title - title of window being created

makeSim(hallwayColors, legalInputs, obsNoise, dynamics, transNoise, title='sim', initialDist=None)

 

Make an instance of the simulator with noisy motion and sensing models.

Parameters:
  • hallwayColors - A list of the colors of the rooms in the hallway, from left to right.
  • legalInputs - A list of the possible action commands
  • obsNoise - conditional distribution specifying the probability of observing a color given the actual color of the room
  • dynamics - function that takes the robot's current location, action, and hallwaylength, and returns its nominal new location
  • transNoise - P(actualResultingLocation | nominalResultingLoc) represented as a function from ideal location to the actual location the robot will end up in
  • title - String specifying title for simulator window

Variables Details

possibleColors

Possible colors for rooms in our hallway

Value:
('black',
 'white',
 'red',
 'green',
 'blue',
 'purple',
 'orange',
 'darkGreen',
...