Skip to content

Instantly share code, notes, and snippets.

@oskarth
oskarth / gist:3259872
Created August 4, 2012 20:56
Golang Concurrency
// Concurrency in Go
// ----------------------------------------------------------------
// several processes running at the same time
// dealing with lots of things at once (connections, computations)
// long live Murphy's^H^H^H^H^H^H^HMoore's law!
// Three things: execution, syncing/messaging and control flow
// 1) GOROUTINES
// ----------------------------------------------------------------
@oskarth
oskarth / gist:3469830
Created August 25, 2012 19:30
Intro to gradient descent, and why feature scaling leads to better convergence
ml gives computers ability to learn without being explicitly programmed.
# Linear Regression
linear regression is a simple model to find best for for data.
http://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Linear_regression.svg/400px-Linear_regression.svg.png
view above x and y axis as features, generalize to n-dimensional.
# Example
You have a data set with commute and sleep time, salary and happiness (1-10)
for the three features, commute, sleep and salary you want to predict happy
@oskarth
oskarth / gist:3469833
Created August 25, 2012 19:30
Intro to gradient descent, and why feature scaling leads to better convergence

Machine learning gives computers the ability to learn without being explicitly programmed.

Linear Regression

Linear regression is a simple model to find best fit for some data.

Example: You have a data set with commute time, sleep time, salary and happiness (1-10). For the three features - commute time, sleep time and salary - you want to predict happiness level.

Cost function and finding a good fit

How well does this line predict the data? Cost function (essentially sum of deltas between a line at a point and the real point) which we want to minimize. Once function converges we know we have a good fit. How do we find it? Gradient descent.

(ns chipper.core
(:use [clojure.contrib.combinatorics :only (selections)])
(:use [clojure.pprint :only (pprint)])
(:require [clojure.tools.macro :as macro]))
(defn bool-space
"Generates every possible boolean n-tuple."
[n]
(selections [0 1] n))
@oskarth
oskarth / core.clj
Created November 1, 2012 17:31
chipper.core
(defn- arrow?
"predicate that returns true if x is =>"
[x]
(and (symbol? x) (= (name x) "=>")))
(defn- split-body
"splits expression into two parts, one with input
pins and the other with => and outputs"
[body]
(split-with (complement arrow?) body))
@oskarth
oskarth / gates.clj
Created November 1, 2012 17:45
chipper.gates
;; nand* is not defined in terms of other gates
;; read the source to find out how we deal with that
(defgate not* [in] => [out]
(nand* [in in] => [out]))
(defgate and* [a b] => [out]
(nand* [a b] => [w])
(not* [w] => [out]))
@oskarth
oskarth / long.clj
Created November 1, 2012 18:07
chipper.long-form.gates
(defn nand* [a b]
(let [[out] (if (= 2 (+ a b)) [0] [1])
out))
(defn not* [in]
(let [[out] (nand* in in)]
out))
(defn and* [a b]
(let [[w] (nand* a b)
@oskarth
oskarth / stacktrace
Created December 5, 2012 19:55
clojurescript reflex computed-observables
;; using reflex clojurescript library
;; works
(def a (atom 0))
(def b (computed-observable (inc @a)))
(def c (computed-observable (dec @a)))
(def d (computed-observable (str @b)))
;; doesn't
;; maximum call stack exceeded
$ znc --version
ZNC 0.206+deb1 - http://znc.in
$ which znc
/usr/local/bin/znc
$ /usr/local/bin/znc --version
ZNC 1.1-git-20121207-8ffab186 - http://znc.in
IPv6: yes, SSL: yes, DNS: threads
@oskarth
oskarth / gist:4260501
Created December 11, 2012 17:33
minikanren break
#lang r5rs
;; chapter 3 minikanren
(define-syntax var
(syntax-rules ()
((_ x) (vector x))))
(define-syntax var? (syntax-rules ()
((_ x) (vector? x))))