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 itertools import combinations | |
from time import ctime, time | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from multiprocessing import Pool | |
def corr(X, method='pearson'): | |
if method == 'pearson': | |
X = X - np.mean(X, axis=0) |
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 | |
N = 10**2 | |
x = np.random.normal(0,100,size=N) | |
means = [] | |
stderrors = [] | |
for i in range(2, N+1): | |
sample = np.random.choice(x, size=i, replace=False) |
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
# https://stats.stackexchange.com/questions/557381/how-do-i-interpret-or-explain-loess-plot | |
from statsmodels.nonparametric.smoothers_lowess import lowess | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from p_tqdm import p_map | |
from astropy.stats import bootstrap | |
x = np.linspace(0,80,1000) | |
y = np.sin(x) + 0.1 * x + np.random.normal(0, 0.1, size=1000) |
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 semopy import Model, semplot | |
desc = ''' | |
Y ~ X | |
Y ~ Z | |
''' | |
model = Model(desc) | |
semplot(model, 'test.png', plot_covs=True) |
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 | |
from time import time | |
import numpy as np | |
import tensorly as tl | |
from tensorly.random import random_cp | |
from tensorly.decomposition import CP, parafac | |
tol = np.logspace(-1, -9) | |
err = np.empty_like(tol) |
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 hypernetx as hnx | |
import matplotlib.pyplot as plt | |
from itertools import permutations | |
values = set(range(10)) | |
solutions = {} | |
sol_count = 0 | |
for perm in permutations(values, r=6): |
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 codecs import decode | |
import struct | |
class SimpleLinearRegression(): | |
''' | |
Simple linear regression trained with bit flipping. | |
''' | |
def __init__(self): | |
self.slope = self.random_bin() |
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 | |
import struct | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
def binary(num): | |
return ''.join('{:0>8b}'.format(c) for c in struct.pack('!f', num)) | |
binary = np.vectorize(binary) |
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 mpl_toolkits.mplot3d import axes3d | |
import matplotlib.pyplot as plt | |
from matplotlib import cm | |
import numpy as np | |
def V(x,y,z): | |
return x * y * z | |
X,Y = np.mgrid[-1:1:100j, -1:1:100j] | |
Z_vals = [ -0.5, 0.0, 0.5] |
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 itertools import product | |
import numpy as np | |
class Interval(object): | |
def __init__(self, lower, upper): | |
assert lower <= upper | |
self.a = lower | |
self.b = upper |