Skip to content

Instantly share code, notes, and snippets.

View twolodzko's full-sized avatar

Timothy Wolodzko twolodzko

View GitHub Profile
@twolodzko
twolodzko / partial_correlation.py
Last active July 12, 2019 16:35
Partial correlation
import numpy as np
def pcor(X, rowvar=False):
"""
Partial correlation
Implemented as in pcor::pcor function in R.
Kim, S. (2015) ppcor: An R Package for a Fast Calculation to Semi-partial Correlation Coefficients.
Communications for Statistical Applications and Methods, 22(6), 665-674.
@twolodzko
twolodzko / matplotlib_identity_line.py
Created October 7, 2019 13:11
Identity line for matplotlib
import matplotlib.pyplot as plt
def identity_line(ax=None, ls='--', *args, **kwargs):
# see: https://stackoverflow.com/q/22104256/3986320
ax = ax or plt.gca()
identity, = ax.plot([], [], ls=ls, *args, **kwargs)
def callback(axes):
low_x, high_x = ax.get_xlim()
low_y, high_y = ax.get_ylim()
low = min(low_x, low_y)
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)]
@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.
"""
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 / 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:
@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 / 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 / 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.