Skip to content

Instantly share code, notes, and snippets.

View twolodzko's full-sized avatar

Timothy Wolodzko twolodzko

View GitHub Profile
@twolodzko
twolodzko / stick-breaking.ipynb
Created June 2, 2020 11:00
Stick breaking process example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@twolodzko
twolodzko / 471238_prior_vs_posterior.R
Created June 10, 2020 07:19
Examples of prior having impact on posterior
# code accompanying answer: https://stats.stackexchange.com/a/471245/35989
n <- 22
x <- 13
lik <- function(p) dbinom(x, n, p) * 20
prior <- function(p) dbeta(p, alpha, beta)
post <- function(p) dbeta(p, alpha+x, beta+(n-x))
op <- par(mfrow=c(1,3), mar=c(3,1,1,1), cex=0.9)
@twolodzko
twolodzko / Multi-Armed Bandits.ipynb
Created August 25, 2020 14:36
Multi-Armed Bandit Algorithm Examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// ==UserScript==
// @name Redirect Jupyter notebooks from GitHub
// @namespace http://tampermonkey.net/
// @version 0.1
// @match github.com/*.ipynb
// @grant none
// ==/UserScript==
(function() {
'use strict';
@twolodzko
twolodzko / flags.go
Created April 28, 2021 15:56
Print command line flags
package main
import (
"fmt"
"os"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "--help" {
args := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@twolodzko
twolodzko / timeout.py
Last active June 25, 2021 10:45
Timeout context manager
import signal
from contextlib import contextmanager
from time import sleep
import pytest
@contextmanager
def timeout(time):
"""Timeout context manager
@twolodzko
twolodzko / Frequentist-vs-Bayesian-beta-hypothesis-test.ipynb
Created July 21, 2021 10:35
Frequentist vs Bayesian hypothesis test giving same results answer to CrossValidated.com question
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@twolodzko
twolodzko / validate_cell_execution_counts.py
Created April 7, 2022 11:01
Validate Jupyter notebook cell execution counts
import json
import sys
# Validate if notebook cells were executed in order
if __name__ == '__main__':
if len(sys.argv) > 0:
path = sys.argv[1]
else:
@twolodzko
twolodzko / 585019-sequential-updating-normal-gama.r
Last active August 11, 2022 09:11
Sequential Bayesian updating of Normal-gamma model
# See:
# https://people.eecs.berkeley.edu/%7Ejordan/courses/260-spring10/lectures/lecture5.pdf
# https://www.cs.ubc.ca/%7Emurphyk/Papers/bayesGauss.pdf
post <- function(x, mu0, kappa0, alpha0, beta0) {
n <- length(x)
xbar <- mean(x)
sse <- sum((x - xbar)^2)
mu <- ((kappa0 * mu0) + (n * xbar)) / (kappa0 + n)
@twolodzko
twolodzko / nbclean
Last active January 2, 2023 09:35
Clean metadata from Jupyter notebooks
#!/bin/bash
function usage {
echo "Usage: $(basename "$0") [OPTION]... FILE" 2>&1
echo " -i modify the file in place"
echo " -o don't strip the outputs"
echo " -h display this help and exit"
exit 0
}