Permalink
Browse files

adding column and row selectors to matrix.

  • Loading branch information...
1 parent a6a0713 commit ee9fa69f0b3dcdbb8b0bb1e33c2713aa017624dd Bradford committed Aug 28, 2010
Showing with 26 additions and 2 deletions.
  1. +1 −0 project.clj
  2. +25 −2 src/infer/matrix.clj
View
@@ -5,6 +5,7 @@
[clojure-csv/clojure-csv "1.1.0"]
[org.apache.commons/commons-math "2.0"]
[ujmp-complete "0.2.4"]
+ [org.apache.mahout/mahout-core "0.3"]
[colt/colt "1.2.0"]
[incanter/parallelcolt "0.9.4"]]
:dev-dependencies [[org.clojars.mmcgrana/lein-javac "0.1.0"]
View
@@ -7,6 +7,7 @@
(:import [org.ujmp.core.matrix Matrix2D])
(:import [org.ujmp.colt
ColtSparseDoubleMatrix2D])
+;; (:import [org.apache.mahout.core SparseMatrix])
(:import [org.ujmp.parallelcolt
ParallelColtSparseDoubleMatrix2D])
(:import [org.ujmp.core.doublematrix
@@ -68,6 +69,23 @@
(defn sparse-pcolt-matrix [xs]
(sparse-matrix* xs #(ParallelColtSparseDoubleMatrix2D. %)))
+;; (defn sparse-mahout-matrix [xs]
+;; (let [n-rows (count xs)
+;; cols (reduce (fn [acc row]
+;; (union acc (into #{} (keys row))))
+;; #{}
+;; xs)
+;; m (SparseMatrix. (long-array [n-rows (+ (apply max cols) 1)]))
+;; row-indices (range 0 (count xs))]
+;; (dorun
+;; (map (fn [row r]
+;; (dorun (map (fn [[c v]]
+;; (.setQuick m r c v)
+;; row)))
+;; xs
+;; row-indices))
+;; m)))
+
(defn from-sparse-matrix [m]
(map (fn [coord]
(conj (into [] (map int coord)) (.getDouble m coord)))
@@ -81,9 +99,9 @@
(defn column-matrix [ys]
(matrix (map vector ys)))
-(defn from-matrix [X]
+(defn from-matrix [A]
(map #(into [] %)
- (.toDoubleArray X)))
+ (.toDoubleArray A)))
(defn from-column-matrix [X]
(flatten (map #(into [] %)
@@ -216,6 +234,11 @@
(defn trans [#^DenseDoubleMatrix2D A]
(.transpose A))
+(def rows from-matrix)
+
+(defn columns [A]
+ (from-matrix (trans A)))
+
(defn svd [#^DenseDoubleMatrix2D A]
(.svd A))

0 comments on commit ee9fa69

Please sign in to comment.