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
from wolf_goat_cabbage_qlearning import WolfGoatCabbageQLearning | |
def main(): | |
wcg_arena = WolfGoatCabbageQLearning( | |
start_state=[['🥦', '🐐', '⛵', '🐺'], [], []], | |
goal_state=[[], [], ['⛵', '🐐', '🥦', '🐺']], | |
gamma=0.8, | |
max_episodes=1000, | |
epsilon_greedy=True) |
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
class RLKey: | |
def __init__(self, k1, k2): | |
self.k1 = k1 | |
self.k2 = k2 | |
def __hash__(self): | |
return hash((tuple(frozenset(x) for x in self.k1), | |
tuple(frozenset(x) for x in self.k2))) | |
def __eq__(self, other): |
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 train(self): | |
convergence_count = 0 | |
q_s_a = defaultdict(int) | |
q_s_a_prec = copy.deepcopy(q_s_a) | |
episode = 1 | |
scores = [] | |
eps_list = [] | |
rewards = {} | |
for episode in range(1,self.max_episodes): |
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 move(self, state, what, where_from, where_to): | |
state[where_from].remove(what) | |
state[where_to].add(what) | |
def get_next_state(self, starting_state, action): | |
next_state = copy.deepcopy(starting_state) | |
if action == 'MOVE_PLAYER_FROM_LEFT_TO_BOAT': | |
if '⛵' in next_state[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
class WolfGoatCabbageQLearning: | |
def __init__(self, start_state, goal_state, gamma=0.8, max_episodes=50000, | |
epsilon_greedy=True, min_epsilon=0.1, max_epsilon=1.0): | |
self.start_state = tuple(set(x) for x in start_state) | |
self.goal_state = tuple(set(x) for x in goal_state) | |
self.gamma = gamma | |
self.max_episodes = max_episodes |
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 get_reward(self, state): | |
# GOAT and WOLF cannot be left unsupervised together | |
# GOAT and CABBAGE cannot be left unsupervised together | |
if state[2] == self.goal_state[2]: | |
return 100 | |
if {'🐐', '🐺'} <= state[0] and '⛵' not in state[0]: | |
return -100 | |
if {'🐐', '🥦'} <= state[0] and '⛵' not in state[0]: | |
return -100 | |
if {'🐐', '🐺'} <= state[2] and '⛵' not in state[2]: |
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
""" | |
Have yourself a merry coding Christmas... | |
""" | |
from num2words import num2words | |
def sing(): | |
things_my_true_love_gave_to_me = [ | |
(1, 'partridge in a pear tree'), | |
(2, 'turtle doves'), |
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
Leap.loop(controllerOptions, function(frame) { | |
// Body of callback function | |
var result = ""; | |
var extendedFingers = 0; | |
if (frame.hands.length > 0) { | |
var hand = frame.hands[0]; | |
for(var f = 0; f < hand.fingers.length; f++){ | |
var finger = hand.fingers[f]; | |
if (finger.extended) extendedFingers++; | |
} |
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
<html> | |
<head> | |
<title>Leap Test</title> | |
<style type="text/css"> | |
#out { | |
font-size: 60px; | |
} | |
</style> | |
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
using System; | |
using Xamarin.Forms; | |
namespace MagicBall | |
{ | |
public partial class MainPage : ContentPage | |
{ | |
readonly Prediction prediction = new Prediction(); | |
public MainPage() | |
{ |
NewerOlder