Skip to content

Instantly share code, notes, and snippets.

View keon's full-sized avatar

Keon keon

View GitHub Profile
@keon
keon / unsort_pytorch.py
Created January 4, 2018 09:02
unsort pytorch
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())
@keon
keon / encoder-decoder.py
Last active April 7, 2019 08:40
basic mini encoder decoder model that translates 'hello' to 'hola'
# 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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
@keon
keon / dqn.py
Created February 18, 2017 11:46
DQN
# -*- 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
class Fenwick{
private:
const int maxN = 10000;
public:
int table[maxN];
int sumQuery(int a, int b){
return sumQuery(b) - sumQuery(a-1);
}
@keon
keon / README.md
Created February 4, 2017 11:24 — forked from tambetm/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
#!/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
# coding: utf-8
# Imports
import os
import cPickle
import numpy as np
import theano
import theano.tensor as T
#include <iostream>
using namespace std;
template <typename ObjectType>
class BaseClass{
public:
friend ObjectType;
int Increment(){
return obj.Increment();
// Load Data and Labels in double types
data::Load(inputFile, data, true);
data::Load(inputLabel, labels, true);
arma::rowvec labels_row = labels.row(0); // extract first row
// Split Data
const auto value = data::TrainTestSplit(data, labels_row, testRatio);
Log::Info << "Train Data Count: " << get<0>(value).n_cols << endl;
Log::Info << "Test Data Count: " << get<1>(value).n_cols << endl;