Skip to content

Instantly share code, notes, and snippets.

View lotabout's full-sized avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / DCWGAN.py
Created March 29, 2018 08:53
WGAN implementation
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch.nn as nn
import torch
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from torch.autograd import Variable, grad
import torch.optim as optim
import torchvision.utils as vutils
@lotabout
lotabout / neural-network.py
Created March 14, 2018 07:43
implementation of backpropogation algorithm
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# implementation of backpropogation algorithm based on
# http://neuralnetworksanddeeplearning.com/chap1.html
#
# note that mini-batches are calculated in matrix form
import numpy as np
import random
@lotabout
lotabout / logistic-regression-experiment.py
Last active March 13, 2018 02:48
Experiment on logic regression
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sklearn.datasets import load_iris
import numpy as np
import math
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.optimize import fmin_bfgs
@lotabout
lotabout / square-cost.py
Last active March 9, 2018 09:45
Try to plot squared cost function for logistic regression, trying to prove that it is non-convex
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import math
#==============================================================================
# Try to verify the cost function is non-convex
xs = np.random.rand(30)
ys = np.random.rand(30)
@lotabout
lotabout / decision-tree.py
Last active March 15, 2018 01:42
Implement decision tree
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
class DecisionTree(object):
def __init__(self, data, method="naive"):
"""Learn a decision tree from data and label
:data: List[List[val]], a list contains M sample, each sample is represented by a List
The last column of the sample is the label
@lotabout
lotabout / expanding_nebula.py
Created October 5, 2017 03:19
Solution for google foobar: Expanding Nebula
def generate(c1,c2,bitlen):
a = c1 & ~(1<<bitlen)
b = c2 & ~(1<<bitlen)
c = c1 >> 1
d = c2 >> 1
return (a&~b&~c&~d) | (~a&b&~c&~d) | (~a&~b&c&~d) | (~a&~b&~c&d)
from collections import defaultdict
def build_map(n, nums):
mapping = defaultdict(set)
@lotabout
lotabout / tmux-tiled.py
Created June 23, 2017 10:31
DWM like pane management for tmux
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import re
import json
import sys
from math import ceil
TMUX_BUFFER_NAME = 'dwm'
@lotabout
lotabout / primes.clj
Last active March 7, 2022 15:58
Infinite sequence of prime numbers in Clojure.
; Sieve of Eratosthenes
; Checkout https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
(def primes
(concat
[2]
(lazy-seq
(let [prime-inner
(fn prime-inner [x table]
(if (table x)
(prime-inner (inc x)
@lotabout
lotabout / cVimrc.vim
Last active August 4, 2017 01:28
Configuration for cVim (Chrome extension)
set autoupdategist
set smoothscroll
let scrollstep = 90
let scrollduration = 30
let barposition = "bottom"
" vimperator style follow link
let numerichints = 1
let typelinkhints = 1
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from PIL import Image
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]