diff --git a/src/inferenceql/inference/gpm.cljc b/src/inferenceql/inference/gpm.cljc index f61ca4c..6a3ee1b 100644 --- a/src/inferenceql/inference/gpm.cljc +++ b/src/inferenceql/inference/gpm.cljc @@ -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])) @@ -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 diff --git a/test/inferenceql/inference/gpm/primitive_gpms/poisson_test.cljc b/test/inferenceql/inference/gpm/primitive_gpms/poisson_test.cljc new file mode 100644 index 0000000..cb0b108 --- /dev/null +++ b/test/inferenceql/inference/gpm/primitive_gpms/poisson_test.cljc @@ -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)))