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
# Crossing over the Primary Agents | |
def crossover_pagent(agents): | |
offspring = [] | |
for _ in range(int((self.population - len(agents)) / 2)): | |
parent1 = random.choice(agents) | |
parent2 = random.choice(agents) | |
child1 = PAgent(self.in_str_len) | |
child2 = PAgent(self.in_str_len) | |
split = random.randint(0, self.in_str_len) | |
child1.string = parent1.string[0:split] + parent2.string[split:self.in_str_len] |
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
'use strict'; | |
// Requiring the Dynamoose NPM package | |
var dynamoose = require('dynamoose'); | |
// To configure Dynamose you can either: | |
/* | |
Set environment variables | |
export AWS_ACCESS_KEY_ID="Your AWS Access Key ID" |
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
'use strict'; | |
// Requiring the Dynamoose NPM package | |
var dynamoose = require('dynamoose'); | |
// Setting our table name prefix to "example-" | |
dynamoose.setDefaults({ | |
prefix: 'example-', | |
suffix: '' | |
}); |
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
backend: TkAgg |
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 PIL import Image | |
import numpy as np | |
gray_images_train = [] | |
# `train_images` is an array containing the image file paths | |
for img in train_images: | |
img = Image.open(img) | |
gray = img.convert('L') | |
gray_images_train.append(gray) |
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 cirq | |
# Build a model using Circuits | |
circuit = cirq.Circuit() | |
# Create Qubits | |
(q0, q1) = cirq.LineQubit.range(2) | |
# Add Qubits to Circuit model using logic gates | |
circuit.append([cirq.H(q0), cirq.CNOT(q0, q1)]) |
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 pandas as pd | |
import numpy | |
import random | |
actions = ['up', 'down', 'left', 'right'] | |
states = ['start', 'mousetrap', 'empty', 'cheese', 'end'] | |
n_actions = len(actions) | |
n_states = len(states) | |
q_table = pd.DataFrame(np.zeros([n_states, n_actions]), columns=actions) |
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
discount_factor_gamma = 0.9 | |
num_episodes = 1000 | |
learning_rate_alpha = 0.8 | |
epsilon_threshold = 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
rewards_lookup = { | |
'empty': -1, | |
'cheese': 5, | |
'mousetrap': -10, | |
'start': 0, | |
'end': 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
# The main RL event loop | |
for i in range(num_episodes): | |
S0 = env.reset() # Current state | |
total_reward_for_episode = 0 | |
game_done = False | |
for s in range(steps_per_episode): | |
# Choosing an action to perform in the current state | |
if np.random.rand() > epsilon: | |
action = env.action_space.sample() # Explore with a random action |