Skip to content

Commit 822a522

Browse files
committed
Implement set_proposal_fun
1 parent 9eca06f commit 822a522

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Diff for: src/lfmcmc.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,28 @@ SEXP set_proposal_fun_cpp(
7272
cpp11::function fun
7373
) {
7474

75-
cpp11::stop("Un implemented");
75+
LFMCMCProposalFun<TData_default> fun_call = [fun](
76+
std::vector< epiworld_double >& params_now,
77+
const std::vector< epiworld_double >& params_prev,
78+
LFMCMC<TData_default>*
79+
) -> void {
80+
81+
auto params_doubles = cpp11::doubles(params_prev);
82+
83+
auto res_tmp = cpp11::doubles(fun(params_doubles));
84+
85+
std::copy(
86+
res_tmp.begin(),
87+
res_tmp.end(),
88+
params_now.begin()
89+
);
90+
91+
return;
92+
};
93+
94+
WrapLFMCMC(lfmcmc_ptr)(lfmcmc);
95+
96+
lfmcmc_ptr->set_proposal_fun(fun_call);
7697

7798
return lfmcmc;
7899
}

Diff for: vignettes/likelihood-free-mcmc.Rmd

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ sumfun <- function(dat) {
8080
return(dat)
8181
}
8282
83+
# Define the LFMCMC proposal function
84+
propfun <- function(params_prev) {
85+
res <- params_prev + rnorm(length(params_prev), )
86+
return(res)
87+
}
88+
8389
# Define the LFMCMC kernel function
8490
# - Based on kernel_fun_uniform from lfmcmc-meat.hpp
8591
kernelfun <- function(stats_now, stats_obs, epsilon) {
@@ -95,7 +101,7 @@ kernelfun <- function(stats_now, stats_obs, epsilon) {
95101
lfmcmc_model <- LFMCMC(model_sir) |>
96102
set_simulation_fun(simfun) |>
97103
set_summary_fun(sumfun) |>
98-
use_proposal_norm_reflective() |>
104+
set_proposal_fun(propfun) |>
99105
set_kernel_fun(kernelfun) |>
100106
set_observed_data(obs_data)
101107
```

0 commit comments

Comments
 (0)