[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5083368.svg)](https://doi.org/10.5281/zenodo.5083368)
# DifferentialEvolutionMCMC
DifferentialEvolutionMCMC.jl is a Differential Evolution MCMC sampler written in Julia and uses the AbstractMCMC interface. DifferentialEvolutionMCMC.jl works with any model, provided that it returns an exact or approximate log likeilhood. An annotated example is provided below. Other examples can be found in the examples subfolder.
## Example
First, load the required libraries.
```julia
using DifferentialEvolutionMCMC, Random, Distributions
Random.seed!(50514)
```
Define a function that returns the prior log likelihood of parameters μ and σ. Note
that order matters for parameters throughout. The algorithm expects parameters to have
the same order.
```julia
function prior_loglike(μ, σ)
LL = 0.0
LL += logpdf(Normal(0, 1), μ)
LL += logpdf(truncated(Cauchy(0, 1), 0, Inf), σ)
return LL
end
```
Define a function for the initial sample. Sampling from the prior distribution is
a reasonable choice for most applications.
```julia
function sample_prior()
μ = rand(Normal(0, 1))
σ = rand(truncated(Cauchy(0, 1), 0, Inf))
return [μ,σ]
end
```
Next, define a function for the log likelihood which accepts the data followed by the parameters (in the order specififed in the priors).
```julia
function loglike(data, μ, σ)
return sum(logpdf.(Normal(μ, σ), data))
end
```
Specify the upper and lower bounds of the parameters.
```julia
bounds = ((-Inf,Inf),(0.0,Inf))
```
Define the names of parameters. Elements of parameter vectors do not need to be named.
```julia
names = (:μ,:σ)
```
Generate simulated data from a normal distribution
```julia
data = rand(Normal(0.0, 1.0), 50)
```
Now we will create a model object containing the sampling and log likelihood functions, the data and parameter names.
```julia
model = DEModel(;
sample_prior,
prior_loglike,
loglike,
data,
names
)
```
Next, define the DifferentialEvolution sampling object. This requires `bounds`, `burnin` and `Np`, which is the number of particles.
```julia
de = DE(;sample_prior, bounds, burnin = 1000, Np = 6)
```
To run the sampler, pass the model and differential evolution object along with settings for the number of iterations and MCMCMThreads() for multithreading.
```julia
n_iter = 2000
chains = sample(model, de, MCMCThreads(), n_iter, progress=true)
println(chains)
```
没有合适的资源?快使用搜索试试~ 我知道了~
用于差分进化MCMC 的 Julia 包_julia_代码_下载
共39个文件
jl:30个
yml:3个
toml:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 53 浏览量
2022-06-22
07:02:49
上传
评论
收藏 37KB ZIP 举报
温馨提示
DifferentialEvolutionMCMC.jl 是一个用 Julia 编写的差分进化 MCMC 采样器,使用 AbstractMCMC 接口。DifferentialEvolutionMCMC.jl 适用于任何模型,前提是它返回精确或近似的对数似然。下面提供了一个带注释的示例。其他示例可以在示例子文件夹中找到。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
DifferentialEvolutionMCMC.jl-master (1).zip (39个子文件)
DifferentialEvolutionMCMC.jl-master
Project.toml 1KB
.github
workflows
TagBot.yml 362B
CI.yml 1KB
CompatHelper.yml 933B
test
gaussian_tests.jl 1KB
multivariate_normal_tests.jl 2KB
lognormal_race_tests.jl 2KB
utility_tests.jl 6KB
blocking_tests.jl 2KB
optimization_tests.jl 2KB
runtests.jl 345B
binomial_tests.jl 964B
snooker_plot
functions.jl 287B
Project.toml 82B
snooker_plots.jl 2KB
LICENSE 1KB
src
main.jl 7KB
optimize.jl 2KB
mutation.jl 727B
temp.jl 3KB
migration.jl 2KB
utilities.jl 8KB
DifferentialEvolutionMCMC.jl 747B
structs.jl 7KB
crossover.jl 9KB
Examples
temp.stan 777B
KDE.jl 200B
Discrete_Example.jl 840B
Run_LBA.jl 1KB
Binomial_ABC.jl 753B
KDE_Example.jl 1KB
Hierarchical_Example.jl 5KB
Gaussian_Example.jl 2KB
Multivariate_Guassian_Example.jl 1KB
Optimize_Example.jl 800B
Guassian_Example_Vector.jl 781B
Predator_Prey_Example.jl 2KB
.gitignore 18B
README.md 2KB
共 39 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功