|
7 | 7 | [gen.dynamic.choice-map :as choice-map] |
8 | 8 | [gen.generative-function :as gf] |
9 | 9 | [gen.trace :as trace] |
10 | | - [gen.test-check-util :refer [gen-double]] |
11 | | - [same.core :refer [ish? zeroish?]])) |
| 10 | + [gen.test-check-util :refer [gen-double within]] |
| 11 | + [same.core :refer [ish? zeroish? with-comparator]])) |
12 | 12 |
|
13 | 13 | (defn gamma-tests [->gamma] |
14 | 14 | (testing "spot checks" |
15 | 15 | (is (= -6.391804444241573 (dist/logpdf (->gamma 0.001 1) 0.4))) |
16 | 16 | (is (= -393.0922447210179 (dist/logpdf (->gamma 1 0.001) 0.4))))) |
17 | 17 |
|
| 18 | +(defn student-t-tests [->student-t] |
| 19 | + (testing "spot checks" |
| 20 | + (with-comparator (within 1e-12) |
| 21 | + (is (ish? -1.7347417805005154 (dist/logpdf (->student-t 2 2.1 2) 2))) |
| 22 | + (is (ish? -2.795309741614719 (dist/logpdf (->student-t 1 0.8 4) 3))))) |
| 23 | + |
| 24 | + (checking "Student's T matches generalized logpdf" |
| 25 | + [v (gen-double -10 10) |
| 26 | + nu (gen/fmap inc gen/nat)] |
| 27 | + (is (= (dist/logpdf (->student-t nu 0 1) v) |
| 28 | + (dist/logpdf (->student-t nu) v)) |
| 29 | + "these two paths should produce the same results"))) |
| 30 | + |
18 | 31 | (defn beta-tests [->beta] |
19 | 32 | (testing "spot checks" |
20 | 33 | (is (= -5.992380837839856 (dist/logpdf (->beta 0.001 1) 0.4))) |
|
161 | 174 | (dist/logpdf (->normal 0.0 sigma) (- v))) |
162 | 175 | "Normal is symmetric about the mean") |
163 | 176 |
|
164 | | - (is (ish? (dist/logpdf (->normal mu sigma) v) |
165 | | - (dist/logpdf (->normal (+ mu shift) sigma) (+ v shift))) |
166 | | - "shifting by the mean is a symmetry")) |
| 177 | + (with-comparator (within 1e-12) |
| 178 | + (is (ish? (dist/logpdf (->normal mu sigma) v) |
| 179 | + (dist/logpdf (->normal (+ mu shift) sigma) (+ v shift))) |
| 180 | + "shifting by the mean is a symmetry"))) |
167 | 181 |
|
168 | 182 | (testing "spot checks" |
169 | 183 | (is (= -1.0439385332046727 (dist/logpdf (->normal 0 1) 0.5))) |
|
0 commit comments