Skip to content

Commit

Permalink
test: (WIP) test poisson logpdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaechtle committed Apr 2, 2024
1 parent 103dbfb commit 0b0b6bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/inferenceql/inference/gpm.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[inferenceql.inference.gpm.primitive-gpms.bernoulli :as bernoulli]
[inferenceql.inference.gpm.primitive-gpms.categorical :as categorical]
[inferenceql.inference.gpm.primitive-gpms.gaussian :as gaussian]
[inferenceql.inference.gpm.primitive-gpms.poisson :as poisson]
[inferenceql.inference.gpm.proto :as gpm-proto]
[inferenceql.inference.gpm.view :as view]))

Expand Down Expand Up @@ -152,6 +153,7 @@
'inferenceql.inference.gpm.primitive_gpms.bernoulli.Bernoulli bernoulli/map->Bernoulli
'inferenceql.inference.gpm.primitive_gpms.categorical.Categorical categorical/map->Categorical
'inferenceql.inference.gpm.primitive_gpms.gaussian.Gaussian gaussian/map->Gaussian
'inferenceql.inference.gpm.primitive_gpms.poisson.Poisson poisson/map->Poisson
'inferenceql.inference.gpm.view.View view/map->View})

(defn as-gpm
Expand Down
22 changes: 22 additions & 0 deletions test/inferenceql/inference/gpm/primitive_gpms/poisson_test.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns inferenceql.inference.gpm.primitive-gpms.poisson-test
(:require [clojure.math :as math]
[clojure.test :as test :refer [deftest is]]
[inferenceql.inference.gpm :as gpm]
[inferenceql.inference.gpm.primitive-gpms.poisson :as poisson]
[inferenceql.inference.gpm.proto :as gpm.proto]
[inferenceql.inference.utils :as utils]))

(def var-name "poisson")

(def poisson-pgpm
(let [suff-stats {:n 0 :sum-x 0 :sum-log-fact 0}
hypers {:a 2 :b 2}]
(poisson/spec->poisson var-name :suff-stats suff-stats :hyperparameters hypers)))

(deftest logpdf
(let [targets {"poisson" 0}
constraints {"poisson" 1}]
(is (= 1.0 (math/exp (gpm.proto/logpdf poisson-pgpm {} {}))))
(is (= 1.0 (math/exp (gpm.proto/logpdf poisson-pgpm targets targets))))
(is (= ##-Inf (gpm.proto/logpdf poisson-pgpm targets constraints))))
(is (utils/almost-equal? -1.2163953243244932 (gpm.proto/logpdf poisson-pgpm {"poisson" 1} {}) utils/relerr 1E-8)))

0 comments on commit 0b0b6bc

Please sign in to comment.