Skip to content

Instantly share code, notes, and snippets.

Avatar

Jinzhou Zhang lotabout

View GitHub Profile
@lotabout
lotabout / neural-network.py
Created Mar 14, 2018
implementation of backpropogation algorithm
View neural-network.py
#!/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 Mar 13, 2018
Experiment on logic regression
View logistic-regression-experiment.py
#!/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 Mar 9, 2018
Try to plot squared cost function for logistic regression, trying to prove that it is non-convex
View square-cost.py
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 Mar 15, 2018
Implement decision tree
View decision-tree.py
#!/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 Oct 5, 2017
Solution for google foobar: Expanding Nebula
View expanding_nebula.py
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 Jun 23, 2017
DWM like pane management for tmux
View tmux-tiled.py
#!/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 Mar 27, 2017
Infinite sequence of prime numbers in Clojure.
View primes.clj
; 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 Aug 4, 2017
Configuration for cVim (Chrome extension)
View cVimrc.vim
set autoupdategist
set smoothscroll
let scrollstep = 90
let scrollduration = 30
let barposition = "bottom"
" vimperator style follow link
let numerichints = 1
let typelinkhints = 1
View qr.py
#!/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]
@lotabout
lotabout / pod.py
Last active Dec 6, 2016
download the wallpaper from bing.com and set it as wallpaper, everyday.
View pod.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# You can put it into crontab
# * */2 * * * HOME=/home/<your username> DISPLAY=:0 <path to the script>
# it will run every two hours to check for new pictures.
from datetime import datetime
import urllib
import urllib2