File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,25 @@ SEXP set_kernel_fun_cpp(
147147 SEXP lfmcmc,
148148 cpp11::function fun
149149) {
150- cpp11::stop (" Unimplemented" );
150+
151+ LFMCMCKernelFun<TData_default> fun_call = [fun](
152+ const std::vector< epiworld_double >& stats_now,
153+ const std::vector< epiworld_double >& stats_obs,
154+ epiworld_double epsilon,
155+ LFMCMC<TData_default>*
156+ ) -> epiworld_double {
157+
158+ auto stats_now_doubles = cpp11::doubles (stats_now);
159+ auto stats_obs_doubles = cpp11::doubles (stats_obs);
160+
161+ return cpp11::as_cpp<epiworld_double>(
162+ fun (stats_now_doubles, stats_obs_doubles, epsilon)
163+ );
164+ };
165+
166+ WrapLFMCMC (lfmcmc_ptr)(lfmcmc);
167+
168+ lfmcmc_ptr->set_kernel_fun (fun_call);
151169
152170 return lfmcmc;
153171}
Original file line number Diff line number Diff line change @@ -80,12 +80,23 @@ sumfun <- function(dat) {
8080 return(dat)
8181}
8282
83+ # Define the LFMCMC kernel function
84+ # - Based on kernel_fun_uniform from lfmcmc-meat.hpp
85+ kernelfun <- function(stats_now, stats_obs, epsilon) {
86+
87+ ans <- sum(mapply(function(v1, v2) (v1 - v2)^2,
88+ stats_obs,
89+ stats_now))
90+
91+ return(ifelse(sqrt(ans) < epsilon, 1.0, 0.0))
92+ }
93+
8394# Create the LFMCMC model using a norm reflective proposal function and a Gaussian kernel function
8495lfmcmc_model <- LFMCMC(model_sir) |>
8596 set_simulation_fun(simfun) |>
8697 set_summary_fun(sumfun) |>
8798 use_proposal_norm_reflective() |>
88- use_kernel_fun_gaussian( ) |>
99+ set_kernel_fun(kernelfun ) |>
89100 set_observed_data(obs_data)
90101```
91102
You can’t perform that action at this time.
0 commit comments