Commit f3203d2d authored by Christian Weilbach's avatar Christian Weilbach

Fix tests, rename typo.

parent c45bd258
......@@ -206,10 +206,10 @@
:else
(let [[f & args] exp
new-*my-gensym*s (atom [])
new-gensyms (atom [])
nargs (map (fn [a] (if (term? a) a
(let [ng (*my-gensym* "v")]
(swap! new-*my-gensym*s conj ng)
(swap! new-gensyms conj ng)
ng))) args)
nexp (conj nargs f)
{:keys [forward backward]}
......@@ -237,7 +237,7 @@
;; initialize new variables with 0
(map (fn [a]
[(adjoint-sym a) 0])
@new-*my-gensym*s)))})))
@new-gensyms)))})))
(defn sensitivities [args]
......
......@@ -117,7 +117,9 @@
(deftest fnr-macro-test
(testing "Macro expension for reverse-diff macro."
(binding [*my-gensym* (local-gensym)]
(binding [*my-gensym* (local-gensym)
;; WTF, why do i need this namespace binding? works in REPL without
*ns* (find-ns 'foppl-compiler.reverse-diff)]
(is (= '(fn [x y]
(let [v2 (* x x) v1 (+ v2)]
[v1 (fn [v1_]
......@@ -151,33 +153,34 @@
(deftest foppl-examples-test
(testing "Testing examples from the lecture."
(is (check-gradient '(fn [x] (exp (sin x))) [3.2]))
(binding [*ns* (find-ns 'foppl-compiler.reverse-diff)]
(is (check-gradient '(fn [x] (exp (sin x))) [3.2]))
(is (check-gradient '(fn [x y] (+ (* x x) (sin x))) [5.1 8.7]))
(is (check-gradient '(fn [x y] (+ (* x x) (sin x))) [5.1 8.7]))
(is (check-gradient '(fn [x] (if (> x 5) (* x x) (+ x 18))) [3]))
(is (check-gradient '(fn [x] (if (> x 5) (* x x) (+ x 18))) [3]))
(is (check-gradient '(fn [x] (if (> x 5) (* x x) (+ x 18))) [6]))
(is (check-gradient '(fn [x] (if (> x 5) (* x x) (+ x 18))) [6]))
(is (check-gradient '(fn [x] (log x)) [2.7]))
(is (check-gradient '(fn [x] (log x)) [2.7]))
(is (check-gradient '(fn [x mu sigma]
(+ (- 0 (/ (* (- x mu) (- x mu))
(* 2 (* sigma sigma))))
(* (- 0 (/ 1 2)) (log (* 2 (* 3.141592653589793 (* sigma sigma)))))))
[3.1 -2.5 8]))
(is (check-gradient '(fn [x mu sigma]
(+ (- 0 (/ (* (- x mu) (- x mu))
(* 2 (* sigma sigma))))
(* (- 0 (/ 1 2)) (log (* 2 (* 3.141592653589793 (* sigma sigma)))))))
[3.1 -2.5 8]))
(is (check-gradient '(fn [x mu sigma] (normpdf x mu sigma)) [3.1 -2.5 8]))
(is (check-gradient '(fn [x mu sigma] (normpdf x mu sigma)) [3.1 -2.5 8]))
(is (check-gradient '(fn [x1 x2 x3] (+ (+ (normpdf x1 2 5)
(if (> x2 7)
(normpdf x2 0 1)
(normpdf x2 10 1)))
(normpdf x3 -4 10)))
[1.2 2.1 4]))
(is (check-gradient '(fn [x1 x2 x3] (+ (+ (normpdf x1 2 5)
(if (> x2 7)
(normpdf x2 0 1)
(normpdf x2 10 1)))
(normpdf x3 -4 10)))
[1.2 2.1 4]))
))
)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment