Skip to content

Commit

Permalink
Add sampler APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
xukai92 committed Nov 15, 2016
1 parent 9de80ec commit 072e034
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 24 deletions.
27 changes: 15 additions & 12 deletions doc/genrst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ end

to_gen = Dict(
"replayapi" => Dict(
:title => "Replay",
:list => ["Prior", "PriorArray", "PriorContainer", "addPrior"]
:title => "Replay",
:list => ["Prior", "PriorArray", "PriorContainer", "addPrior"]
),
"compilerapi" => Dict(
:title => "Macros for Compiler",
:list => ["@assume", "@observe", "@predict", "@model"]
:title => "Compiler",
:list => ["@assume", "@observe", "@predict", "@model"]
),
"samplerapi" => Dict(
:title => "Sampler",
:list => ["IS", "SMC", "PG", "HMC"]
)
)

Expand Down Expand Up @@ -74,23 +78,22 @@ Contents
usage
demos
.. toctree::
:maxdepth: 2
:caption: APIs
$api_str
.. toctree::
:maxdepth: 2
:caption: Development Notes
language
compiler
sampler
coroutines
samplerintro
tarray
workflow
.. toctree::
:maxdepth: 2
:caption: APIs
$api_str
.. toctree::
:maxdepth: 2
:caption: License
Expand Down
2 changes: 1 addition & 1 deletion doc/source/compilerapi.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Macros for Compiler
Compiler
=========

.. function:: assume(ex)
Expand Down
20 changes: 11 additions & 9 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@ Contents
usage
demos

.. toctree::
:maxdepth: 2
:caption: APIs

replayapi
samplerapi
compilerapi

.. toctree::
:maxdepth: 2
:caption: Development Notes

language
compiler
sampler
coroutines
samplerintro
tarray
workflow

.. toctree::
:maxdepth: 2
:caption: APIs

replayapi
compilerapi

.. toctree::
:maxdepth: 2
:caption: License

license


2 changes: 0 additions & 2 deletions doc/source/sampler.rst

This file was deleted.

83 changes: 83 additions & 0 deletions doc/source/samplerapi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Sampler
=========

.. function:: IS(n_particles::Int)

Importance sampler.

Usage:

.. code-block:: julia
IS(1000)
Example:

.. code-block:: julia
@model example begin
...
end
sample(example, IS(1000))
.. function:: SMC(n_particles::Int)

Sequential Monte Carlo sampler.

Usage:

.. code-block:: julia
SMC(1000)
Example:

.. code-block:: julia
@model example begin
...
end
sample(example, SMC(1000))
.. function:: PG(n_particles::Int, n_iterations::Int)

Particle Gibbs sampler.

Usage:

.. code-block:: julia
PG(100, 100)
Example:

.. code-block:: julia
@model example begin
...
end
sample(example, PG(100, 100))
.. function:: HMC(n_samples::Int64, lf_size::Float64, lf_num::Int64)

Hamiltonian Monte Carlo sampler.

Usage:

.. code-block:: julia
HMC(1000, 0.05, 10)
Example:

.. code-block:: julia
@model example begin
...
end
sample(example, HMC(1000, 0.05, 10))
2 changes: 2 additions & 0 deletions doc/source/samplerintro.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Breif Introduction to Supported Samplers
============
21 changes: 21 additions & 0 deletions src/samplers/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ else
RerunThreshold = 1
end

doc"""
HMC(n_samples::Int64, lf_size::Float64, lf_num::Int64)
Hamiltonian Monte Carlo sampler.
Usage:
```julia
HMC(1000, 0.05, 10)
```
Example:
```julia
@model example begin
...
end
sample(example, HMC(1000, 0.05, 10))
```
"""
immutable HMC <: InferenceAlgorithm
n_samples :: Int64 # number of samples
lf_size :: Float64 # leapfrog step size
Expand Down
22 changes: 22 additions & 0 deletions src/samplers/is.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@

doc"""
IS(n_particles::Int)
Importance sampler.
Usage:
```julia
IS(1000)
```
Example:
```julia
@model example begin
...
end
sample(example, IS(1000))
```
"""
immutable IS <: InferenceAlgorithm
n_samples :: Int
end
Expand Down
21 changes: 21 additions & 0 deletions src/samplers/pgibbs.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Particle Gibbs sampler

doc"""
PG(n_particles::Int, n_iterations::Int)
Particle Gibbs sampler.
Usage:
```julia
PG(100, 100)
```
Example:
```julia
@model example begin
...
end
sample(example, PG(100, 100))
```
"""
immutable PG <: InferenceAlgorithm
n_particles :: Int
n_iterations :: Int
Expand Down
22 changes: 22 additions & 0 deletions src/samplers/smc.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@

doc"""
SMC(n_particles::Int)
Sequential Monte Carlo sampler.
Usage:
```julia
SMC(1000)
```
Example:
```julia
@model example begin
...
end
sample(example, SMC(1000))
```
"""
immutable SMC <: InferenceAlgorithm
n_particles :: Int
resampler :: Function
Expand Down

0 comments on commit 072e034

Please sign in to comment.