Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import scipy.stats as sps
import matplotlib.pyplot as plt
from scipy.special import digamma
#
# Config
#
np.random.seed(999)
plt.rcParams['font.family'] = "monospace"
/*
This code reads the BNO055 fast using the RPi linux kernel support for I2C.
for running this file as a program, compile and run!
gcc -o faster faster.c -O3 && ./faster
You can also compile as a shared lib, and then call it from python.
gcc -Wall -shared -o faster.so faster.c && python faster.py
Page number and table number references are to the BNO055 data sheet.
@el-hult
el-hult / MySet1.hs
Last active November 6, 2023 10:43
Two bad implementations of a Set in haskell
{- A module implementing a simple (and quite dumb) set -}
module MySet1 (Set, empty, toList, insert, contains) where
import Data.List(nub)
{- Set
A set, backed by a regular list.
If the list has duplicates, it is nothing the user should notice
-}
data Set a = SetC [a]
@el-hult
el-hult / leg_jax.py
Created August 20, 2024 11:08
Jax program that computes the Legendre approximation for the Entropy of a Gaussian Mixture Model, according to Caleb Dahlke and Jason Pacheco https://papers.nips.cc/paper_files/paper/2023/hash/ee860a9fa65a55a335754c557a5211de-Abstract-Conference.html
import jax
import jax.numpy as jnp
import functools
def gmm_max(logpi, mu, cov):
"""Return an upper bound the GMM density
logpi: (K,)-array of the log-weights
mu: (K, D)-array of the component means
cov: (K,D,D)-array of the component covarainces