Skip to content

Instantly share code, notes, and snippets.

View danhammer's full-sized avatar

Dan danhammer

View GitHub Profile
@danhammer
danhammer / logistic.clj
Created January 16, 2012 23:20
logistic, ridge classifier
(ns forma.source.logistic
(:use [clojure.math.numeric-tower :only (sqrt floor abs expt)]
[clojure-csv.core])
(:require [incanter.core :as i]))
(defn feature-vec
[n]
(map (partial cons 1)
(for [x (range n)]
(take 22 (repeatedly rand)))))
@danhammer
danhammer / logistic.py
Created January 16, 2012 23:39
logistic, ridge classifier
def logistic_regression(x,
y,
rdg_cons = 1.e-6,
verbose=False,
conv_thresh=1.e-8,
maxit=500):
"""Calculates the maximum likelihood estimates of a logistic
regression. Uses the [Newton-Raphson algorithm]
(sites.stat.psu.edu/~jiali/course/stat597e/notes2/logit.pdf)
@danhammer
danhammer / gist:1627807
Created January 17, 2012 17:49
timing matrix multiplication
(ns forma.source.logistic
(:require [incanter.core :as i]))
(defn feature-vec
[n]
(map (partial cons 1)
(for [x (range n)]
(take 22 (repeatedly rand)))))
(defn dot-product
@danhammer
danhammer / gist:1627819
Created January 17, 2012 17:52
timing matrix multiplication
import numpy as np
def test_my_mult(n):
A = np.random.rand(n*23).reshape(n,23)
At = A.T
t0 = time.time()
res = np.dot(A.T, A)
print time.time() - t0
print np.shape(res)
@danhammer
danhammer / trends.clj
Created January 18, 2012 06:53
trends
@danhammer
danhammer / trends.py
Created January 18, 2012 06:54
trends
@danhammer
danhammer / logistic.clj
Created January 19, 2012 02:19
logistic, ridge classifier
(ns forma.source.logistic
(:use [forma.utils :only (dot-product transpose multiply-rows)]
[clojure.contrib.math :only (abs)])
(:require [incanter.core :as i])
(:import [org.jblas FloatMatrix MatrixFunctions Solve DoubleMatrix]))
;; TODO: correct for error induced by ridge
(defn logistic-fn
"returns the value of the logistic function, given input `x`"
@danhammer
danhammer / gist:1691694
Created January 28, 2012 00:05
trend analysis in python and r
def convert_ts(time_series, start_year=2000, start_pd=4, freq=23):
"""
Convert a numpy time-series into an rpy2 object, which, in turn,
is a 'ts' object in R. The 'ts' object is more wholly specified
if a start date is provided. For our applications at 16-day
intervals for NDVI, this start date is April 2000, with a
frequency of 23 observations each year.
input: numpy time-series
output: rpy2 ts object
@danhammer
danhammer / logistic.clj
Created February 8, 2012 23:09
logistic, ridge classifier
(ns forma.classify.logistic
(:use [forma.utils]
[clojure.math.numeric-tower :only (abs)]
[forma.matrix.utils]
[cascalog.api])
(:require [incanter.core :as i])
(:import [org.jblas FloatMatrix MatrixFunctions Solve DoubleMatrix]))
;; TODO: correct for error induced by ridge
@danhammer
danhammer / cluster-queries.clj
Created March 7, 2012 20:15
cascalog queries for final clearing probabilities
(ns forma.hadoop.jobs.forma
(:use cascalog.api)
(:require [cascalog.ops :as c]
[forma.trends.analysis :as a]
[forma.classify.logistic :as log]))
(def get-loc
(<- [?chunk :> ?s-res ?mod-h ?mod-v ?sample ?line ?val]
(map ?chunk [:location :value] :> ?loc ?val)
(schema/unpack-pixel-location ?loc :> ?s-res ?mod-h ?mod-v ?sample ?line)))