Instantly share code, notes, and snippets.

View differential-evolution.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View get_layer_output.py
def get_layer_output(model, layer, x):
layer_output = None
def layer_output_hook(m, i, o):
layer_output = o.clone()
hook = layer.register_forward_hook(layer_output_hook)
_ = model(x) # call forward hook
hook.remove()
return layer_output
View unsort_pytorch.py
x = torch.randn(10)
print(x)
y, ind = torch.sort(x, 0)
print("y", y)
print("ind", ind)
unsorted = y.new(*y.size())
unsorted.scatter_(0, ind, y)
print("unsorted:", unsorted)
print((x - unsorted).abs().max())
View encoder-decoder.py
# coding: utf-8
"""
Seq2Seq (Encoder-Decoder) Model
this model is the basic encoder decoder model without attention mechanism.
author: Keon Kim
"""
import numpy as np
import torch as th
import torch.nn as nn
View topsort.cpp
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
View dqn.py
# -*- coding: utf-8 -*-
import random
import gym
import numpy as np
from collections import deque
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import RMSprop
EPISODES = 5000
View FenwickTree.cpp
class Fenwick{
private:
const int maxN = 10000;
public:
int table[maxN];
int sumQuery(int a, int b){
return sumQuery(b) - sumQuery(a-1);
}
View README.md

Used dueling network architecture with Q-learning, as outlined in this paper:

Dueling Network Architectures for Deep Reinforcement Learning
Ziyu Wang, Tom Schaul, Matteo Hessel, Hado van Hasselt, Marc Lanctot, Nando de Freitas
http://arxiv.org/abs/1511.06581

Command line:

python duel.py CartPole-v0 --gamma 0.995
View setup tensorflow on aws
#!/bin/bash
# stop on error
set -e
############################################
# install the required packages
sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get -y install linux-headers-$(uname -r) linux-image-extra-`uname -r`
# install cuda
View spynet.py
# coding: utf-8
# Imports
import os
import cPickle
import numpy as np
import theano
import theano.tensor as T