Skip to content

Commit

Permalink
test: Test ensembles using conditioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaechtle committed Jan 24, 2024
1 parent ba64d87 commit 9e06dd3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/inferenceql/inference/gpm/ensemble_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:require [inferenceql.inference.test-models.crosscat :as crosscat]
[clojure.test :refer [deftest is]]
[inferenceql.inference.gpm :as gpm]
[inferenceql.inference.gpm.ensemble :as ensemble]))
[inferenceql.inference.gpm.ensemble :as ensemble]
[inferenceql.inference.gpm.conditioned :as conditioned]))

(def models (ensemble/ensemble [crosscat/model crosscat/model]))

Expand All @@ -26,5 +27,19 @@
;; test Bayes' Rule
(is (= (+ x-given-y y) x-and-y)))))

#?(:clj (deftest condition
(let [x-and-y (gpm/logpdf models {:color "red" :height 0.4} {})
x-given-y (gpm/logpdf (gpm/condition models {:height 0.4}) {:color "red"} {})
x-given-y-indep-z (gpm/logpdf (gpm/condition (gpm/condition models {:height 0.4}) {:flip true}) {:color "red"} {})
x-given-indep-z-y (gpm/logpdf (gpm/condition (gpm/condition models {:flip true}) {:height 0.4}) {:color "red"} {})
y (gpm/logpdf models {:height 0.4} {})]
(is (number? x-and-y))
(is (number? x-given-y))
(is (number? y))
;; test Bayes' Rule
(is (= (+ x-given-y y) x-and-y))
(is (= (+ x-given-y-indep-z y) x-and-y))
(is (= (+ x-given-indep-z-y y) x-and-y)))))

(deftest variables
(is (= #{:color :height :flip} (gpm/variables models))))

0 comments on commit 9e06dd3

Please sign in to comment.