Skip to content

Instantly share code, notes, and snippets.

View ekibun's full-sized avatar
🕊️
GUGUGU

ekibun ekibun

🕊️
GUGUGU
View GitHub Profile
@raddy
raddy / sample_higher_moments.py
Created September 12, 2018 02:09
Sample from a distribution with known skew and kurtosis
import statsmodels.sandbox.distributions.extras as extras
import scipy.interpolate as interpolate
import numpy as np
def generate_normal_four_moments(mu, sigma, skew, kurt, size=1000, sd_wide = 10):
f = extras.pdf_mvsk([mu, sigma, skew, kurt])
x = np.linspace(mu - sd_wide * sigma, mu + sd_wide * sigma, num=500)
y = [f(i) for i in x]
yy = np.cumsum(y) / np.sum(y)
inv_cdf = interpolate.interp1d(yy, x, fill_value="extrapolate")