This file contains hidden or 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 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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 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) |
This file contains hidden or 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 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])) |
This file contains hidden or 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 | |
| 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) |
This file contains hidden or 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
| 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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 | |
| 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) |
This file contains hidden or 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 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')) |
This file contains hidden or 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 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) |