This file contains hidden or 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
| rm -rf lambda_deployment | |
| mkdir - p lambda_deployment/var/task/models | |
| cp requirements.txt lambda_deployment/requirements.txt | |
| cp lambda_dockerfile lambda_deployment/Dockerfile | |
| aws_account_id=$AWS_ACCOUNT | |
| aws_region="us-east-1" | |
| # Store model |
This file contains hidden or 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 public.ecr.aws/lambda/python:3.8 | |
| ADD . / | |
| WORKDIR / | |
| ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID | |
| ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY | |
| ENV AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN | |
| RUN pip install -r requirements.txt | |
| CMD ["handler.handler"] |
This file contains hidden or 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 requests | |
| import json | |
| url = "http://localhost:9000/2015-03-31/functions/function/invocations" | |
| headers = {'Content-type': 'application/json'} | |
| q = requests.post(url, headers = headers, | |
| data = json.dumps({"body": json.dumps({"image":grayscale_array.tolist(), 'source':'payload_array', 'preprocessing_type':'bw'})})) | |
This file contains hidden or 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 environment: | |
| def __init__(self, probabilities): | |
| """ | |
| Arguments: | |
| probabilities: `list` or `np.array` with the probabilities of success of each action. | |
| """ | |
| self.probabilities = probabilities | |
| def step(self, action): | |
| """ | |
| Environment step returning the reward of each action |
This file contains hidden or 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
| env = environment([0.5, 0.75, 0.25]) | |
| n_steps = 10000 | |
| print("Average reward:\naction 0:{}\naction 1:{}\naction 2:{}\n".format( | |
| np.mean([env.step(0) for i in range(n_steps)]), | |
| np.mean([env.step(1) for i in range(n_steps)]), | |
| np.mean([env.step(2) for i in range(n_steps)]) | |
| )) | |
This file contains hidden or 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 argmax(q_values): | |
| """ | |
| Takes in a list of q_values and returns the index | |
| of the item with the highest value. Breaks ties randomly. | |
| returns: int - the index of the highest value in q_values | |
| """ | |
| top = float("-inf") | |
| ties = [] | |
| for i in range(len(q_values)): |
This file contains hidden or 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
| num_runs = 200 # Number of simulations | |
| num_steps = 100000 # Number of visits (timesteps) | |
| probabilities = [0.5, 0.75, 0.25] | |
| epsilon = 0.15 | |
| all_averages = [] | |
| actions = [] | |
| for i in tqdm(range(num_runs)): | |
| env = environment(probabilities) # env initialization | |
| agent = EpsilonGreedyAgent(action_size = 3, epsilon = epsilon) # agent initialization |
This file contains hidden or 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
| epsilons = [0.0, 0.01, 0.1, 0.4, 0.5] | |
| num_runs = 200 | |
| num_steps = 50000 | |
| per_epsilon = {} | |
| per_epsilon_action = {} | |
| for epsilon in epsilons: | |
| all_averages = [] |
This file contains hidden or 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
| num_runs = 200 # Número de veces que repetimos el experimento | |
| num_steps = 50000 # Número de visitas (pasos) por experimento | |
| probabilities = [0.5, 0.75, 0.25] | |
| epsilons = [0.0, 0.01, 0.1, 0.4, 0.5] | |
| per_epsilon_priorkw = {} | |
| for epsilon in epsilons: | |
| all_averages = [] | |
| for i in tqdm(range(num_runs)): |
This file contains hidden or 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
| n_samples = 10000 | |
| # features ------------------------------------------------------- | |
| design = np.random.randint(0,10,n_samples)/10 | |
| consumption = np.random.randint(0,10,n_samples)/10 | |
| reliability = np.random.randint(0,10,n_samples)/10 | |
| innovation = np.random.randint(0,10,n_samples)/10 | |
| price = np.random.randint(0,10,n_samples)/10 | |
| X = np.array([design, consumption, reliability, innovation, price]).transpose() |