Skip to content

Instantly share code, notes, and snippets.

View rish-16's full-sized avatar
🤖
backpropagating through memories

Rishabh Anand rish-16

🤖
backpropagating through memories
View GitHub Profile
# 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]
'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"
'use strict';
// Requiring the Dynamoose NPM package
var dynamoose = require('dynamoose');
// Setting our table name prefix to "example-"
dynamoose.setDefaults({
prefix: 'example-',
suffix: ''
});
@rish-16
rish-16 / matplotlibrc
Created January 1, 2019 06:28
Solving plotting problem on installation of OpenAI's Spinning Up
backend: TkAgg
@rish-16
rish-16 / convert.py
Last active February 10, 2019 16:01
Converting coloured images to black and white images
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)
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)])
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)
discount_factor_gamma = 0.9
num_episodes = 1000
learning_rate_alpha = 0.8
epsilon_threshold = 1.0
rewards_lookup = {
'empty': -1,
'cheese': 5,
'mousetrap': -10,
'start': 0,
'end': 0
}
# 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