def main_handler(ctx): """ :param ctx: Dict ctx is the context object containing message data, the user who owns the bot instance, and :return: The bot's return value will be POSTed to its specified webhook address, if one is provided. """ # First create an instance of the API interface api = MC(ctx) # Replace 'pass' with your code. # Try uncommenting the line(s) below to send an email to yourself with the original message. # api.send_email(ctx['user']['email'], "Original message:\n" + str(ctx['message']), # subject='Hello from Machine Colony!') pass
import gym import matplotlib.pyplot as plt import numpy as np from mc import FiniteMCModel as MC env = gym.make("CliffWalking-v0") # WARNING: If you try to set eps to a very low value, # And you attempt to get the m.score() of m.pi, there may not # be guarranteed convergence. eps = 10000 S = 4*12 A = 4 START_EPS = 0.7 m = MC(S, A, epsilon=START_EPS) for i in range(1, eps+1): ep = [] observation = env.reset() while True: # Choosing behavior policy action = m.choose_action(m.b, observation) # Run simulation next_observation, reward, done, _ = env.step(action) ep.append((observation, action, reward)) observation = next_observation if done: break m.update_Q(ep) # Decaying epsilon, reach optimal policy
import gym env = gym.make("Blackjack-v0") # The typical imports import gym import numpy as np import matplotlib.pyplot as plt from mc import FiniteMCModel as MC eps = 1000000 S = [(x, y, z) for x in range(4,22) for y in range(1,11) for z in [True,False]] A = 2 m = MC(S, A, epsilon=1) for i in range(1, eps+1): ep = [] observation = env.reset() while True: # Choosing behavior policy action = m.choose_action(m.b, observation) # Run simulation next_observation, reward, done, _ = env.step(action) ep.append((observation, action, reward)) observation = next_observation if done: break m.update_Q(ep) # Decaying epsilon, reach optimal policy m.epsilon = max((eps-i)/eps, 0.1)
import json import os import re OBJECTS_PATH = "./dets/objects/" RECOG_PATH = "./dets/recogobj/" FRAME_MDATA_PATH = "./dets/" if len(sys.argv) < 6: print "no db arg" print "legacy.py <db server url> <db server port> <username> <password>" exit(1) mc = MC({'serverUrl': sys.argv[1], 'port': int(sys.argv[2]), 'userName': sys.argv[3], 'password': sys.argv[4], 'dbName': sys.argv[5]}) # upload objects (facetraces) print "uploading objects (facetraces)" object_files = os.listdir(OBJECTS_PATH) total_obj_files = len(object_files) processed_obj_files = 0 for obj_file in object_files: print "processing file {0}".format(obj_file) obj_json = open(OBJECTS_PATH + obj_file).read() obj_data = json.loads(obj_json) mc.addFaceTrace(obj_data) processed_obj_files = processed_obj_files + 1 print "uploaded facetrace {0} of {1}".format(processed_obj_files, total_obj_files)
def __init__(self, symbole = 'O', num_tirages_MC = 3, num_descentes_dans_arbre = 7, facteur_uct = 0.0): '''Créer un joueur du symbole indiqué''' MC.__init__(self, symbole, num_tirages_MC) self.num_descentes_dans_arbre = num_descentes_dans_arbre self.facteur_uct = facteur_uct