Finish project 5 and class.
This commit is contained in:
parent
17ff044b6d
commit
76a519cfa9
26
p5_classification/.vscode/launch.json
vendored
Normal file
26
p5_classification/.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "run_file",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal"
|
||||
},
|
||||
{
|
||||
"name": "features",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/dataClassifier.py",
|
||||
"args" : ["-d", "pacman", "-c", "perceptron", "-f", "-g", "ContestAgent", "-t", "1000", "-s", "1000"]
|
||||
},
|
||||
{
|
||||
"name": "autograder",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/autograder.py",
|
||||
"args" : []
|
||||
}
|
||||
]
|
||||
}
|
3
p5_classification/.vscode/settings.json
vendored
Normal file
3
p5_classification/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.pythonPath": "/usr/bin/python2"
|
||||
}
|
@ -144,6 +144,7 @@ def basicFeatureExtractorPacman(state):
|
||||
features[action] = featureCounter
|
||||
return features, state.getLegalActions()
|
||||
|
||||
|
||||
def enhancedFeatureExtractorPacman(state):
|
||||
"""
|
||||
Your feature extraction playground.
|
||||
@ -159,14 +160,30 @@ def enhancedFeatureExtractorPacman(state):
|
||||
features[action] = util.Counter(features[action], **enhancedPacmanFeatures(state, action))
|
||||
return features, state.getLegalActions()
|
||||
|
||||
|
||||
def enhancedPacmanFeatures(state, action):
|
||||
"""
|
||||
For each state, this function is called with each legal action.
|
||||
It should return a counter with { <feature name> : <feature value>, ... }
|
||||
"""
|
||||
features = util.Counter()
|
||||
"*** YOUR CODE HERE ***"
|
||||
util.raiseNotDefined()
|
||||
ghostDists = []
|
||||
state = state.generateSuccessor(0, action)
|
||||
pacmanPosition = state.getPacmanPosition()
|
||||
ghostPositions = [ghostState.getPosition() for ghostState in state.getGhostStates()]
|
||||
foodPositions = [foodPos for foodPos in state.getFood().asList()]
|
||||
walls = state.data.layout.walls
|
||||
for x in range(walls.width):
|
||||
for y in range(walls.height):
|
||||
if walls[x][y] is True:
|
||||
# features[("wall", x, y)] = 1
|
||||
pass
|
||||
else:
|
||||
pos = (x, y)
|
||||
features[("wall", x, y)] = 0
|
||||
features[("pacman", x, y)] = 1 if pos == pacmanPosition else 0
|
||||
features[("ghost", x, y)] = 1 if pos in ghostPositions else 0
|
||||
features[("food", x, y)] = 1 if pos in foodPositions else 0
|
||||
return features
|
||||
|
||||
|
||||
@ -208,17 +225,17 @@ def analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)
|
||||
|
||||
# Put any code here...
|
||||
# Example of use:
|
||||
# for i in range(len(guesses)):
|
||||
# prediction = guesses[i]
|
||||
# truth = testLabels[i]
|
||||
# if (prediction != truth):
|
||||
# print "==================================="
|
||||
# print "Mistake on example %d" % i
|
||||
# print "Predicted %d; truth is %d" % (prediction, truth)
|
||||
# print "Image: "
|
||||
# print rawTestData[i]
|
||||
# print whiteAreasFeature(rawTestData[i])
|
||||
# break
|
||||
for i in range(len(guesses)):
|
||||
prediction = guesses[i]
|
||||
truth = testLabels[i]
|
||||
if (prediction != truth):
|
||||
print "==================================="
|
||||
print "Mistake on example %d" % i
|
||||
print "Predicted {}; truth is {}".format(prediction, truth)
|
||||
print "Image: "
|
||||
print rawTestData[i]
|
||||
# print whiteAreasFeature(rawTestData[i])
|
||||
break
|
||||
|
||||
|
||||
## =====================
|
||||
|
Loading…
Reference in New Issue
Block a user