Skip to content

Instantly share code, notes, and snippets.

View twolodzko's full-sized avatar

Timothy Wolodzko twolodzko

View GitHub Profile
@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 / 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@twolodzko
twolodzko / Pearce_etal_2020_for_normal_mean.ipynb
Created May 6, 2020 12:26
Trying the RMS alsorithm from the Uncertainty in Neural Networks: Approximately Bayesian Ensembling paper by Pearce et al (2020) on trivial example of estimating mean for normal distribution with known variance
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@twolodzko
twolodzko / prbr.sh
Last active May 18, 2020 11:36
Git squash and rebase branch into a single commit branch
#!/bin/bash
set -e
git fetch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
NEWBRANCH="$BRANCH-pr"
if [[ -n $(git rev-parse --verify $NEWBRANCH) ]]; then
read -p "'$NEWBRANCH' exists, do you want to overwrite it? (y/[n])? " CONTINUE
@twolodzko
twolodzko / sampling_multivariate_normal.py
Created April 2, 2020 14:24
Sampling from multivariate normal distribution in Numpy
import numpy as np
import scipy.stats as sp
C = np.array([
[3, 2, 3],
[2, 4, 2],
[3, 2, 3]
])
n = 100_000
@twolodzko
twolodzko / conda_and_jupyter.md
Created January 21, 2020 09:35
conda_and_jupyter.md

Conda

# new env:
conda create --name myenv python=3.7 ipykernel numpy pandas

# remove:
conda remove --name myenv --all

# export:
"""
This is a pure python implementation of t-digest algorithm 1. Parts of the code are borrowed
from https://github.com/CamDavidsonPilon/tdigest
Code is released under The MIT License (MIT).
"""
import math
from typing import List, Tuple, Union, Optional
@twolodzko
twolodzko / Regression on aggregated data.ipynb
Created October 10, 2019 14:30
Regression on aggregated data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import matplotlib.pyplot as plt
class ECDF:
def __init__(self, arr: np.ndarray, max_points: Optional[int] = None) -> None:
self.arr = np.sort(arr)
n = len(self.arr)
if max_points and n > max_points:
self.arr = self.arr[:: (n // max_points)]