abcpp is a lightweight embeddable C++ library for Approximate Bayesian
Computation, with R and Python wrappers. The C++ library is the only algorithm
implementation; R and Python are thin frontends.
C++ Usage
abcpp can be embedded in another CMake project in the same style as small algorithm libraries such as NLopt, using FetchContent_Declare to call abcpp as the algorithm backend:
include(FetchContent) FetchContent_Declare( abcpp GIT_REPOSITORY https://github.com/yuki-961004/abcpp.git GIT_TAG main GIT_SHALLOW TRUE ) FetchContent_MakeAvailable(abcpp) target_link_libraries(my_target PRIVATE abcpp::abcpp)
The primary C++ API is NLopt-like:
#include <abcpp/abcpp.hpp> abcpp::opt opt; abcpp::result fit = opt .set_target(target) .set_params(params) .set_sumstats(sumstats) .set_method(abcpp::method::neuralnet) .set_tol(0.01) .set_nnet_sizenet(8) .run();
R Usage
Install from CRAN:
install.packages("abcpp")The R interface uses four inputs: target, params, sumstats, and
control.
library(abcpp) result <- abcpp::abc( target = <target_summary_vector_or_matrix>, params = <parameter_vector_or_matrix>, sumstats = <simulated_summary_vector_or_matrix>, control = list( method = "rejection", tol = <tolerance_between_0_and_1> ) ) summary(result)
Python Usage
Install from PyPI:
pip install abcpp
The Python interface mirrors the R interface:
import abcpp result = abcpp.abc( target=<target_summary_vector_or_matrix>, params=<parameter_vector_or_matrix>, sumstats=<simulated_summary_vector_or_matrix>, control={ "method": "rejection", "tol": <tolerance_between_0_and_1>, }, ) abcpp.summary(result)