Skip to content
Browse files

Added factorization tests

1 parent 6132aae commit 9849325a27770794b91415592a8706fd90777469 Aria Haghighi committed
Showing with 26 additions and 0 deletions.
  1. +26 −0 test/infer/matrix_factorization_test.clj
View
26 test/infer/matrix_factorization_test.clj
@@ -0,0 +1,26 @@
+(ns infer.matrix-factorization-test
+ (:use clojure.test
+ [infer.matrix :only [matrix I times]]
+ infer.matrix-factorization))
+
+(defn- near-zero [x]
+ (< (Math/abs x) 1.0e-8))
+
+(deftest frobenius-error-test
+ (let [A (matrix [[1 1] [1 1]])
+ B (matrix [[2 2] [2 2]])
+ C (times A B)]
+ (is (near-zero (frobenius-error C A B)))))
+
+(defn decreasing-seq? [xs]
+ (every?
+ (fn [[x y]] (> x y))
+ (partition 2 1 xs)))
+
+(deftest lee-seung-factorization-test
+ (let [M (I 50 50) k 20
+ err-seq
+ (for [iters [1 10 100]]
+ (let [[X Y] (lee-seung-factorize M k {:num-iters iters})]
+ (frobenius-error M X Y)))]
+ (is (decreasing-seq? err-seq))))

0 comments on commit 9849325

Please sign in to comment.
Something went wrong with that request. Please try again.