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
(defn lazy-combine-sorted [xs ys] | |
"lazily combines xs and ys and returns their union (assumes xs ys sorted)" | |
(lazy-seq | |
(if-let [[x & xs*] xs] | |
(if-let [[y & ys*] ys] | |
(cond (= x y) (cons x (lazy-combine-sorted xs* ys*)) | |
(< x y) (cons x (lazy-combine-sorted xs* ys)) | |
(> x y) (cons y (lazy-combine-sorted xs ys*))) | |
xs) ; no more ys | |
ys))) ; no more xs |
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
(defn lazy-combine-sorted [xs ys] | |
"lazily combines xs and ys and returns their union (assumes xs ys sorted)" | |
(lazy-seq | |
(if-let [[x & xs*] xs] | |
(if-let [[y & ys*] ys] | |
(cond (= x y) (cons x (lazy-combine-sorted xs* ys*)) | |
(< x y) (cons x (lazy-combine-sorted xs* ys)) | |
(> x y) (cons y (lazy-combine-sorted xs ys*))) | |
xs) ; no more ys | |
ys))) ; no more xs |
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
(defn compute-metrics [[header lines]] | |
(loop [[ln & lns*] lines | |
features nil | |
experiments 0] | |
(printf "%d, %d\n" experiments (count features)) | |
(if (not ln) | |
(assoc header | |
:experiments experiments | |
:features features) | |
(recur lns* |
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
(defn lazy-combine-sorted [xs ys] | |
"lazily combines xs and ys and returns their union (assumes xs ys sorted)" | |
(if (empty? xs) ys) | |
(if (empty? ys) xs) | |
(lazy-seq | |
(if-let [[x & xs*] xs] | |
(if-let [[y & ys*] ys] | |
(cond (= x y) (cons x (lazy-combine-sorted xs* ys*)) | |
(< x y) (cons x (lazy-combine-sorted xs* ys)) | |
(> x y) (cons y (lazy-combine-sorted xs ys*))) |
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
(if (< a b) ;; either way | |
(recur a- b+ (conj acc a)) | |
(recur a+ b- (conj acc b)))))))) | |
(defn combine [A B] | |
(combine-sorted (sort A) (sort B))) |
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
(defn lazy-combine-sorted [xs ys] | |
"lazily combines xs and ys and returns their union (assumes xs ys sorted)" | |
(if (empty? xs) ys) | |
(if (empty? ys) xs) | |
(lazy-seq | |
(if-let [[x & xs*] xs] | |
(if-let [[y & ys*] ys] | |
(cond (= x y) (cons x (lazy-combine-sorted xs* ys*)) | |
(< x y) (cons x (lazy-combine-sorted xs* ys)) | |
(> x y) (cons y (lazy-combine-sorted xs ys*))) |
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
(defn lazy-combine-sorted [xs ys] | |
"lazily combines xs and ys and returns their union (assumes xs ys sorted)" | |
(lazy-seq | |
(if-let [[x & xs*] xs] | |
(if-let [[y & ys*] ys] | |
(cond (= x y) (cons x (lazy-combine-sorted xs* ys*)) | |
(< x y) (cons x (lazy-combine-sorted xs* ys)) | |
(> x y) (cons y (lazy-combine-sorted xs ys*))) | |
xs) ; no more ys | |
ys))) ; no more xs |
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
;; LibSVM Model Parser | |
(use 'clojure.contrib.duck-streams) | |
(use 'clojure.contrib.seq-utils) | |
(require '[clojure.contrib.str-utils2 :as s]) | |
(load "coll-util") | |
(def *root* "/Users/angerman/Downloads/libsvm-2.9-dense/tools/") |
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 clojure.contrib.duck-streams | |
(:import (java.io File RandomAccessFile))) | |
;; copied and adapted from c.c.ds | |
(defmulti #^{:arglist '([x])} random-access-reader class) | |
(defmethod random-access-reader File [#^File x] | |
(RandomAccessFile. x "r")) | |
(defmethod random-access-reader String [#^String x] | |
(random-access-reader (File. 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
(in-ns 'clojure.contrib.duck-streams) | |
(import '(java.io File RandomAccessFile)) | |
;; copied and adapted from c.c.ds | |
(defmulti #^{:arglist '([x])} random-access-reader class) | |
(defmethod random-access-reader File [#^File x] | |
(RandomAccessFile. x "r")) | |
(defmethod random-access-reader String [#^String x] | |
(random-access-reader (file-str x))) |