Skip to content

Instantly share code, notes, and snippets.

View galenseilis's full-sized avatar
🚀
🟰🦀➕🐍

Galen Seilis galenseilis

🚀
🟰🦀➕🐍
View GitHub Profile
from scipy import stats
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1, 1, num=150)
y = 10*x + np.random.normal(size=x.size)
y[11:15] += 10
y[-5:] -= 7
import numpy as np
def scale(x, a=0, b=1):
if a > b:
a, b = b, a
min_x = np.min(x)
result = (x - min_x) / (np.max(x) - min_x)
result *= (b - a)
result += a
return result
import numpy as np
def scale(x, a=0, b=1):
if a > b:
a, b = b, a
min_x = np.min(x)
xout = (x - min_x) / (np.max(x) - min_x)
xout *= (b - a)
xout += a
sigma_in = np.std(x, ddof=1)
import numpy as np
def convert_range(value, r1, r2 ):
return (value - r1[0]) * (r2[1] - r2[0]) / (r1[1] - r1[0]) + r2[0]
if __name__ == '__main__':
print(convert_range(328.17,[300.77,559.22 ],[1,10]))
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import describe
if __name__ == '__main__':
x = np.random.normal(2, 3, size=10**4)
z = x + x
q = 2 * x
plt.hist(x, bins=100, alpha=0.1)
plt.hist(z, bins=100, alpha=0.1)
@galenseilis
galenseilis / normal_parameter_tensor.py
Created October 16, 2022 17:04
A model which is nothing but a k-mode tensor of trainable parameters. Useful for making certain toy data sets.
class ParameterTensor(tf.keras.models.Model):
def __init__(self, shape):
super().__init__()
self.w = tf.random.normal(shape=shape)
self.w = tf.Variable(self.w, trainable=True)
def call(self, x=None):
return self.w
import tensorflow as tf
class ChiCorr(tf.keras.losses.Loss):
def chilogl(self, x, k=2):
ll = k * tf.math.log(x) / 2
ll = ll - x / 2
ll = ll - k * tf.math.log(2.0) / 2
ll = ll - tf.math.lgamma(k / 2)
return -ll
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
z1 = np.random.chisquare(10, 10**4)
z2 = np.random.chisquare(10, 10**4)
c = 10
y = (z1 + c) / (z1 - z2)
sort_y = np.sort(y)
from astropy.stats import jackknife_stats
import numpy as np
from scipy.spatial.distance import pdist
data = np.random.normal(size=10**3)
def test_statistic(x):
x = np.unique(x)
x = x.reshape(-1,1)
return np.min(pdist(x, metric='cityblock'))
from dateutil import parser
import os
import requests
import zipfile
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 500)