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
# -*- coding: utf-8 -*- | |
import gym | |
from gym import wrappers | |
env = gym.make("CartPole-v0") | |
env = wrappers.Monitor(env, './cartpole-experiment-1') | |
for i_episode in range(20): | |
observation = env.reset() | |
for t in range(100): |
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
# -*- coding: utf-8 -*- | |
# ref: https://gym.openai.com/evaluations/eval_1lfzNKEHS9GA7nNWE73w | |
import numpy as np | |
import gym | |
from gym import wrappers | |
# Q learning params | |
ALPHA = 0.1 # learning rate | |
GAMMA = 0.99 # reward discount |
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
# -*- coding: utf-8 -*- | |
# ref: http://taotao54321.hatenablog.com/entry/2016/11/08/180245 | |
import numpy as np | |
import gym | |
from gym import wrappers | |
# Q learning params | |
ALPHA = 0.1 # learning rate | |
GAMMA = 0.99 # reward discount |
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
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """ | |
import numpy as np | |
import pickle | |
import gym | |
# hyperparameters | |
H = 200 # number of hidden layer neurons | |
batch_size = 10 # every how many episodes to do a param update? | |
learning_rate = 1e-4 | |
gamma = 0.99 # discount factor for reward |
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
'''This script demonstrates how to build a variational autoencoder with Keras. | |
Reference: "Auto-Encoding Variational Bayes" https://arxiv.org/abs/1312.6114 | |
''' | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.stats import norm | |
from keras.layers import Input, Dense, Lambda, Layer | |
from keras.models import Model | |
from keras import backend as K |
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 | |
import torch | |
import torch.nn as nn | |
from torch.autograd import Variable | |
from torch import optim | |
import torch.nn.functional as F | |
seq_len = 10 | |
n_class = 5 | |
class SimpleNet(nn.Module): |
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
# https://stackoverflow.com/questions/7851077/how-to-return-index-of-a-sorted-list | |
s = [2, 3, 1, 4, 5] | |
sorted(range(len(s)), key=lambda k: s[k]) | |
# [2, 0, 1, 3, 4] | |
sorted(range(len(s)), key=lambda k: s[k], reverse=True) | |
# [4, 3, 1, 0, 2] | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
%load_ext autoreload | |
%autoreload 2 |
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
# https://discuss.pytorch.org/t/how-pytorch-releases-variable-garbage/7277/2 | |
def memReport(): | |
for obj in gc.get_objects(): | |
if torch.is_tensor(obj) or (hasattr(obj, 'data') and torch.is_tensor(obj.data)): | |
print(type(obj), obj.size()) | |
def cpuStats(): | |
print(sys.version) | |
print(psutil.cpu_percent()) | |
print(psutil.virtual_memory()) # physical memory usage |
OlderNewer