Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeRZP committed Jan 15, 2024
1 parent af2a4a8 commit f1d8b98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,30 @@ samples_hmc = sample(funnel_model, NUTS(5_000, 0.95), 50_000; progress=true, sav
- MCHMC effective samples per second --> ~1340
- Ensemble MCHMC effective samples per second per worker --> ~957

## Using MicroCanonicalHMC.jl with AbstractMCMC.jl
## Using your own likelihood function

### Define a Target
Start by defining your likelihood function and its gradient
```julia
samples_hmc = sample(funnel_model, spl, 100_000; progress=true, save_state=true)
d=2
function ℓπ(x; a=a, b=b)
x1 = x[1:Int(d / 2)]
x2 = x[Int(d / 2)+1:end]
m = @.((a - x1)^2 + b * (x2 - x1^2)^2)
return -0.5 * sum(m)
end
function ∂lπ∂θ(x)
return ℓπ(x), ForwardDiff.gradient(ℓπ, x)
end
θ_start = rand(MvNormal(zeros(d), ones(d)))
```
Wrap it into a `CustomTarget`
```julia
target = CustomTarget(ℓπ, ∂lπ∂θ, θ_start)
```
Note that we are passing the `Turing` model directly instead of the `Target` object.
### Start Sampling
```julia
samples_mchmc = Sample(spl, target, 500_000; dialog=true);
```
![](https://raw.githubusercontent.com/JaimeRZP/MicroCanonicalHMC.jl/master/docs/src/assets/mchmc_comp_2.png)

Binary file added docs/src/assets/mchmc_comp_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f1d8b98

Please sign in to comment.