Skip to content

Instantly share code, notes, and snippets.

class TrafficSimulator_1Lane:
def __init__(self, initial_density, length, v_max, p_slow_down, random_v = False):
'''
Initialize the 1 lane traffic simulator object, also keep track of the flow density as a list
Args:
initial_density (float, between 0 and 1): the initial density of cars on the lane
class TrafficSimulator_1Lane:
def __init__(self, initial_density, length, v_max, p_slow_down, random_v = False):
'''
Initialize the 1 lane traffic simulator object, also keep track of the flow density as a list
Args:
initial_density (float, between 0 and 1): the initial density of cars on the lane
@AshNguyen
AshNguyen / vae_torch.py
Created May 9, 2020 10:43
simple VAE pytorch
class VAE(nn.Module):
def __init__(self, n_latent):
super(VAE, self).__init__()
self.fc1 = nn.Linear(784, 400)
self.fc21 = nn.Linear(400, n_latent)
self.fc22 = nn.Linear(400, n_latent)
self.fc3 = nn.Linear(n_latent, 400)
self.fc4 = nn.Linear(400, 784)
@AshNguyen
AshNguyen / simple_ae.py
Created May 9, 2020 10:40
Simple AE in pytorch
class AE(nn.Module):
def __init__(self, n_latent):
super(AE, self).__init__()
self.encoder = nn.Sequential(
nn.Linear(28 * 28, 128),
nn.ReLU(True),
nn.Linear(128, 64),
nn.ReLU(True),
nn.Linear(64, n_latent))
self.decoder = nn.Sequential(
def average_prob(p1, p2, p3):
'''
Takes three different probability vectors in and outputs a randomly
sampled action from n_action with probability equals the average \
probability of the input vectors
'''
a = range(n_action)
p = (p1 + p2 + p3)/3
a = np.random.choice(a=a, p=p)
return a
@AshNguyen
AshNguyen / erl_avr.py
Created April 20, 2020 10:32
ERL Average prob
def average_prob(p1, p2, p3):
'''
Takes three different probability vectors in and outputs a randomly
sampled action from n_action with probability equals the average \
probability of the input vectors
'''
a = range(n_action)
p = (p1 + p2 + p3)/3
a = np.random.choice(a=a, p=p)
return a
@AshNguyen
AshNguyen / erl_m.py
Created April 20, 2020 10:31
ERL_majority
def majority_vote(p1, p2, p3):
'''
Takes three different probability vectors in and outputs a randomly
sampled action from n_action according to majority voting scheme
'''
a = range(n_action)
a1 = np.random.choice(a=a, p=p1)
a2 = np.random.choice(a=a, p=p2)
a3 = np.random.choice(a=a, p=p3)
l = [a1, a2, a3]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.