Skip to content

Instantly share code, notes, and snippets.

View andiac's full-sized avatar
🦄
Yooooooooo

Andi Zhang andiac

🦄
Yooooooooo
View GitHub Profile
@andiac
andiac / eval_ece.py
Created December 9, 2020 03:03
Evaluate ECE
def evaluate_ECE(data_iter, net, device, M=15):
net.eval()
bins, n = [0.0 for _ in range(M)], 0
with torch.no_grad():
for X_batch, y_batch in data_iter:
p_batch = torch.exp(lsoftmax(net(X_batch.to(device))))
y_hat_batch = net(X_batch.to(device)).argmax(dim=1)
for p, y_hat, y in zip(p_batch.numpy(), y_hat_batch.numpy(), y_batch.numpy()):
@andiac
andiac / textCNNconv.py
Last active December 17, 2020 05:24
TextCNN pytorch implementation, conv1d vs. conv2d
import torch
batch_size = 3
seq_len = 20
vocab_size = 4
emb_size = 6
conv_length = 2
num_conv_kernel = 30
channel_in = 1 # of course for text...
@andiac
andiac / kldivs.ipynb
Last active June 7, 2021 08:46
KL divergence between a gaussian and a mixture of gaussian
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andiac
andiac / hsv_ref.py
Last active February 10, 2022 11:40
Generate HSV color inference for [Opencv optical flow example](https://docs.opencv.org/4.4.0/d4/dee/tutorial_optical_flow.html)
import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
output_size = 501
flow = np.zeros((output_size, output_size, 2), dtype=np.float32)
flow[:, :, 0] = np.arange(-(output_size // 2), output_size // 2 + 1)
flow[:, :, 1] = np.arange(-(output_size // 2), output_size // 2 + 1)[:, np.newaxis]
@andiac
andiac / anim.py
Created February 10, 2022 22:51
Matplotlib patch animation
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib.collections import PatchCollection
fig = plt.figure()
ax = plt.axes(xlim=(-1.5, 1.5), ylim=(-1.5, 1.5), aspect='equal')
# not visible
@andiac
andiac / brownian_bridge.py
Created February 17, 2022 20:50
Generate brownian bridge
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
N = 10
T = 300
random_seed = 0
np.random.seed(random_seed)
@andiac
andiac / heteroskedastic_lr.ipynb
Last active March 15, 2022 18:40
Heteroskedastic linear regression...
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andiac
andiac / svg_to_tikz.py
Last active May 6, 2022 00:50
svg path to tikz code
import svgpathtools
from svgpathtools import svg2paths2
paths, attributes, svg_attributes = svg2paths2('doubleset.svg')
SCALE = 10
print("\\begin{tikzpicture}")
for path in paths:
print("\\begin{scope}")
for b in path:
@andiac
andiac / mitsuba_3_direct_integrator.ipynb
Last active July 21, 2022 21:02
This is a direct integrator for Mitsuba 3
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.