File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,23 @@ let betabinLogPmf:Int -> Float -> Float -> Int -> Float = lam n. lam a. lam b. l
203203let betabinPmf = lam n :Int . lam a : Float . lam b : Float . lam x :Int .
204204 exp (betabinLogPmf n a b x )
205205
206+ -- Reciprocal (or log uniform ) distribution
207+ let reciprocalSample : Float - > Float - > Float = lam a . lam b .
208+ let logSample = uniformContinuousSample (log a ) (log b ) in
209+ exp logSample
210+
211+ let reciprocalPdf : Float - > Float - > Float - > Float = lam a . lam b . lam x .
212+ if geqf x a then
213+ if leqf x b then divf 1.0 (mulf (log (divf b a )) x )
214+ else 0.
215+ else 0.
216+
217+ let reciprocalLogPdf : Float - > Float - > Float - > Float = lam a . lam b . lam x .
218+ if geqf x a then
219+ if leqf x b then negf (log (mulf (log (divf b a )) x ))
220+ else negf inf
221+ else negf inf
222+
206223-- Seed
207224external externalSetSeed ! : Int - > ()
208225let setSeed : Int - > () = lam seed .
@@ -322,6 +339,13 @@ utest exp (betabinLogPmf 5 1. 1. 3) with 0.166666666667 using _eqf in
322339utest betabinPmf 5 1. 1. 3 with 0.166666666667 using _eqf in
323340utest betabinSample 20 1. 1. with 0 using intRange 0 20 in
324341
342+ -- Testing Reciprocal
343+ utest reciprocalLogPdf 1. 2. 1.5 with - 0.038952187526 using _eqf in
344+ utest reciprocalLogPdf 1. 2. 2.5 with negf inf using leqf in
345+ utest exp (reciprocalLogPdf 4. 6. 5. ) with 0.493260692475 using _eqf in
346+ utest reciprocalPdf 4. 6. 5. with 0.493260692475 using _eqf in
347+ utest reciprocalSample 0.5 0.7 with 0.5 using floatRange 0.5 0.7 in
348+
325349-- Testing seed
326350utest setSeed 0 ; uniformSample (); uniformSample ()
327351with setSeed 0 ; uniformSample (); uniformSample () in
You can’t perform that action at this time.
0 commit comments