This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def ewma(x, alpha, adjust=True): | |
q = 1 - alpha | |
y = x.copy() | |
if not adjust: | |
for i in range(1, len(y)): | |
y[i] += q * (y[i-1] - y[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (intersect, (\\)) | |
import Data.Maybe (catMaybes) | |
digits = ['1'..'9'] | |
blank = '0' | |
complexity = sum . map (length . filter (/= blank)) | |
rows = id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = np.array([ | |
[1, 1, 1], | |
[0.8, 0.7, 0.5] | |
]) | |
assert np.linalg.matrix_rank(A) == len(A) | |
Q, _ = np.linalg.qr(A.T) | |
P = np.eye(len(Q)) - Q @ Q.T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def l1_simplex_proj(x, radius=1.0): | |
z = np.abs(x) | |
mu = np.sort(z)[::-1] | |
cmu = np.cumsum(mu) | |
f = mu * np.arange(1, 1 + len(x)) - (cmu - radius) | |
rho = np.where(f > 0)[0][-1] | |
theta = (cmu[rho] - radius) / (1.0 + rho) | |
y = np.sign(x) * np.maximum(z - theta, 0) | |
return y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p = sp.stats.laplace.fit(x) | |
y = sp.stats.norm.ppf(sp.stats.laplace.cdf(x, *p)) | |
z = sp.stats.laplace.ppf(sp.stats.norm.cdf(y), *p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import sklearn.covariance as cov | |
def _norm2(x): | |
return np.square(x.real) + np.square(x.imag) | |
def rie_estimator(X): | |
T, N = X.shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LightGBMTree | |
{ | |
public int[] split_feature; | |
public double[] threshold; | |
public int[] left_child; | |
public int[] right_child; | |
public double[] leaf_value; | |
public double Predict(double[] features) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def markowitz(mu, cov, hedge=None): | |
z = mu | |
K = np.linalg.inv(cov) | |
if hedge is not None: | |
Q = hedge @ K @ hedge.T | |
beta = np.linalg.inv(Q) @ hedge @ K @ mu | |
z = mu - beta @ hedge | |
z = K @ z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import HTML | |
HTML("<style>.container { width: 95% !important; }</style>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _parmap(fun, q_in, q_out, init=None): | |
init() if init else None | |
while True: | |
i, x = q_in.get() | |
ret = fun(x) | |
q_out.put((i, ret)) | |
def parmap(fun, tasks, n=None, init=None): | |
from multiprocessing import Pool, Queue |
OlderNewer