mirror of
https://github.com/maciej-bendkowski/generic-boltzmann-brain.git
synced 2024-09-11 12:48:09 +03:00
Introduce mkSpecSampler
.
This commit is contained in:
parent
8b7d88eb79
commit
f709e3bfe4
@ -10,12 +10,12 @@
|
||||
-- Maintainer : maciej.bendkowski@gmail.com
|
||||
-- Stability : experimental
|
||||
module Data.Boltzmann.Oracle
|
||||
( mkChoiceFun,
|
||||
mkWeightFun,
|
||||
( mkSpecSampler,
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Monad (replicateM)
|
||||
import Data.Boltzmann.Sampler (BoltzmannSampler (sample))
|
||||
import Data.Boltzmann.Specifiable
|
||||
( Cons (args, name),
|
||||
Specifiable (..),
|
||||
@ -199,3 +199,6 @@ mkWeightMatch sys cons = return $ Match (LitP (StringL s)) (NormalB $ LitE (Inte
|
||||
where
|
||||
s = name cons
|
||||
w = sys `S.getWeight` s
|
||||
|
||||
mkSpecSampler :: S.SystemSpec -> Q Exp
|
||||
mkSpecSampler sys = [|sample $(mkChoiceFun sys) $(mkWeightFun sys)|]
|
||||
|
@ -2,11 +2,9 @@
|
||||
|
||||
module Data.Samplers.BinTree where
|
||||
|
||||
import Data.Boltzmann.Oracle (mkChoiceFun, mkWeightFun)
|
||||
import Data.Boltzmann.Oracle (mkSpecSampler)
|
||||
import Data.Boltzmann.Sampler (BoltzmannSampler (..), rejectionSamplerIO)
|
||||
import Data.Types.BinTree (BinTree, binTreeSysSpec)
|
||||
|
||||
randomBinTreeIO :: Int -> Int -> IO BinTree
|
||||
randomBinTreeIO =
|
||||
rejectionSamplerIO
|
||||
(sample $(mkChoiceFun binTreeSysSpec) $(mkWeightFun binTreeSysSpec))
|
||||
randomBinTreeIO = rejectionSamplerIO $(mkSpecSampler binTreeSysSpec)
|
||||
|
@ -2,11 +2,9 @@
|
||||
|
||||
module Data.Samplers.Lambda where
|
||||
|
||||
import Data.Boltzmann.Oracle (mkChoiceFun, mkWeightFun)
|
||||
import Data.Boltzmann.Oracle (mkSpecSampler)
|
||||
import Data.Boltzmann.Sampler (BoltzmannSampler (..), rejectionSamplerIO)
|
||||
import Data.Types.Lambda (Lambda, lambdaSysSpec)
|
||||
|
||||
randomLambdaIO :: Int -> Int -> IO Lambda
|
||||
randomLambdaIO =
|
||||
rejectionSamplerIO
|
||||
(sample $(mkChoiceFun lambdaSysSpec) $(mkWeightFun lambdaSysSpec))
|
||||
randomLambdaIO = rejectionSamplerIO $(mkSpecSampler lambdaSysSpec)
|
||||
|
@ -2,11 +2,9 @@
|
||||
|
||||
module Data.Samplers.Tree where
|
||||
|
||||
import Data.Boltzmann.Oracle (mkChoiceFun, mkWeightFun)
|
||||
import Data.Boltzmann.Oracle (mkSpecSampler)
|
||||
import Data.Boltzmann.Sampler (BoltzmannSampler (..), rejectionSamplerIO)
|
||||
import Data.Types.Tree (Tree, treeSysSpec)
|
||||
|
||||
randomTreeIO :: Int -> Int -> IO Tree
|
||||
randomTreeIO =
|
||||
rejectionSamplerIO
|
||||
(sample $(mkChoiceFun treeSysSpec) $(mkWeightFun treeSysSpec))
|
||||
randomTreeIO = rejectionSamplerIO $(mkSpecSampler treeSysSpec)
|
||||
|
Loading…
Reference in New Issue
Block a user