Skip to content

Instantly share code, notes, and snippets.

View yuq-1s's full-sized avatar
:octocat:
Working in the lab

Yuquan Wang yuq-1s

:octocat:
Working in the lab
  • Tsinghua University
  • Beijing
View GitHub Profile
@yuq-1s
yuq-1s / dptable.cc
Last active December 3, 2019 10:58
Dynamic programming like a mathematician
#include <limits>
#include <array>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#define MO 998244353
template <typename T, size_t rank>
@yuq-1s
yuq-1s / heartbeat-client.py
Last active February 22, 2019 10:22
heartbeat for dynamic dns
import socket
import time
import copy
import struct
import socketserver
import select
#######################################################################
# package pyaes #
#######################################################################
@yuq-1s
yuq-1s / treemnist.py
Created April 8, 2019 10:19
mnist with naive binary-tree-like hierarchical softmax
from __future__ import print_function
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms
import torchvision
class Net(nn.Module):
@yuq-1s
yuq-1s / hmm.py
Last active July 2, 2021 12:55
HMM on GPU with pytorch in 100 lines
'''
This proof-of-concept follows [PRML](https://www.microsoft.com/en-us/research/people/cmbishop/prml-book/)'s idea.
This code extends plain HMM in the way that it has different transition matrix and emission matrix on different features `xs`.
To get a normal HMM, you can set all `x` to the same.
`HMM.predict()` uses formula (13.44) in PRML, which considers the whole seen sequence of observation `y`s.
If you have no observed `y`s and only have `x`s, you can use `model.trans(x).view(T, N, self.H, self.H).softmax(dim=3)` as transition matrix to get predicted sequence.
`gamma` here represents posterior probability of hidden states.
'''
@yuq-1s
yuq-1s / income.py
Last active September 29, 2021 09:28
Comparing income of Beijing and Singapore.
import sys
import fire
class Beijing:
max_base = 28221
min_base = 5360
def __init__(self, total):
self.total = total
def wuxianyijin(self):
@yuq-1s
yuq-1s / cached.py
Created November 30, 2021 10:53
Utility function for caching middle results of Python
import gzip
import logging
import pickle
import time
import yaml
from tqdm import tqdm
def cached(cache_path):
def wrapper(func):