Skip to content

Instantly share code, notes, and snippets.

View iantimmis's full-sized avatar
🧑‍🍳
Cookin

Ian Timmis iantimmis

🧑‍🍳
Cookin
  • Michigan
View GitHub Profile
@iantimmis
iantimmis / james_stein_estimation.py
Last active August 5, 2025 15:04
James-Stein Estimation
import numpy as np
def run_trial():
# Hidden Variables
a = np.random.rand()
b = np.random.rand()
c = np.random.rand()
# Create 3 variables sampled from normal distributions
var1 = np.random.normal(loc=a, scale=1)
@iantimmis
iantimmis / softmax_cross_entropy.py
Created October 12, 2020 03:54
Numerically stable softmax with cross entropy in numpy
import numpy as np
def naive_softmax(logits):
'''
Failure modes:
* If any entry is very large, exp overflows
* if all entries are very negative, all exps underflow
'''
exp_logits = np.exp(logits)
return exp_logits / np.sum(exp_logits)