Skip to content

Instantly share code, notes, and snippets.

View yulkang's full-sized avatar

Yul Kang yulkang

View GitHub Profile
@johnb30
johnb30 / bootstrap.py
Created November 29, 2012 01:06
Bootstrapped two-sample t-test in Python
from __future__ import division
import numpy as np
import pandas as pd
import random
def sample(data):
sample = [random.choice(data) for _ in xrange(len(data))]
return sample
def bootstrap_t_test(treatment, control, nboot = 1000, direction = "less"):
@fasiha
fasiha / rotateVectors.py
Last active June 22, 2024 23:13
I frequently have to re-implement projecting vectors onto other vectors, and rotating vectors about other vectors. So here we go. Public domain.
import unittest
import numpy as np
import numpy.linalg as linalg
def makeUnit(x):
"""Normalize entire input to norm 1. Not what you want for 2D arrays!"""
return x / linalg.norm(x)
@zhiyzuo
zhiyzuo / pearsonr_ci.py
Last active January 4, 2023 06:19
calculate Pearson correlation along with the confidence interval using scipy and numpy
import numpy as np
from scipy import stats
def pearsonr_ci(x,y,alpha=0.05):
''' calculate Pearson correlation along with the confidence interval using scipy and numpy
Parameters
----------
x, y : iterable object such as a list or np.array
Input for correlation calculation
@sbarratt
sbarratt / torch_jacobian.py
Created May 9, 2019 19:40
Get the jacobian of a vector-valued function that takes batch inputs, in pytorch.
def get_jacobian(net, x, noutputs):
x = x.squeeze()
n = x.size()[0]
x = x.repeat(noutputs, 1)
x.requires_grad_(True)
y = net(x)
y.backward(torch.eye(noutputs))
return x.grad.data