Skip to content

Instantly share code, notes, and snippets.

View michaelchughes's full-sized avatar

Mike Hughes michaelchughes

View GitHub Profile
@michaelchughes
michaelchughes / marg_lik_for_unk_m_fix_v_normal.py
Created September 6, 2017 21:21
Computing marginal log likelihood of data for unknown mean, fixed variance normal model.
'''
Computing marginal log likelihood of data for unknown mean, fixed variance model.
Running Demo
------------
$ python marg_lik_of_normal.py
This will compare numerical and exact methods for calculating marg. lik.
By visual inspection, user can see the exact method matches numerical.
@michaelchughes
michaelchughes / README.md
Last active May 30, 2024 01:16
Fixes for GLIBC errors when installing tensorflow or pytorch on older Red Hat or CentOS cluster environments

Goal

Install working tensorflow or pytorch via standard conda environment workflow.

Basic Setup : Install pytorch in a fresh conda environment

The recommended conda-based install process works smoothly:

$ # Create a fresh environment
@michaelchughes
michaelchughes / RemoveBadFilesFromGit.md
Last active April 7, 2023 15:02
Remove Bad Files from Git Completely

RECIPE TO TOTALLY REMOVE BAD FILES FROM A GIT REPO WITH MULTIPLE USERS

1) Make sure all local copies of the repo are sync'd on the same commit

We assume that there are two users (A and B). A is gonna delete the bad files. B is gonna receive the changes.

At the start, we need A and B to have the SAME version history.

We'll assume there are no branches other than master.

@michaelchughes
michaelchughes / convert_ordered_to_indicator.py
Last active July 19, 2019 13:29
Convert Ordered ICD DataFrame to Indicator
import numpy as np
import pandas as pd
import argparse
def convert_ordered_dx_df_to_indicator_df(
ordered_dx_df,
list_of_possible_icd_code_values=None,
list_of_possible_icd_code_names=None):
''' Convert rank-ordered diagnosis codes into indicator format
@michaelchughes
michaelchughes / speedtest__per_subj_mean.py
Created September 18, 2019 22:51
Collapsing DataFrame by subject
import pandas as pd
import numpy as np
import time
prng = np.random.RandomState(0)
n_subj = 20000
n_rows = 1000000
# Randomly assign to one of 20000 subjects
@michaelchughes
michaelchughes / SimpleICUViz.ipynb
Created September 24, 2019 21:56
Simple visualization of ventilator usage and vital signs in the ICU
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@michaelchughes
michaelchughes / normal_distribution_with_log_std_dev_parameterization.py
Last active October 4, 2019 12:04
Using log of standard deviation parameterization of the Normal
S = 10 # num samples throughout
## FIRST, REMEMBER THE COMMON PARAMETERIZATION
# x ~ Normal(m, sigma^2)
# m is a real number
# sigma >= 0 is a standard deviation
m = 2
sigma = 0.1
@michaelchughes
michaelchughes / bnpy_changepoint.py
Created January 21, 2020 23:04
Simple changepoint detection from BNPy HMM code
## Using notation from HDP-HMM paper in NeurIPS 2015 (Hughes, Stephenson, Sudderth)
## Start for a single sequence of interest,
## Compute the following as in the tutorial here:
https://bnpy.readthedocs.io/en/latest/examples/08_mocap6/plot-03-demo=interpret_hdphmm_params_and_run_viterbi.html#sphx-glr-examples-08-mocap6-plot-03-demo-interpret-hdphmm-params-and-run-viterbi-py
# start_prob_K : 1D array size K, sums to one
# trans_proba_KK : 2D array, size K x K, rows sum to one
# log_lik_seq_TK : 2D array, size T x K
@michaelchughes
michaelchughes / demo_per_token_elbo.py
Last active May 27, 2020 23:25
Quick check of per-token ELBO calculation
import numpy as np
import scipy.stats
from scipy.special import logsumexp, softmax
np.set_printoptions(precision=3, suppress=1)
## Settings
## --------
@michaelchughes
michaelchughes / check_job.sh
Created May 30, 2020 19:00
SLURM post-mortem diagnostics
sacct -j 56012984_1.batch --format=jobid,jobname,partition,maxvmsize,maxrss,state,elapsed,reqmem,reqcpus