Skip to content

Instantly share code, notes, and snippets.

@kailaix
kailaix / ppl.py
Last active December 29, 2018 20:07
A working example of Probabilistic Programming using Edward
# modified version from http://edwardlib.org/tutorials/
from tensorflow_probability import edward2 as ed
import tensorflow as tf
import tensorflow_probability as tfp
import numpy as np
def logistic_regression(features):
coeffs = ed.Normal(loc=0., scale=1.,
sample_shape=features.shape[1], name="coeffs")
outcomes = ed.Bernoulli(logits=tf.tensordot(features, coeffs, [[1], [0]]),
@kailaix
kailaix / cir.jl
Last active January 13, 2019 22:59
CIR Model
using LinearAlgebra
using PyPlot
using SparseArrays
# https://uu.diva-portal.org/smash/get/diva2:1148496/FULLTEXT01.pdf page 8
# https://regulation.pstat.ucsb.edu/sites/sa-wcmf6/5-Peng_ECIR_Model_Qidi.pdf page 13
# params
r0 = 0.5
L = 4.0
a = 1.0
@kailaix
kailaix / run.sh
Created February 2, 2019 21:22
Running jobs in parallel
for n in 50 60 70 80 90 100
do
julia euro_main.jl $n 2>&1 | tee -a euro$n.log &
done
wait %1 %2 %3 %4 %5 %6
for n in 50 70 90 110 130 150
do
julia flap_main.jl $n 2>&1 | tee -a flap$n.log &
@kailaix
kailaix / pwd.cpp
Created April 17, 2019 22:54
PWD in C++
std::string survey_fname;
std::string dir(__FILE__);
dir = dir.substr(0, dir.find_last_of("\\/"));
@kailaix
kailaix / Burgers.jl
Created April 7, 2020 04:43
Finite difference for Burger's equation
using PyPlot
using ADCMEKit
NT = 2000
n = 100
Δt = 1.0/NT
Δx = 1/n
method = "Central"