Skip to content

Instantly share code, notes, and snippets.

View alexmlamb's full-sized avatar

Alex Lamb alexmlamb

  • Universite de Montreal. Amazon Machine Learning
  • Seattle
View GitHub Profile
@alexmlamb
alexmlamb / gist:74761f3ea158eddf86579a7ceadf4546
Created January 30, 2023 16:09
Pulling Block Environment Plans (Dijkstra's Algorithm)
Goal:
Agent:(0,0). Block:(4,4)
x . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . b .
. . . . . .
State at step 0:
Agent:(3,0). Block:(1,3)
@alexmlamb
alexmlamb / gist:9c76249429c90dfe309b31ce8e6e5c8b
Created January 30, 2023 16:06
Push Block Environment Plans (Dijkstra)
Goal:
Agent:(4,3). Block:(1,3)
. . . . .
. . . . .
. . . . .
. b . . x
. . . . .
State at step 0:
Agent:(3,2). Block:(0,1)
. . . . .
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:
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:
import numpy as np
import torch
import random
from torch.autograd import Variable, grad
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
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
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]
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
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)
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)