-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Test importance sampling with a model and constraints resulting…
… in samples with weight 0 This crashed previously.
- Loading branch information
1 parent
d4c5152
commit 4d2538e
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns gen.inference.importance-test | ||
(:require [clojure.test :refer [deftest is testing]] | ||
[gen.choicemap :as choicemap :refer [choicemap get-value]] | ||
[gen.distribution.commons-math :as dist] | ||
[gen.dynamic :as dynamic :refer [gen]] | ||
[gen.inference.importance :as importance] | ||
[gen.trace :as trace])) | ||
|
||
(def model-causing-rejection-sampling | ||
(gen | ||
[] | ||
(if (dynamic/trace! :foo dist/bernoulli 0.5) | ||
(dynamic/trace! :bar dist/bernoulli 1.0) | ||
(dynamic/trace! :bar dist/bernoulli 0.0)))) | ||
|
||
(deftest rejection | ||
(testing "Robustness in the presence of importance samples with weight log(0)." | ||
(is {:foo true :bar true} | ||
;; Needs a couple of samples to trigger previous bug here. | ||
(-> (importance/resampling model-causing-rejection-sampling [] (choicemap {:bar true}) 10) | ||
(:trace) | ||
(trace/get-choices) | ||
(get-value))))) |