Skip to content

Instantly share code, notes, and snippets.

View crhea93's full-sized avatar
💭
Astrophysics!

Carter Lee Rhea crhea93

💭
Astrophysics!
  • Montreal, QC, CANADA
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@crhea93
crhea93 / PCA-step0
Last active November 1, 2020 19:40
# Define datasets
X = [1, 1.25, 1.8, 1.9, 2.21, 2.85]
Y = [1.1, 1.14, 1.8, 1.85, 2.25, 2.9]
print(X,Y)
# Let's see what this looks like
with plt.xkcd():
plt.scatter(X, Y)
plt.show()
# Calculate means and normalize
x_mean = np.mean(X)
X_adj = [x-x_mean for x in X]
y_mean = np.mean(Y)
Y_adj = [y - y_mean for y in Y]
# Caculate Covariance Matrix
cov = np.cov(X_adj, Y_adj)
print(cov)
lam, v = np.linalg.eig(cov)
print("Eigenvalues:")
print(lam)
print("Eigenvectors:")
print(v)
# Sort
eigvals, eigvects = (list(t) for t in zip(*sorted(zip(lam, v))))
# And now we can see what this looks like!
x_s = np.linspace(np.min(X_adj), np.max(X_adj), 10)
@crhea93
crhea93 / MSIGMA-imports.py
Last active August 1, 2022 22:56
MSIGMA-imports
import corner
import emcee
from google.colab import drive
import pandas as pd
import matplotlib.pyplot as plt
import mplcyberpunk
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
plt.style.use("cyberpunk")
@crhea93
crhea93 / MSIGMA-read.py
Created August 1, 2022 23:03
MSIGMA-Read
data = pd.read_csv(DATASET_PATH, delimiter=' ')
data['M_BH'] = np.log10(data['M_BH'])
data['M_low'] = np.log10(data['M_low'])
data['M_high'] = np.log10(data['M_high'])
# Change low and high to errors
data['M_low'] = data['M_BH'] - data['M_low']
data['M_high'] = data['M_high'] - data['M_BH']
@crhea93
crhea93 / gaussians1.py
Created October 12, 2022 19:15
RIM-create-gaussians
n = 50 # Size of spectrum
N = 5000 # Number of spectra
def gaussian(x, mu, sig):
return 1*np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
def conv_mat(n):
"""
Create convolution matrix that is an identity matrix with noise
"""
conv_mat = np.eye(n)+np.random.normal(0, 0.05, (n,n))