Browse files

more empty doc-strings for autodoc.

  • Loading branch information...
liebke committed Dec 19, 2009
1 parent 5008cd2 commit 0ecd289e43304698922164ca8cdfae8078086219
@@ -12,7 +12,9 @@ incanter.classification
(:use [incanter.probability :only [bucket +cond-prob-tuples]])
(:use [incanter.internal :only [safe threshold-to]]))
-(defn classifier [fns classify]
+(defn classifier
+[fns classify]
(fn [data]
(classify fns data)))
@@ -30,8 +32,13 @@ incanter.classification
(for [feature features]
[feature feature])))
-(defn category-classifier [x] {x 1})
+(defn category-classifier
+ {x 1})
(defn category-map-classifier
([x] (map-map category-classifier x))
([s x] (category-map-classifier (into {} (filter #(contains? s (key %)) x)))))
@@ -128,7 +135,9 @@ usage:
(into {} (for [[k v] class-mappings]
(into {} (for [equiv v] [equiv k])))))
-(defn merge-levels [class-mappings coll]
+(defn merge-levels
+[class-mappings coll]
#(apply deep-merge-with + (map second %))
@@ -201,8 +210,9 @@ usage:
[k2 v2]))
m)] k))
-(defn confusion-matrix [trd tst]
+(defn confusion-matrix
"computes a confusion matrix from the counts on train and test data sets represented as maps. traverse you get to the point of counts of actuals, replace the series of nested keys that lead to that point with the single key of the predicted"
+[trd tst]
(apply deep-merge-with +
((fn each-level [tr ts]
@@ -218,17 +228,19 @@ usage:
(each-level {} v)))))
trd tst))))
-(defn precision [m]
+(defn precision
"computes precision by class label from confusion matrix."
(into {}
(for [[k v] m
:let [predicted (v k)]
:when (not (= k :no-prediction))]
[k (float (/ (if predicted predicted 0)
(apply + (vals v))))])))
-(defn recall [m]
+(defn recall
"computes recall by class label from confusion matrix."
(into {}
(for [k (all-keys m)
:let [v-predicted (m k)]
@@ -267,30 +279,41 @@ merges the resulting n cross-validation matrices into a single matrix.
x (remove #{x} xs)))))
-(defn n-times-k-fold-cross-validation-confusion-matrix [list-of-lists]
+(defn n-times-k-fold-cross-validation-confusion-matrix
(apply deep-merge-with +
(map (partial apply cross-validation-confusion-matrix)
-(defn map-of-vectors [keys]
+(defn map-of-vectors
(into {}
(map (fn [k] [k []]) keys)))
-(defn vectorize [maps]
+(defn vectorize
(map-of-vectors (all-keys maps)))
-(defn collect-vals [maps]
+(defn collect-vals
"(collect-vals [{:a 1 :b 2} {:a 4 :b 5} {:c 4} {:c 5}]) > {:b [2 5], :c [4 5], :a [1 4]}"
(apply merge-with conj
(cons (vectorize maps) maps)))
-(defn prob-map-tuples-by-time [prob-map-tuple]
+(defn prob-map-tuples-by-time
"use to transform data for confusion matrix by time before departure"
(into {}
(for [[k v] (first prob-map-tuple)]
[k [v ((second prob-map-tuple) k)]])))
-(defn confusion-matrix-by-time [results]
+(defn confusion-matrix-by-time
(let [results-by-time (collect-vals
(map prob-map-tuples-by-time results))]
(into {}
@@ -11,10 +11,13 @@
;; \operatorname{Cov}(X_i, X_j) = \operatorname{E}\left((X_i-\operatorname{E}(X_i))(X_j-\operatorname{E}(X_j))\right) = \operatorname{E}(X_iX_j) -\operatorname{E}(X_i)\operatorname{E}(X_j)
-(defn mean-state [x val queue]
+(defn mean-state
+[x val queue]
[(+ val (/ (- x (peek queue)) (count queue))) (conj (pop queue) x)])
-(defn mean-state-2 [x val queue]
+(defn mean-state-2
+[x val queue]
(let [m (+ val (/ (- x (peek queue)) (count queue)))]
[m #(mean-state-2 %1 m (conj (pop queue) x))]))
@@ -31,11 +34,14 @@
;; [4 #<test$mean_state_2__1717$fn__1719 test$mean_state_2__1717$fn__1719@1854b38>]
;; test>
-(defn update-sample [x]
+(defn update-sample
(update-val :sample #(conj (pop %) x)))
;;Monad spike for stateful rolling stats
(defn update-mean
(domonad state-m
[sample (fetch-val :sample)
@@ -56,7 +62,10 @@
;; ((update-mean 4 5 6) a-state)
-(defn tuplize-apply [f] (fn [x] [(f x) f]))
+(defn tuplize-apply
+ (fn [x] [(f x) f]))
;; (defn rolling-mean [l k]
;; (let [rm (RollingMean. l)]
@@ -111,15 +111,20 @@
(let [data-lines (map seq (seq (.readAll reader)))
- raw-data (filter #(> (count %) 0) (map (fn [line] (filter #(not= % "") line)) data-lines))
- parsed-data (into [] (map (fn [row] (into [] (map parse-string row))) raw-data))
+ raw-data (filter #(> (count %) 0)
+ (map (fn [line] (filter #(not= % "") line))
+ data-lines))
+ parsed-data (into [] (map (fn [row] (into [] (map parse-string row)))
+ raw-data))
(if header?
; have header row
(dataset (first parsed-data) (rest parsed-data))
; no header row so build a default one
(let [col-count (count (first parsed-data))
- col-names (apply vector (map str (repeat col-count "col") (iterate inc 0)))]
+ col-names (apply vector (map str
+ (repeat col-count "col")
+ (iterate inc 0)))]
(dataset col-names parsed-data))))))))
@@ -175,53 +180,71 @@
(.close file-writer))))
-(defn read-map [& keys]
+(defn read-map
+[& keys]
(into {} (for [k keys] [k (comp eval read-string)])))
-(defn string-date-read-map [& keys]
+(defn string-date-read-map
+[& keys]
(into {} (for [k keys] [k joda-date])))
-(defn read-json-file [f]
+(defn read-json-file
(decode-from-reader (reader f)))
;;todo if we want this process to be lazy we can remove the doall.
-(defn read-json-lines [f]
+(defn read-json-lines
(for [l (read-lines f)] (decode-from-str l))))
;;TODO: switch back to stream impl?
-(defn clj-to-json-file [c f]
+(defn clj-to-json-file
+[c f]
(spit (File. f)
(encode-to-str c)))
;;doesn't work in maven builds. must use fn below.
;;(ClassLoader/getSystemResource f)))))
-(defn load-resource [f]
+(defn load-resource
(class *ns*)) f))
-(defn read-from-classpath [f]
+(defn read-from-classpath
(reader (load-resource f)))
-(defn json-from-classpath [f]
+(defn json-from-classpath
(decode-from-reader (read-from-classpath f)))
(def report-model (comp pprint sort-map-of-maps model-from-maps))
-(defn package-model [file prob-map-tuple]
+(defn package-model
+[file prob-map-tuple]
(clj-to-json-file (model-from-maps prob-map-tuple) file))
-(defn unpackage-model [file]
+(defn unpackage-model
(read-json-file file))
-(defn into-file [filename stuff]
+(defn into-file
+[filename stuff]
(let [f (file filename)]
(spit f stuff)))
-(defn csv-line [v]
+(defn csv-line
"turn a vector into a csv line"
(let [commas (repeat (- (count v) 1) ", ")
;;the seperated list must be a vector so that conj appends
;;conj prepends for list type.
@@ -230,8 +253,9 @@
cells (conj seperated (str tail "\n"))]
(apply str cells)))
-(defn csv-table [m]
+(defn csv-table
"turn a 2-level map into a csv table"
(let [column-names (all-keys (vals m))
rows (for [[k v] m]
(cons k
@@ -263,17 +287,41 @@ example dbinfo:
(with-connection db
(with-query-results rs [query] (f rs)))))
-(defn sql-query [d q]
+(defn sql-query
+[d q]
(let [printer #(println (:internaluage :iso_code %))]
(with-mysql-results d q
#(dorun (map printer %)))))
-(defn query [table sample & columns] (str "select " (str-join ", " columns) " from " table " limit " sample))
-(defn sql-select [& x] (str-join " " (cons "select" x)))
+(defn query
+[table sample & columns]
+ (str "select " (str-join ", " columns)
+ " from " table
+ " limit " sample))
+(defn sql-select
+[& x]
+ (str-join " " (cons "select" x)))
(def sql-from #(str "from " %))
(def sql-unique #(str "distinct " %))
(def sql-limit #(str "limit " %))
(def random-row "order by rand()")
-(defn sql-order-by [c] (str "order by " c))
-(defn sql-where [pred] (str "where " pred))
-(defn columns [& x] (str-join ", " x))
+(defn sql-order-by
+ (str "order by " c))
+(defn sql-where
+ (str "where " pred))
+(defn columns
+[& x]
+ (str-join ", " x))
@@ -14,12 +14,15 @@ a function for binary classification that takes a booleavn value and returns 1 f
[pred] (if pred 1 0))
-;;set based counting for keys in maps
-(defn count-missing [exp act]
+(defn count-missing
+"set based counting for keys in maps"
+[exp act]
(let [diff (difference exp (keys act))]
(set-to-unit-map diff)))
-(defn rolling-windows [len] (fn [col] (partition len 1 col)))
+(defn rolling-windows
+ (fn [col] (partition len 1 col)))
(defn map-counter
@@ -60,8 +63,9 @@ wraps a counting function for vectors in apply and deep-merge-with, curreid fn e
(map summate (vals m))))))
-(defn summate-level [j]
+(defn summate-level
"given a nested map, summates all counts below the tree from each key-node in the map-tree."
(assert (not (bottom-level? j)))
(map-map summate j))
@@ -97,7 +101,8 @@ for summation note that a variable, suppose it is x, is represented as a level o
;; (recur next (+ 1 level))))
;; j 0))
-(defn n-sided-die [n]
+(defn n-sided-die
(apply hash-map
(interleave (range 1 (+ n 1) 1)
(repeat n 1))))
@@ -187,5 +192,6 @@ classify one item based on what interval in a range the item falls into.
[k (cond-prob-tuple (a obs) (b obs))]))))
(defn P
([a given b & bs] (given a (cons b bs)))
([a given b] (given a (if (coll? b) b [b]))))

0 comments on commit 0ecd289

Please sign in to comment.