Skip to content

Commit

Permalink
Merge pull request #295 from turion/dev_transformer_naming
Browse files Browse the repository at this point in the history
Make transformer naming idiomatic. Fixes #189. Fixes #242.
  • Loading branch information
turion authored Oct 4, 2023
2 parents d2f658c + b73c22d commit 039f630
Show file tree
Hide file tree
Showing 47 changed files with 595 additions and 602 deletions.
2 changes: 1 addition & 1 deletion benchmark/SSM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Control.Monad.Bayes.Inference.RMSMC (rmsmcDynamic)
import Control.Monad.Bayes.Inference.SMC
import Control.Monad.Bayes.Inference.SMC2 as SMC2 (smc2)
import Control.Monad.Bayes.Population
import Control.Monad.Bayes.Population (population, resampleMultinomial)
import Control.Monad.Bayes.Population (resampleMultinomial, runPopulationT)
import Control.Monad.Bayes.Sampler.Strict (sampleIO, sampleIOfixed, sampleWith)
import Control.Monad.Bayes.Weighted (unweighted)
import Control.Monad.IO.Class (MonadIO (liftIO))
Expand Down
6 changes: 3 additions & 3 deletions benchmark/Speed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Control.Monad.Bayes.Class (MonadMeasure)
import Control.Monad.Bayes.Inference.MCMC (MCMCConfig (MCMCConfig, numBurnIn, numMCMCSteps, proposal), Proposal (SingleSiteMH))
import Control.Monad.Bayes.Inference.RMSMC (rmsmcDynamic)
import Control.Monad.Bayes.Inference.SMC (SMCConfig (SMCConfig, numParticles, numSteps, resampler), smc)
import Control.Monad.Bayes.Population (population, resampleSystematic)
import Control.Monad.Bayes.Population (resampleSystematic, runPopulationT)
import Control.Monad.Bayes.Sampler.Strict (SamplerIO, sampleIOfixed)
import Control.Monad.Bayes.Traced (mh)
import Control.Monad.Bayes.Weighted (unweighted)
Expand Down Expand Up @@ -59,10 +59,10 @@ instance Show Alg where

runAlg :: Model -> Alg -> SamplerIO String
runAlg model (MH n) = show <$> unweighted (mh n (buildModel model))
runAlg model (SMC n) = show <$> population (smc SMCConfig {numSteps = (modelLength model), numParticles = n, resampler = resampleSystematic} (buildModel model))
runAlg model (SMC n) = show <$> runPopulationT (smc SMCConfig {numSteps = (modelLength model), numParticles = n, resampler = resampleSystematic} (buildModel model))
runAlg model (RMSMC n t) =
show
<$> population
<$> runPopulationT
( rmsmcDynamic
MCMCConfig {numMCMCSteps = t, numBurnIn = 0, proposal = SingleSiteMH}
SMCConfig {numSteps = modelLength model, numParticles = n, resampler = resampleSystematic}
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/notebooks/Diagrams.html
Original file line number Diff line number Diff line change
Expand Up @@ -14729,8 +14729,8 @@ <h2 id="Viewing-traces">Viewing traces<a class="anchor-link" href="#Viewing-trac
<div class="jp-InputPrompt jp-InputArea-prompt">In&nbsp;[3]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="CodeMirror cm-s-jupyter">
<div class=" highlight hl-Haskell"><pre><span></span><span class="nf">getTrace</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Weighted</span><span class="w"> </span><span class="p">(</span><span class="kt">Density</span><span class="w"> </span><span class="kt">SamplerIO</span><span class="p">)</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="kt">SamplerIO</span><span class="w"> </span><span class="p">([</span><span class="kt">Double</span><span class="p">],</span><span class="w"> </span><span class="kt">Log</span><span class="w"> </span><span class="kt">Double</span><span class="p">)</span>
<span class="nf">getTrace</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">fmap</span><span class="w"> </span><span class="p">(</span><span class="nf">\</span><span class="p">((</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">),</span><span class="n">z</span><span class="p">)</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">z</span><span class="p">,</span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">runWriterT</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">weighted</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="kt">Weighted</span><span class="o">.</span><span class="n">hoist</span><span class="w"> </span><span class="p">(</span><span class="kt">WriterT</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="n">density</span><span class="w"> </span><span class="kt">[]</span><span class="p">)</span><span class="w"> </span><span class="n">m</span>
<div class=" highlight hl-Haskell"><pre><span></span><span class="nf">getTrace</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">WeightedT</span><span class="w"> </span><span class="p">(</span><span class="kt">DensityT</span><span class="w"> </span><span class="kt">SamplerIO</span><span class="p">)</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="kt">SamplerIO</span><span class="w"> </span><span class="p">([</span><span class="kt">Double</span><span class="p">],</span><span class="w"> </span><span class="kt">Log</span><span class="w"> </span><span class="kt">Double</span><span class="p">)</span>
<span class="nf">getTrace</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">fmap</span><span class="w"> </span><span class="p">(</span><span class="nf">\</span><span class="p">((</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">),</span><span class="n">z</span><span class="p">)</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">z</span><span class="p">,</span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="p">)</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">runWriterT</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">runWeightedT</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="kt">Weighted</span><span class="o">.</span><span class="n">hoist</span><span class="w"> </span><span class="p">(</span><span class="kt">WriterT</span><span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="n">runDensityT</span><span class="w"> </span><span class="kt">[]</span><span class="p">)</span><span class="w"> </span><span class="n">m</span>
</pre></div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/notebooks/Histogram.html
Original file line number Diff line number Diff line change
Expand Up @@ -14642,7 +14642,7 @@ <h1 id="Distributions-over-anything">Distributions over <strong>anything</strong
<span class="w"> </span><span class="n">return</span><span class="w"> </span><span class="n">y</span>
<span class="w"> </span>
<span class="nf">distributionOverWeightedSamples</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Distribution</span><span class="w"> </span><span class="p">(</span><span class="kt">Double</span><span class="p">,</span><span class="w"> </span><span class="kt">Log</span><span class="w"> </span><span class="kt">Double</span><span class="p">)</span>
<span class="nf">distributionOverWeightedSamples</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">weighted</span><span class="w"> </span><span class="n">unnormalizedDistribution</span>
<span class="nf">distributionOverWeightedSamples</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">runWeightedT</span><span class="w"> </span><span class="n">unnormalizedDistribution</span>
<span class="w"> </span>
<span class="nf">iidDistribution</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="kt">Distribution</span><span class="w"> </span><span class="p">[(</span><span class="kt">Double</span><span class="p">,</span><span class="w"> </span><span class="kt">Log</span><span class="w"> </span><span class="kt">Double</span><span class="p">)]</span>
<span class="nf">iidDistribution</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">replicateM</span><span class="w"> </span><span class="mi">100000</span><span class="w"> </span><span class="n">distributionOverWeightedSamples</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/notebooks/Parsing.html
Original file line number Diff line number Diff line change
Expand Up @@ -14701,7 +14701,7 @@ <h1 id="Probabilistic-Parser-Combinators">Probabilistic Parser Combinators<a cla

<span class="nf">runWordParser</span><span class="w"> </span><span class="n">w</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kr">do</span>
<span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="ow">&lt;-</span><span class="w"> </span><span class="n">sampler</span><span class="w"> </span>
<span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="n">population</span><span class="w"> </span>
<span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="n">runPopulationT</span><span class="w"> </span>
<span class="w"> </span><span class="o">.</span><span class="w"> </span><span class="n">smc</span><span class="w"> </span><span class="kt">SMCConfig</span><span class="w"> </span><span class="p">{</span><span class="n">numSteps</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="n">numParticles</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="mi">3000</span><span class="p">,</span><span class="w"> </span><span class="n">resampler</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">resampleMultinomial</span><span class="p">}</span><span class="w"> </span>
<span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="n">word</span><span class="w"> </span><span class="n">w</span>
<span class="w"> </span><span class="n">pPrintCustom</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">toEmpiricalWeighted</span><span class="w"> </span><span class="n">x</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/notebooks/Streaming.html
Original file line number Diff line number Diff line change
Expand Up @@ -14906,7 +14906,7 @@ <h2 id="Conditioning">Conditioning<a class="anchor-link" href="#Conditioning">&#
<div class="jp-InputPrompt jp-InputArea-prompt">In&nbsp;[7]:</div>
<div class="jp-CodeMirrorEditor jp-Editor jp-InputArea-editor" data-type="inline">
<div class="CodeMirror cm-s-jupyter">
<div class=" highlight hl-Haskell"><pre><span></span><span class="nf">particles</span><span class="w"> </span><span class="ow">&lt;-</span><span class="w"> </span><span class="n">sampleIOfixed</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">runPopulation</span><span class="w"> </span><span class="o">$</span><span class="w"> </span>
<div class=" highlight hl-Haskell"><pre><span></span><span class="nf">particles</span><span class="w"> </span><span class="ow">&lt;-</span><span class="w"> </span><span class="n">sampleIOfixed</span><span class="w"> </span><span class="o">$</span><span class="w"> </span><span class="n">runPopulationT</span><span class="w"> </span><span class="o">$</span><span class="w"> </span>
<span class="w"> </span><span class="n">smc</span><span class="w"> </span><span class="kt">SMCConfig</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">numSteps</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="mi">100</span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">numParticles</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="mi">1000</span><span class="p">,</span><span class="w"> </span>
Expand Down
Loading

0 comments on commit 039f630

Please sign in to comment.