<commit_before>{-# LANGUAGE
  TupleSections,
  Rank2Types
 #-}

module TestInference where

import Data.AEq
import Control.Monad.Trans.Identity
import System.Random

import Control.Monad.Bayes.Class
import Control.Monad.Bayes.Dist
import Control.Monad.Bayes.Sampler
import Control.Monad.Bayes.Weighted
import Control.Monad.Bayes.Empirical
import Control.Monad.Bayes.Trace
import Control.Monad.Bayes.Inference
import Sprinkler
import qualified StrictlySmallerSupport
import qualified Gamma

sprinkler :: MonadBayes m => m Bool
sprinkler = Sprinkler.soft

g = mkStdGen 0

check_terminate_smc = stdSample (smc' 2 5 sprinkler) g

check_preserve_smc = (enumerate . collapse . smc 2 2) sprinkler ~==
                      enumerate sprinkler

check_preserve_ismh = (enumerate . collapse . ismh 2 2) sprinkler ~==
                      enumerate sprinkler

check_preserve_smh = (enumerate . collapse . smh 2 2) sprinkler ~==
                      enumerate sprinkler

check_preserve_smcrm = (enumerate . collapse . smcrm 2 1) sprinkler ~==
                        enumerate sprinkler

sprinkler_posterior = duplicateWeight sprinkler

mhPriorrans :: MonadDist m => Weighted m Bool -> m Bool
mhPriorrans d = fmap (!! 1) $ mh 2 d (MHKernel $ const $ fmap (,1) sprinkler)

check_prior_trans = enumerate (mhPriorrans sprinkler_posterior) ~==<commit_msg>Reduce number of MH transitions in testing ISMH to reduce testing time<commit_after>{-# LANGUAGE
  TupleSections,
  Rank2Types
 #-}

module TestInference where

import Data.AEq
import Control.Monad.Trans.Identity
import System.Random

import Control.Monad.Bayes.Class
import Control.Monad.Bayes.Dist
import Control.Monad.Bayes.Sampler
import Control.Monad.Bayes.Weighted
import Control.Monad.Bayes.Empirical
import Control.Monad.Bayes.Trace
import Control.Monad.Bayes.Inference
import Sprinkler
import qualified StrictlySmallerSupport
import qualified Gamma

sprinkler :: MonadBayes m => m Bool
sprinkler = Sprinkler.soft

g = mkStdGen 0

check_terminate_smc = stdSample (smc' 2 5 sprinkler) g

check_preserve_smc = (enumerate . collapse . smc 2 2) sprinkler ~==
                      enumerate sprinkler

check_preserve_ismh = (enumerate . collapse . ismh 1 2) sprinkler ~==
                      enumerate sprinkler

check_preserve_smh = (enumerate . collapse . smh 2 2) sprinkler ~==
                      enumerate sprinkler

check_preserve_smcrm = (enumerate . collapse . smcrm 2 1) sprinkler ~==
                        enumerate sprinkler

sprinkler_posterior = duplicateWeight sprinkler

mhPriorrans :: MonadDist m => Weighted m Bool -> m Bool
mhPriorrans d = fmap (!! 1) $ mh 2 d (MHKernel $ const $ fmap (,1) sprinkler)

check_prior_trans = enumerate (mhPriorrans sprinkler_posterior) ~==
{'fraction_non_alphanumeric': 0.07667031763417305, 'fraction_numerical': 0.01095290251916758, 'mean_word_length': 3.5819397993311037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1165629', 'n_tokens_mistral': 950, 'n_tokens_neox': 873, 'n_words': 241}