{{ message }}

Instantly share code, notes, and snippets.

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
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
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)
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
Created Oct 5, 2017
Solution for google foobar: Expanding Nebula
View expanding_nebula.py
 def generate(c1,c2,bitlen): a = c1 & ~(1<> 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)
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'
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)
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
Created Jan 3, 2017
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]
Last active Dec 6, 2016