Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.gridspec as gridspec | |
import itertools | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.svm import SVC | |
from sklearn.ensemble import RandomForestClassifier | |
from mlxtend.classifier import EnsembleVoteClassifier | |
from mlxtend.data import iris_data | |
from mlxtend.plotting import plot_decision_regions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def best_route(starting_location, intermediary_location, ending_location): | |
return route(starting_location, intermediary_location) + route(intermediary_location, ending_location)[1:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def route(starting_location, ending_location): | |
R_new = np.copy(R) | |
ending_state = location_to_state[ending_location] | |
R_new[ending_state, ending_state] = 1000 | |
Q = np.array(np.zeros([12,12])) | |
for i in range(1000): | |
current_state = np.random.randint(0,12) | |
playable_actions = [] | |
for j in range(12): | |
if R_new[current_state, j] > 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R = np.array([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], | |
[0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], | |
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], | |
[0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0], | |
[0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1], | |
[0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0], | |
[0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Making a mapping from the states to the locations | |
state_to_location = {state: location for location, | |
state in location_to_state.items()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1000): | |
current_state = np.random.randint(0,12) | |
playable_actions = [] | |
for j in range(12): | |
if R[current_state, j] > 0: | |
playable_actions.append(j) | |
next_state = np.random.choice(playable_actions) | |
TD = R[current_state, next_state] + gamma*Q[next_state, np.argmax(Q[next_state,])] | |
- Q[current_state, next_state] | |
Q[current_state, next_state] = Q[current_state, next_state] + alpha*TD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
R = np.array([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], | |
[0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], | |
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], | |
[0, 0, 1, 0, 0, 0, 1000, 1, 0, 0, 0, 0], | |
[0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location_to_state = {'A': 0, | |
'B': 1, | |
'C': 2, | |
'D': 3, | |
'E': 4, | |
'F': 5, | |
'G': 6, | |
'H': 7, | |
'I': 8, | |
'J': 9, |
NewerOlder