|
1 | 1 | (ns gensql.inference.gpm.crosscat-test
|
2 |
| - (:require [gensql.inference.test-models.crosscat :refer [model]] |
3 |
| - [clojure.test :refer [deftest is]] |
| 2 | + (:require [gensql.inference.test-models.crosscat :refer [model str-model]] |
| 3 | + [clojure.test :refer [deftest is testing]] |
4 | 4 | [gensql.inference.gpm :as gpm]))
|
5 | 5 |
|
6 | 6 | (deftest simulate
|
7 |
| - (let [sim-no-constraint (gpm/simulate model [:color :height :flip] {}) |
8 |
| - sim-constraint-not-target (gpm/simulate model [:color] {:height 0.4}) |
9 |
| - sim-constraints-are-target (gpm/simulate model [:color :height] {:color "blue" :height 0.4})] |
10 |
| - ;; Simply checking that we generated all columns without error. |
11 |
| - (is (= #{:color :height :flip} (set (keys sim-no-constraint)))) |
12 |
| - (is (= #{:color} (set (keys sim-constraint-not-target)))) |
13 |
| - (is (= "blue" (:color sim-constraints-are-target))) |
14 |
| - (is (= 0.4 (:height sim-constraints-are-target))))) |
| 7 | + (testing "keyword" |
| 8 | + (let [sim-no-constraint (gpm/simulate model [:color :height :flip] {}) |
| 9 | + sim-constraint-not-target (gpm/simulate model [:color] {:height 0.4}) |
| 10 | + sim-constraints-are-target (gpm/simulate model [:color :height] {:color "blue" :height 0.4})] |
| 11 | + ;; Simply checking that we generated all columns without error. |
| 12 | + (is (= #{:color :height :flip} (set (keys sim-no-constraint)))) |
| 13 | + (is (= #{:color} (set (keys sim-constraint-not-target)))) |
| 14 | + (is (= "blue" (:color sim-constraints-are-target))) |
| 15 | + (is (= 0.4 (:height sim-constraints-are-target))))) |
| 16 | + |
| 17 | + (testing "string" |
| 18 | + (let [sim-no-constraint (gpm/simulate str-model ["color" "height" "flip"] {}) |
| 19 | + sim-constraint-not-target (gpm/simulate str-model ["color"] {"height" 0.4}) |
| 20 | + sim-constraints-are-target (gpm/simulate str-model ["color" "height"] {"color" "blue" "height" 0.4})] |
| 21 | + ;; Simply checking that we generated all columns without error. |
| 22 | + (is (= #{"color" "height" "flip"} (set (keys sim-no-constraint)))) |
| 23 | + (is (= #{"color"} (set (keys sim-constraint-not-target)))) |
| 24 | + (is (= "blue" (get sim-constraints-are-target "color"))) |
| 25 | + (is (= 0.4 (get sim-constraints-are-target "height")))))) |
15 | 26 |
|
16 | 27 | (deftest logpdf
|
17 |
| - (let [no-constraints (gpm/logpdf model {:color "red" :height 4.0 :flip true} {}) |
18 |
| - constraints-match-target (gpm/logpdf model {:color "red" :height 4.0} {:color "red" :height 4.0}) |
19 |
| - mistmatch (gpm/logpdf model |
20 |
| - {:color "red" :height 4.0 :flip true} {:color "blue" :height 4.0 :flip true}) |
21 |
| - match-subset (gpm/logpdf model |
22 |
| - {:color "red" :height 4.0} {:color "red" :flip true}) |
23 |
| - nonmatch-subset (gpm/logpdf model |
24 |
| - {:height 4.0} {:color "red" :flip true}) |
25 |
| - no-target (gpm/logpdf model |
26 |
| - {} {:color "red" :height 4.0 :flip true}) |
27 |
| - fully-constrained-target (gpm/logpdf model |
28 |
| - {:color "red" :height 4.0} {:color "red" :height 4.0 :flip true})] |
29 |
| - (is (number? no-constraints)) |
30 |
| - (is (= 0.0 constraints-match-target)) |
31 |
| - (is (= ##-Inf mistmatch)) |
32 |
| - (is (= match-subset nonmatch-subset)) |
33 |
| - (is (= no-target fully-constrained-target 0.0)))) |
| 28 | + (testing "keyword" |
| 29 | + (let [no-constraints (gpm/logpdf model {:color "red" :height 4.0 :flip true} {}) |
| 30 | + constraints-match-target (gpm/logpdf model {:color "red" :height 4.0} {:color "red" :height 4.0}) |
| 31 | + mistmatch (gpm/logpdf model |
| 32 | + {:color "red" :height 4.0 :flip true} {:color "blue" :height 4.0 :flip true}) |
| 33 | + match-subset (gpm/logpdf model |
| 34 | + {:color "red" :height 4.0} {:color "red" :flip true}) |
| 35 | + nonmatch-subset (gpm/logpdf model |
| 36 | + {:height 4.0} {:color "red" :flip true}) |
| 37 | + no-target (gpm/logpdf model |
| 38 | + {} {:color "red" :height 4.0 :flip true}) |
| 39 | + fully-constrained-target (gpm/logpdf model |
| 40 | + {:color "red" :height 4.0} {:color "red" :height 4.0 :flip true})] |
| 41 | + (is (number? no-constraints)) |
| 42 | + (is (= 0.0 constraints-match-target)) |
| 43 | + (is (= ##-Inf mistmatch)) |
| 44 | + (is (= match-subset nonmatch-subset)) |
| 45 | + (is (= no-target fully-constrained-target 0.0)))) |
| 46 | + |
| 47 | + (testing "string" |
| 48 | + (let [no-constraints (gpm/logpdf str-model {"color" "red" "height" 4.0 "flip" true} {}) |
| 49 | + constraints-match-target (gpm/logpdf str-model {"color" "red" "height" 4.0} {"color" "red" "height" 4.0}) |
| 50 | + mistmatch (gpm/logpdf str-model |
| 51 | + {"color" "red" "height" 4.0 "flip" true} {"color" "blue" "height" 4.0 "flip" true}) |
| 52 | + match-subset (gpm/logpdf str-model |
| 53 | + {"color" "red" "height" 4.0} {"color" "red" "flip" true}) |
| 54 | + nonmatch-subset (gpm/logpdf str-model |
| 55 | + {"height" 4.0} {"color" "red" "flip" true}) |
| 56 | + no-target (gpm/logpdf str-model |
| 57 | + {} {"color" "red" "height" 4.0 "flip" true}) |
| 58 | + fully-constrained-target (gpm/logpdf str-model |
| 59 | + {"color" "red" "height" 4.0} {"color" "red" "height" 4.0 "flip" true})] |
| 60 | + (is (number? no-constraints)) |
| 61 | + (is (= 0.0 constraints-match-target)) |
| 62 | + (is (= ##-Inf mistmatch)) |
| 63 | + (is (= match-subset nonmatch-subset)) |
| 64 | + (is (= no-target fully-constrained-target 0.0))))) |
34 | 65 |
|
35 | 66 | (deftest variables
|
36 |
| - (is (= #{:color :height :flip} (gpm/variables model)))) |
| 67 | + (is (= #{:color :height :flip} (gpm/variables model))) |
| 68 | + (is (= #{"color" "height" "flip"} (gpm/variables str-model)))) |
0 commit comments