32 #ifndef MCKL_ALGORITHM_PMCMC_HPP 33 #define MCKL_ALGORITHM_PMCMC_HPP 45 template <
typename Param, MatrixLayout Layout,
typename T, std::
size_t Dim = 0>
53 double log_nc()
const {
return log_nc_; }
72 template <
typename Param,
typename T,
typename U =
double>
80 std::function<double(typename Particle<T>::rng_type &,
param_type &)>;
81 using prior_type = std::function<double(const param_type &)>;
84 template <
typename Prior,
typename... Args>
85 PMCMCMutation(std::size_t N, std::size_t M, Prior &&prior, Args &&... args)
86 : M_(M), prior_(prior), pf_(N,
std::forward<Args>(args)...)
103 mutation.pf_.particle().rng_set().reset();
104 mutation.pf_.particle().rng().seed(
110 template <
typename Prior>
113 prior_ = std::forward<Prior>(prior);
117 template <
typename Eval>
120 eval_.push_back(std::forward<Eval>(eval));
122 return eval_.size() - 1;
129 pf_.particle().state().reset(param, 0);
134 const double lnc = pf_.particle().state().log_nc();
136 double prob = -prior_(param) - lnc;
138 for (
auto &eval : eval_) {
139 prob += eval(pf_.particle().rng(), p);
144 pf_.particle().state().reset(p, 0);
146 prob += pf_.particle().state().log_nc();
152 param = std::move(p);
154 pf_.particle().state().reset(param, lnc);
157 return u < prob ? 1 : 0;
171 #endif // MCKL_ALGORITHM_PMCMC_HPP
void add_log_nc(double nc)
PMCMCMutation(std::size_t N, std::size_t M, Prior &&prior, Args &&... args)
std::function< double(const param_type &)> prior_type
std::size_t update(Eval &&eval)
Add a new evaluation object for the update step.
#define MCKL_PUSH_CLANG_WARNING(warning)
std::vector< T, Alloc > Vector
std::vector with Allocator as the default allocator
void log(std::size_t n, const float *a, float *y)
PMCMCMutation< Param, T, U > clone() const
RealType u01(UIntType u)
Convert uniform unsigned integers to floating points within [0, 1].
SMCSampler< T, U > pf_type
typename rng_set_type::rng_type rng_type
const param_type & param()
void prior(Prior &&prior)
void reset(const param_type &p, double nc=0)
Particle::state_type subtype.
typename Particle< T >::size_type size_type
#define MCKL_POP_CLANG_WARNING
Standard uniform distribution on [0, 1)
std::size_t operator()(std::size_t iter, param_type ¶m)
Particle Markov chain Monte Carlo mutation.
RNG default seed generator.
std::function< double(typename Particle< T >::rng_type &, param_type &)> eval_type