For the Localization program I've submitted the code below
When I run the code I get the following result
[[0.011059807427972012, 0.02464041578496803, 0.06799662806785915, 0.04472487045812158, 0.02465153121665372], [0.0071532041833209815, 0.010171326481705892, 0.08696596002664689, 0.07988429965998084, 0.009350668508437186], [0.007397366886111671, 0.008943730670452702, 0.11272964670259776, 0.3535072295521272, 0.040655492078276775], [0.009106505805646497, 0.0071532041833209815, 0.014349221618346574, 0.04313329135844895, 0.036425599329004736]]
I would like to know why is hat been marked 'incorrect'
Thx
(Here is the code copied from the Udacity-Window)
colors = [['red', 'green', 'green', 'red' , 'red'],
['red', 'red', 'green', 'red', 'red'],
['red', 'red', 'green', 'green', 'red'],
['red', 'red', 'red', 'red', 'red']]
measurements = ['green', 'green', 'green' ,'green', 'green']
motions = [[0,0],[0,1],[1,0],[1,0],[0,1]]
sensor_right = 0.7
p_move = 0.8
def show(p):
for i in range(len(p)):
print p[i]
#DO NOT USE IMPORT
#ENTER CODE BELOW HERE
#ANY CODE ABOVE WILL CAUSE
#HOMEWORK TO BE GRADED
#INCORRECT
print('Unit1: Assignment')
#Global variables
worldColor = [[ 'Green', 'Green', 'Green' ],
[ 'Green', 'Red', 'Red' ],
[ 'Green', 'Green', 'Green' ]]
worldColorSize = 3, 3
uniformedProbabilityDistribution = [[ .2, .2, .2, .2, .2],
[ .2, .2, .2, .2, .2],
[ .2, .2, .2, .2, .2],
[ .2, .2, .2, .2, .2]]
botMovement = ['Idle', 'Left', 'Right', 'Up', 'Down']
botMotions = [ [ 0, 0], [ 0, -1], [ 0, 1], [ -1, 0], [ 1, 0] ]
sensorAccuracy = 1.0
botMvmtAccuracy = 0.5
def GetTransposedList( aList):
tmp = []
for i in range( len( aList ) ):
tmp.append([ row[ i ] for row in aList ] )
return tmp
def GetZeroList( aList):
tmp = []
for i in range( len( aList ) ):
tmp.append([ 0 for i in aList[i] ] )
return tmp
def Sum2DList( aList ):
sum = 0
for m in range( len(aList ) ):
for n in range( len(aList[m]) ):
sum += aList[m][n]
return sum
def normedSense( aDistribution, measurementValue ):
senseProb = GetZeroList( aDistribution )
for m in range( len(worldColor) ):
for n in range( len(worldColor[m]) ):
hitFlag = ( measurementValue == worldColor[ m ][ n ] )
senseProb[m][n] = aDistribution[ m ][ n ] * ( ( hitFlag * sensorAccuracy ) + ( 1 - hitFlag )*(1.0 - sensorAccuracy) )
localSum = Sum2DList( senseProb )
normedSenseProb = GetZeroList(aDistribution)
for m in range( len(normedSenseProb) ):
for n in range( len(normedSenseProb[m]) ):
normedSenseProb[m][n] = senseProb[m][n] / localSum
return normedSenseProb
def MoveWithMotion( aDistribution, aMotion ):
distr = GetZeroList( aDistribution )
for m in range( len(worldColor) ):
for n in range( len(worldColor[m]) ):
rowMove = ( m - aMotion[ 0 ] ) % len( worldColor )
columnMove = ( n - aMotion[ 1 ] ) % len( worldColor[ m ] )
distr[m][n] = aDistribution[ rowMove ][ columnMove ] * botMvmtAccuracy + aDistribution[ m ][ n ] * ( 1.0 - botMvmtAccuracy )
return distr
#Run code
worldColor = colors
sensorAccuracy = sensor_right
botMvmtAccuracy = p_move
botSense = measurements
botMoves = motions
aDistr = uniformedProbabilityDistribution
for i in range( len(botSense ) ):
aDistr = normedSense( MoveWithMotion( aDistr, botMoves[ i ] ), botSense[ i ] )
print(aDistr )
#Your probability array must be printed
#with the following code.
#show(p)
Please go back and edit your comment. Select your code, then select that 101 010 icon to display the code as code. Then we will be able to read it.