Finish project 5 and class.
This commit is contained in:
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
|
features[action] = featureCounter
|
||||||
return features, state.getLegalActions()
|
return features, state.getLegalActions()
|
||||||
|
|
||||||
|
|
||||||
def enhancedFeatureExtractorPacman(state):
|
def enhancedFeatureExtractorPacman(state):
|
||||||
"""
|
"""
|
||||||
Your feature extraction playground.
|
Your feature extraction playground.
|
||||||
@@ -159,14 +160,30 @@ def enhancedFeatureExtractorPacman(state):
|
|||||||
features[action] = util.Counter(features[action], **enhancedPacmanFeatures(state, action))
|
features[action] = util.Counter(features[action], **enhancedPacmanFeatures(state, action))
|
||||||
return features, state.getLegalActions()
|
return features, state.getLegalActions()
|
||||||
|
|
||||||
|
|
||||||
def enhancedPacmanFeatures(state, action):
|
def enhancedPacmanFeatures(state, action):
|
||||||
"""
|
"""
|
||||||
For each state, this function is called with each legal action.
|
For each state, this function is called with each legal action.
|
||||||
It should return a counter with { <feature name> : <feature value>, ... }
|
It should return a counter with { <feature name> : <feature value>, ... }
|
||||||
"""
|
"""
|
||||||
features = util.Counter()
|
features = util.Counter()
|
||||||
"*** YOUR CODE HERE ***"
|
ghostDists = []
|
||||||
util.raiseNotDefined()
|
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
|
return features
|
||||||
|
|
||||||
|
|
||||||
@@ -208,17 +225,17 @@ def analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)
|
|||||||
|
|
||||||
# Put any code here...
|
# Put any code here...
|
||||||
# Example of use:
|
# Example of use:
|
||||||
# for i in range(len(guesses)):
|
for i in range(len(guesses)):
|
||||||
# prediction = guesses[i]
|
prediction = guesses[i]
|
||||||
# truth = testLabels[i]
|
truth = testLabels[i]
|
||||||
# if (prediction != truth):
|
if (prediction != truth):
|
||||||
# print "==================================="
|
print "==================================="
|
||||||
# print "Mistake on example %d" % i
|
print "Mistake on example %d" % i
|
||||||
# print "Predicted %d; truth is %d" % (prediction, truth)
|
print "Predicted {}; truth is {}".format(prediction, truth)
|
||||||
# print "Image: "
|
print "Image: "
|
||||||
# print rawTestData[i]
|
print rawTestData[i]
|
||||||
# print whiteAreasFeature(rawTestData[i])
|
# print whiteAreasFeature(rawTestData[i])
|
||||||
# break
|
break
|
||||||
|
|
||||||
|
|
||||||
## =====================
|
## =====================
|
||||||
|
|||||||
Reference in New Issue
Block a user