mirror of
https://github.com/maciej-bendkowski/generic-boltzmann-brain.git
synced 2024-09-11 12:48:09 +03:00
Rename hoist
samplers to quickCheck
samplers
This commit is contained in:
parent
d6413ceebb
commit
0f1766980d
@ -63,7 +63,7 @@ in that respect closely related to QuickCheck's generator type `Gen a` to which
|
|||||||
it can be converted through, e.g.:
|
it can be converted through, e.g.:
|
||||||
|
|
||||||
``` hs
|
``` hs
|
||||||
hoistRejectionSampler ::
|
quickCheckRejectionSampler ::
|
||||||
BoltzmannSampler a => (Int -> (LowerBound, UpperBound)) -> Gen a
|
BoltzmannSampler a => (Int -> (LowerBound, UpperBound)) -> Gen a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ module Data.Boltzmann (
|
|||||||
toleranceRejectionSampler,
|
toleranceRejectionSampler,
|
||||||
mkBoltzmannSampler,
|
mkBoltzmannSampler,
|
||||||
mkDefBoltzmannSampler,
|
mkDefBoltzmannSampler,
|
||||||
hoistRejectionSampler,
|
quickCheckRejectionSampler,
|
||||||
hoistToleranceRejectionSampler,
|
quickCheckToleranceRejectionSampler,
|
||||||
|
|
||||||
-- * Buffon machines
|
-- * Buffon machines
|
||||||
BuffonMachine,
|
BuffonMachine,
|
||||||
@ -39,8 +39,8 @@ import Data.Boltzmann.Sampler (
|
|||||||
BoltzmannSampler (..),
|
BoltzmannSampler (..),
|
||||||
LowerBound (..),
|
LowerBound (..),
|
||||||
UpperBound (..),
|
UpperBound (..),
|
||||||
hoistRejectionSampler,
|
quickCheckRejectionSampler,
|
||||||
hoistToleranceRejectionSampler,
|
quickCheckToleranceRejectionSampler,
|
||||||
rejectionSampler,
|
rejectionSampler,
|
||||||
toleranceRejectionSampler,
|
toleranceRejectionSampler,
|
||||||
)
|
)
|
||||||
|
@ -16,17 +16,18 @@ module Data.Boltzmann.Sampler (
|
|||||||
toleranceRejectionSampler,
|
toleranceRejectionSampler,
|
||||||
|
|
||||||
-- * Other utilities
|
-- * Other utilities
|
||||||
hoistRejectionSampler,
|
quickCheckRejectionSampler,
|
||||||
hoistToleranceRejectionSampler,
|
quickCheckToleranceRejectionSampler,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
|
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
|
||||||
import Data.Boltzmann.BuffonMachine (BuffonMachine, eval)
|
import Data.Boltzmann.BuffonMachine (BuffonMachine, eval)
|
||||||
import Data.Coerce (coerce)
|
import Data.Coerce (coerce)
|
||||||
import System.Random (RandomGen)
|
import System.Random (RandomGen)
|
||||||
import Test.QuickCheck (Gen)
|
|
||||||
import Test.QuickCheck.Gen (Gen (MkGen))
|
import qualified Test.QuickCheck as QuickCheck (Gen)
|
||||||
import Test.QuickCheck.Random (QCGen (QCGen))
|
import qualified Test.QuickCheck.Gen as QuickCheck (Gen (MkGen))
|
||||||
|
import qualified Test.QuickCheck.Random as QuickCheck (QCGen (QCGen))
|
||||||
|
|
||||||
-- | Multiparametric Boltzmann samplers.
|
-- | Multiparametric Boltzmann samplers.
|
||||||
class BoltzmannSampler a where
|
class BoltzmannSampler a where
|
||||||
@ -73,21 +74,26 @@ toleranceRejectionSampler n eps = rejectionSampler lb ub
|
|||||||
ub = MkUpperBound $ ceiling $ (1 + eps) * fromIntegral n
|
ub = MkUpperBound $ ceiling $ (1 + eps) * fromIntegral n
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- Using the given tolerance, hoists a tolerance rejection sampler
|
-- Using the given tolerance, maps a tolerance rejection sampler
|
||||||
-- for @a@ to a Quickcheck generator @Gen a@.
|
-- for @a@ to a Quickcheck generator @Gen a@.
|
||||||
hoistRejectionSampler ::
|
quickCheckRejectionSampler ::
|
||||||
BoltzmannSampler a =>
|
BoltzmannSampler a =>
|
||||||
(Int -> (LowerBound, UpperBound)) ->
|
(Int -> (LowerBound, UpperBound)) ->
|
||||||
Gen a
|
QuickCheck.Gen a
|
||||||
hoistRejectionSampler genBounds = MkGen $ \(QCGen g) n ->
|
quickCheckRejectionSampler genBounds = QuickCheck.MkGen $
|
||||||
|
\(QuickCheck.QCGen g) n ->
|
||||||
let (lb, ub) = genBounds n
|
let (lb, ub) = genBounds n
|
||||||
machine = rejectionSampler lb ub
|
machine = rejectionSampler lb ub
|
||||||
in eval machine g
|
in eval machine g
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- Using the given tolerance, hoists a tolerance rejection sampler
|
-- Using the given tolerance, maps a tolerance rejection sampler
|
||||||
-- for @a@ to a Quickcheck generator @Gen a@.
|
-- for @a@ to a Quickcheck generator @Gen a@.
|
||||||
hoistToleranceRejectionSampler :: BoltzmannSampler a => Double -> Gen a
|
quickCheckToleranceRejectionSampler ::
|
||||||
hoistToleranceRejectionSampler eps = MkGen $ \(QCGen g) n ->
|
BoltzmannSampler a =>
|
||||||
|
Double ->
|
||||||
|
QuickCheck.Gen a
|
||||||
|
quickCheckToleranceRejectionSampler eps = QuickCheck.MkGen $
|
||||||
|
\(QuickCheck.QCGen g) n ->
|
||||||
let machine = toleranceRejectionSampler n eps
|
let machine = toleranceRejectionSampler n eps
|
||||||
in eval machine g
|
in eval machine g
|
||||||
|
@ -39,6 +39,7 @@ packages:
|
|||||||
#
|
#
|
||||||
extra-deps:
|
extra-deps:
|
||||||
- criterion-1.5.12.0
|
- criterion-1.5.12.0
|
||||||
|
- testing-feat-1.1.0.0
|
||||||
- git: https://github.com/maciej-bendkowski/paganini-hs
|
- git: https://github.com/maciej-bendkowski/paganini-hs
|
||||||
commit: 941e8f6314ea49b79c2cf1a03924cbedc981917e
|
commit: 941e8f6314ea49b79c2cf1a03924cbedc981917e
|
||||||
- git: https://github.com/OctopiChalmers/BinderAnn
|
- git: https://github.com/OctopiChalmers/BinderAnn
|
||||||
|
@ -11,6 +11,13 @@ packages:
|
|||||||
sha256: 92034e3e490c5fe0eab10277f6e35534b37dc0962347025630380c7d37d99ca1
|
sha256: 92034e3e490c5fe0eab10277f6e35534b37dc0962347025630380c7d37d99ca1
|
||||||
original:
|
original:
|
||||||
hackage: criterion-1.5.12.0
|
hackage: criterion-1.5.12.0
|
||||||
|
- completed:
|
||||||
|
hackage: testing-feat-1.1.0.0@sha256:7c7629c5014edf06aefbf30a061d1ee64c6ee15f438d868e34749fb22208ab0b,2466
|
||||||
|
pantry-tree:
|
||||||
|
size: 790
|
||||||
|
sha256: 444f3c68a4f4fa1488fbbe9e8d9bbcc5f226b12a5027ee93683d5f95bf0ece28
|
||||||
|
original:
|
||||||
|
hackage: testing-feat-1.1.0.0
|
||||||
- completed:
|
- completed:
|
||||||
name: paganini-hs
|
name: paganini-hs
|
||||||
version: 0.3.0.0
|
version: 0.3.0.0
|
||||||
|
@ -9,7 +9,7 @@ import Data.Boltzmann (
|
|||||||
LowerBound (MkLowerBound),
|
LowerBound (MkLowerBound),
|
||||||
System (..),
|
System (..),
|
||||||
UpperBound (MkUpperBound),
|
UpperBound (MkUpperBound),
|
||||||
hoistRejectionSampler,
|
quickCheckRejectionSampler,
|
||||||
mkBoltzmannSampler,
|
mkBoltzmannSampler,
|
||||||
mkDefWeights,
|
mkDefWeights,
|
||||||
)
|
)
|
||||||
@ -40,6 +40,6 @@ mkBoltzmannSampler
|
|||||||
|
|
||||||
instance Arbitrary BinTree where
|
instance Arbitrary BinTree where
|
||||||
arbitrary =
|
arbitrary =
|
||||||
hoistRejectionSampler $
|
quickCheckRejectionSampler $
|
||||||
const (MkLowerBound 800, MkUpperBound 1200)
|
const (MkLowerBound 800, MkUpperBound 1200)
|
||||||
shrink = const []
|
shrink = const []
|
||||||
|
@ -14,7 +14,7 @@ import Data.Boltzmann (
|
|||||||
LowerBound (MkLowerBound),
|
LowerBound (MkLowerBound),
|
||||||
System (..),
|
System (..),
|
||||||
UpperBound (MkUpperBound),
|
UpperBound (MkUpperBound),
|
||||||
hoistRejectionSampler,
|
quickCheckRejectionSampler,
|
||||||
mkBoltzmannSampler,
|
mkBoltzmannSampler,
|
||||||
mkDefWeights,
|
mkDefWeights,
|
||||||
)
|
)
|
||||||
@ -67,7 +67,7 @@ instance Size Lambda where
|
|||||||
|
|
||||||
instance Arbitrary Lambda where
|
instance Arbitrary Lambda where
|
||||||
arbitrary =
|
arbitrary =
|
||||||
hoistRejectionSampler $
|
quickCheckRejectionSampler $
|
||||||
const (MkLowerBound 8_000, MkUpperBound 12_000)
|
const (MkLowerBound 8_000, MkUpperBound 12_000)
|
||||||
shrink = const []
|
shrink = const []
|
||||||
|
|
||||||
@ -95,6 +95,6 @@ mkBoltzmannSampler
|
|||||||
|
|
||||||
instance Arbitrary BinLambda where
|
instance Arbitrary BinLambda where
|
||||||
arbitrary =
|
arbitrary =
|
||||||
hoistRejectionSampler $
|
quickCheckRejectionSampler $
|
||||||
const (MkLowerBound 5_000, MkUpperBound 6_400)
|
const (MkLowerBound 5_000, MkUpperBound 6_400)
|
||||||
shrink = const []
|
shrink = const []
|
||||||
|
@ -9,7 +9,7 @@ import Data.Boltzmann (
|
|||||||
LowerBound (MkLowerBound),
|
LowerBound (MkLowerBound),
|
||||||
System (..),
|
System (..),
|
||||||
UpperBound (MkUpperBound),
|
UpperBound (MkUpperBound),
|
||||||
hoistRejectionSampler,
|
quickCheckRejectionSampler,
|
||||||
mkBoltzmannSampler,
|
mkBoltzmannSampler,
|
||||||
mkDefBoltzmannSampler,
|
mkDefBoltzmannSampler,
|
||||||
mkDefWeights,
|
mkDefWeights,
|
||||||
@ -30,7 +30,7 @@ instance Size Tree where
|
|||||||
|
|
||||||
instance Arbitrary Tree where
|
instance Arbitrary Tree where
|
||||||
arbitrary =
|
arbitrary =
|
||||||
hoistRejectionSampler $
|
quickCheckRejectionSampler $
|
||||||
const (MkLowerBound 1600, MkUpperBound 2400)
|
const (MkLowerBound 1600, MkUpperBound 2400)
|
||||||
shrink = const []
|
shrink = const []
|
||||||
|
|
||||||
@ -53,6 +53,6 @@ mkBoltzmannSampler
|
|||||||
|
|
||||||
instance Arbitrary Tree' where
|
instance Arbitrary Tree' where
|
||||||
arbitrary =
|
arbitrary =
|
||||||
hoistRejectionSampler $
|
quickCheckRejectionSampler $
|
||||||
const (MkLowerBound 8500, MkUpperBound 11_150)
|
const (MkLowerBound 8500, MkUpperBound 11_150)
|
||||||
shrink = const []
|
shrink = const []
|
||||||
|
Loading…
Reference in New Issue
Block a user