Skip to content

Instantly share code, notes, and snippets.

View galenseilis's full-sized avatar
📈
f(data | model, expertise) = insight

Galen Seilis galenseilis

📈
f(data | model, expertise) = insight
View GitHub Profile
@galenseilis
galenseilis / msc_parallel_corr.py
Created December 7, 2022 15:05
Code from early on in my MSc.
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)
@galenseilis
galenseilis / std_err_converge.py
Created December 7, 2022 15:03
Standard error convergence
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)
# 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)
@galenseilis
galenseilis / collider_sem_semopy.py
Created December 7, 2022 14:50
Plot simply collider SEM using SemoPy
from semopy import Model, semplot
desc = '''
Y ~ X
Y ~ Z
'''
model = Model(desc)
semplot(model, 'test.png', plot_covs=True)
@galenseilis
galenseilis / test_tensor_decomp.py
Created December 7, 2022 14:47
Testing out CP decomposition on toy example.
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)
@galenseilis
galenseilis / hyppermplot.py
Created December 7, 2022 14:45
Plot hypergraph wose edges satisfy certain addition constraints
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):
@galenseilis
galenseilis / bit_flip_regression.py
Created December 7, 2022 14:43
Bit flip regression example
from codecs import decode
import struct
class SimpleLinearRegression():
'''
Simple linear regression trained with bit flipping.
'''
def __init__(self):
self.slope = self.random_bin()
@galenseilis
galenseilis / bit_stochastic_process.py
Created December 7, 2022 14:41
Bit-to-binary stochastic process example
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)
@galenseilis
galenseilis / 3d_partial_surface.py
Last active December 7, 2022 14:39
Plot of partial of f(x,y,z)=xyz
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]
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