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
Goal: | |
Agent:(0,0). Block:(4,4) | |
x . . . . . | |
. . . . . . | |
. . . . . . | |
. . . . . . | |
. . . . b . | |
. . . . . . | |
State at step 0: | |
Agent:(3,0). Block:(1,3) |
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
Goal: | |
Agent:(4,3). Block:(1,3) | |
. . . . . | |
. . . . . | |
. . . . . | |
. b . . x | |
. . . . . | |
State at step 0: | |
Agent:(3,2). Block:(0,1) | |
. . . . . |
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
grtr_txt = 'Alex Lamb is here. ' | |
pred_txt = 'Alex Lamb is here. ' | |
def counts(string, size=3): | |
d = {} | |
for i in range(0,len(string)-size+1): | |
sub = tuple(string[i:i+size]) | |
if not sub in d: |
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
gt_txt = 'Iamalexlambfirstnamealex' | |
pred_txt = 'Iamalexlambfir..stnamealex' | |
def counts(string, size=3): | |
d = {} | |
for i in range(0,len(string)-size+1): | |
sub = string[i:i+size] | |
if not sub in d: |
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 numpy as np | |
import torch | |
import random | |
from torch.autograd import Variable, grad | |
import matplotlib | |
matplotlib.use('Agg') | |
import matplotlib.pyplot as plt |
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 random | |
def rollout(T): | |
s = 0 | |
bought = 0 | |
sold = 0 | |
for i in range(T): | |
if random.uniform(0,1) < 0.5: | |
s += 1 |
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 gaussian_likelihood(mu, sigma, t): | |
l = 0.5 * ((t - mu)/sigma)**2 + torch.log(sigma) | |
return l | |
assert(state.shape[0] == action.shape[0]) | |
assert(state.shape[0] == target_Q.shape[0]) | |
ind = torch.randperm(state.shape[0]) | |
state_rs = state[ind] | |
action_rs = action[ind] | |
target_Q_rs = target_Q[ind] |
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
assert(state.shape[0] == action.shape[0]) | |
assert(state.shape[0] == target_Q.shape[0]) | |
ind = torch.randperm(state.shape[0]) | |
state_rs = state[ind] | |
action_rs = action[ind] | |
target_Q_rs = target_Q[ind] | |
def make_critic_loss(s,a,t): | |
current_Q1, current_Q2 = self.critic(s, a) | |
return F.mse_loss(current_Q1, t) + F.mse_loss(current_Q2, t) | |
alpha = 0.1 |
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 matplotlib | |
matplotlib.use('Agg') | |
from matplotlib import pyplot as plt | |
from torch.utils.data import TensorDataset, DataLoader | |
from tqdm import tqdm_notebook as tqdm | |
import numpy as np | |
import torch | |
import random | |
torch.manual_seed(52) |
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 torch | |
from torchvision.utils import save_image | |
from torch.nn.modules.upsampling import Upsample | |
m = Upsample(scale_factor=84//4, mode='nearest') | |
''' | |
Image is: (bs, 3, 84, 84) |
NewerOlder