This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns forma.trends.analysis | |
(:use [forma.matrix.utils :only (variance-matrix coll-avg ones-column)] | |
[clojure.math.numeric-tower :only (sqrt floor abs expt)] | |
[forma.trends.filter :only (deseasonalize make-reliable hp-filter)] | |
[clojure-csv.core]) | |
(:require [forma.utils :as utils] | |
[incanter.core :as i] | |
[incanter.stats :as s])) | |
;; TODO (dan): move thest extra matrix functions somewhere else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys, json | |
import numpy as np | |
try: | |
#import matplotlib.pylab as plt | |
from scikits.timeseries.lib.interpolate import * | |
import scikits.statsmodels.sandbox.stats.diagnostic as diag | |
from scikits.statsmodels.tsa.filters import hpfilter | |
import scikits.statsmodels.api as sm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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`" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
OlderNewer