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 / 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 / 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 / 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 / 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 / retroarch.cfg
Created November 6, 2020 05:55
Clockwork os 0.5 default retroarch settings
ai_service_enable = "false"
ai_service_mode = "0"
ai_service_pause = "false"
ai_service_source_lang = "0"
ai_service_target_lang = "0"
ai_service_url = "http://localhost:4404/"
all_users_control_menu = "true"
apply_cheats_after_load = "false"
apply_cheats_after_toggle = "false"
aspect_ratio_index = "0"
/*
* Copyright (C) 2020-2021 Andi Zhang <[email protected]>
*/
#include <iostream>
using namespace std;
class MyInt {
public:
@andiac
andiac / qsort.py
Last active March 8, 2020 23:59
Some sorts
import random
import sys
import time
# sys.setrecursionlimit(10000)
def qsort(a):
if len(a) <= 1: return a
pivot = random.choice(a)
left = qsort([x for x in a if x < pivot])
@andiac
andiac / cross_validation_std.ipynb
Last active January 18, 2020 21:02
cross_validation?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andiac
andiac / IcdfBeta.ipynb
Created December 18, 2019 22:57
Pytorch Autograd Function for the Inverse CDF of Beta Distribution (numerical deriviation)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@andiac
andiac / ac_automaton.py
Created December 17, 2019 22:50
Aho-Corasick Automaton
from collections import deque
class TrieNode:
def __init__(self, endWord = False, parent = None, char = ''):
# to record duplicate words
self.count = int(endWord)
self.children = dict()
# fail pointer of Aho Corasick Automaton
self.fail = None
# recording the parent in order to output the matched concept