Skip to content

Instantly share code, notes, and snippets.

View Vayel's full-sized avatar

Vincent Lefoulon Vayel

View GitHub Profile
import random
# A stochastic model with a single input `p` and a single output `side`
# `p` is the probability of throwing tail
# `side` is either 'head' or 'tail'
def coin_model(p, seed=None):
# The seed allows us to control randomness and ensure reproducibility
random.seed(seed)
# Mathematically, `side_output` is a discrete random variable
import scipy.stats
import numpy as np
def ks_test(real_series, simulated_series):
# `real_series` and `simulated_series` are lists of series, i.e. lists of lists.
# All series have the same size but we don't need to have as many real series as
# simulated series.
real_series, simulated_series = map(np.asarray, (real_series, simulated_series))
n_steps = len(real_series[0])
@Vayel
Vayel / data.csv
Last active August 15, 2018 08:33
ks_test_data
0.0 0.253 0.490 0.695 0.855
0.013 0.133 0.217 0.713 1.04
0.044 0.284 0.587 0.855 0.739
0.238 0.361 0.400 0.598 0.829
-0.098 0.054 0.428 0.791 0.836
-0.042 0.310 0.474 0.633 0.799
import random
import json
Y0 = 100
noise = lambda: random.gauss(0, 0.01)
def run(steps):
y = [Y0] * steps
for t in range(1, steps):
y[t] = y[t-1] * (1 + noise())
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import kstwobign
d_min, d_max = kstwobign.ppf(0.01), kstwobign.ppf(0.99)
d_vals = np.linspace(d_min, d_max, num=100)
cdf = kstwobign.cdf(d_vals)
fig, ax = plt.subplots()
ax.plot(d_vals, cdf, '-')
### Keybase proof
I hereby claim:
* I am vayel on github.
* I am vayel (https://keybase.io/vayel) on keybase.
* I have a public key ASBu4piKL-qabomWg9YNFVEaJls_4hnebIMSwdm-oaTkAAo
To claim this, I am signing this object: