Skip to content

Instantly share code, notes, and snippets.

View yulkang's full-sized avatar

Yul Kang yulkang

View GitHub Profile
@yulkang
yulkang / torch_jacobian.py
Created June 12, 2019 16:02 — forked from sbarratt/torch_jacobian.py
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
@yulkang
yulkang / .gitignore
Last active November 12, 2023 03:29 — forked from gngdb/example_usage.py
Wrap PyTorch functions for scipy's optimize.minimize: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
*.pyc
@yulkang
yulkang / bootstrap.py
Created April 25, 2022 16:49 — forked from johnb30/bootstrap.py
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"):
@yulkang
yulkang / rotateVectors.py
Created December 13, 2022 04:29 — forked from fasiha/rotateVectors.py
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)