Skip to content

Instantly share code, notes, and snippets.

View ChuaCheowHuan's full-sized avatar
⛏️
Focusing

Chua Cheow Huan ChuaCheowHuan

⛏️
Focusing
View GitHub Profile
@ChuaCheowHuan
ChuaCheowHuan / smk_ray_0.6.5_custom_env_output.txt
Created September 30, 2019 09:37
smk ray 0.6.5 custom env output
Creating tmp8z_8haic_algo-1-vmd10_1 ...
Attaching to tmp8z_8haic_algo-1-vmd10_12mdone
algo-1-vmd10_1 | 2019-09-30 07:54:22,885 sagemaker-containers INFO Imported framework sagemaker_tensorflow_container.training
algo-1-vmd10_1 | 2019-09-30 07:54:22,892 sagemaker-containers INFO No GPUs detected (normal if no gpus installed)
algo-1-vmd10_1 | 2019-09-30 07:54:23,011 sagemaker-containers INFO No GPUs detected (normal if no gpus installed)
algo-1-vmd10_1 | 2019-09-30 07:54:23,031 sagemaker-containers INFO No GPUs detected (normal if no gpus installed)
algo-1-vmd10_1 | 2019-09-30 07:54:23,045 sagemaker-containers INFO Invoking user script
algo-1-vmd10_1 |
algo-1-vmd10_1 | Training Env:
algo-1-vmd10_1 |
@ChuaCheowHuan
ChuaCheowHuan / test_modify_orders.py
Created October 30, 2019 07:44
test modify orders
#! /usr/bin/python
from __future__ import print_function
from random import *
import sys
sys.path.append('..')
from orderbook import OrderBook
order_book = OrderBook()
order_0 = {'type' : 'limit',
@ChuaCheowHuan
ChuaCheowHuan / tf_KL_divergence.py
Created April 20, 2020 06:32
tf KL divergence
import tensorflow as tf
import numpy as np
m1 = np.array([[[0.0], [1.1]], [[0.1], [1.2]], [[0.2], [1.3]]])
s1 = np.array([[[1.1]], [[1.2]], [[1.3]]])
m2 = np.array([[[1.0]], [[1.1]], [[1.2]]])
s2 = np.array([[[0.1]], [[0.2]], [[0.3]]])
print(m1.shape)
nd_1 = tf.distributions.Normal(loc=m1, scale=s1)
@ChuaCheowHuan
ChuaCheowHuan / FS_LSTM.py
Last active April 20, 2020 06:39
Fast-slow LSTM
#class FSRNNCell(tf.contrib.rnn.RNNCell):
class FSRNNCell(tf.compat.v1.nn.rnn_cell.RNNCell):
def __init__(self, fast_cells, slow_cell, input_keep_prob=1.0, keep_prob=1.0, training=True):
"""Initialize the basic Fast-Slow RNN.
Args:
fast_cells: A list of RNN cells that will be used for the fast RNN.
The cells must be callable, implement zero_state() and all have the
same hidden size, like for example tf.contrib.rnn.BasicLSTMCell.
slow_cell: A single RNN cell for the slow RNN.
keep_prob: Keep probability for the non recurrent dropout. Any kind of
@ChuaCheowHuan
ChuaCheowHuan / FS_LSTM_VU.py
Last active April 20, 2020 08:12
Fast-slow LSTM with variational unit (VU)
import tensorflow as tf
import numpy as np
latent_dim = 2
#class FSRNNCell_VU(tf.contrib.rnn.RNNCell):
class FSRNNCell_VU(tf.compat.v1.nn.rnn_cell.RNNCell):
def __init__(self, fast_cells, slow_cell, input_keep_prob=1.0, keep_prob=1.0, training=True):
@ChuaCheowHuan
ChuaCheowHuan / mvg_KL.py
Created April 20, 2020 06:38
KL divergence for multivariate normal distributions
def kl_mvn(m0, S0, m1, S1):
"""
https://stackoverflow.com/questions/44549369/kullback-leibler-divergence-from-gaussian-pm-pv-to-gaussian-qm-qv
The following function computes the KL-Divergence between any two
multivariate normal distributions
(no need for the covariance matrices to be diagonal)
Kullback-Liebler divergence from Gaussian pm,pv to Gaussian qm,qv.
Also computes KL divergence from a single Gaussian pm,pv to a set
@ChuaCheowHuan
ChuaCheowHuan / hyp_chg_MARL.py
Last active July 31, 2020 10:50
Change hyperparameters during runtime for MARL with ray[rllib]
# -*- coding: utf-8 -*-
"""hyp_chg_MARL.ipynb
Automatically generated by Colaboratory.
Original file is located at
"""
# Commented out IPython magic to ensure Python compatibility.
"""
@ChuaCheowHuan
ChuaCheowHuan / hyp_chg_schd_MARL.py
Last active August 4, 2020 14:54
Changing hyperparameter via lr_schedule for MARL with ray[rllib]
# -*- coding: utf-8 -*-
"""mod_pol.ipynb
Automatically generated by Colaboratory.
Original file is located at
"""
"""
# Commented out IPython magic to ensure Python compatibility.
@ChuaCheowHuan
ChuaCheowHuan / lr_schedule_ddppo.py
Created August 5, 2020 13:09
Testing lr_schedule for ddppo
from gym.spaces import Discrete
import numpy as np
import ray
from ray.rllib.env.multi_agent_env import MultiAgentEnv
from ray.rllib.models import ModelCatalog
from ray.rllib.agents.ppo import ddppo
from ray.rllib.agents.ppo import DDPPOTrainer
from ray.rllib.utils.framework import try_import_tf