Skip to content

Commit

Permalink
Rename kernel fun parameters stats_now, stats_obs
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Dec 5, 2024
1 parent 9c96d89 commit 2f42c2e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 54 deletions.
73 changes: 41 additions & 32 deletions epiworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,17 +1137,17 @@ inline void proposal_fun_unif(
/**
* @brief Uses the uniform kernel with euclidean distance
*
* @param stats_now Vector of current statistics based on
* simulated data.
* @param stats_obs Vector of observed statistics
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model.
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_uniform(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
);
Expand All @@ -1156,14 +1156,17 @@ inline epiworld_double kernel_fun_uniform(
* @brief Gaussian kernel
*
* @tparam TData
* @param epsilon
* @param m
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_gaussian(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
);
Expand Down Expand Up @@ -1425,17 +1428,17 @@ inline void proposal_fun_unif(
/**
* @brief Uses the uniform kernel with euclidean distance
*
* @param stats_now Vector of current statistics based on
* simulated data.
* @param stats_obs Vector of observed statistics
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model.
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_uniform(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
);
Expand All @@ -1444,14 +1447,17 @@ inline epiworld_double kernel_fun_uniform(
* @brief Gaussian kernel
*
* @tparam TData
* @param epsilon
* @param m
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_gaussian(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
);
Expand Down Expand Up @@ -1737,24 +1743,24 @@ inline void proposal_fun_unif(
/**
* @brief Uses the uniform kernel with euclidean distance
*
* @param stats_now Vector of current statistics based on
* simulated data.
* @param stats_obs Vector of observed statistics
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model.
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_uniform(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
) {

epiworld_double ans = 0.0;
for (size_t p = 0u; p < m->get_n_params(); ++p)
ans += std::pow(stats_obs[p] - stats_now[p], 2.0);
ans += std::pow(observed_stats[p] - simulated_stats[p], 2.0);

return std::sqrt(ans) < epsilon ? 1.0 : 0.0;

Expand All @@ -1766,21 +1772,24 @@ inline epiworld_double kernel_fun_uniform(
* @brief Gaussian kernel
*
* @tparam TData
* @param epsilon
* @param m
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_gaussian(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
) {

epiworld_double ans = 0.0;
for (size_t p = 0u; p < m->get_n_params(); ++p)
ans += std::pow(stats_obs[p] - stats_now[p], 2.0);
ans += std::pow(observed_stats[p] - simulated_stats[p], 2.0);

return std::exp(
-.5 * (ans/std::pow(1 + std::pow(epsilon, 2.0)/3.0, 2.0))
Expand Down
23 changes: 13 additions & 10 deletions include/epiworld/math/lfmcmc/lfmcmc-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ inline void proposal_fun_unif(
/**
* @brief Uses the uniform kernel with euclidean distance
*
* @param stats_now Vector of current statistics based on
* simulated data.
* @param stats_obs Vector of observed statistics
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model.
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_uniform(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
);
Expand All @@ -94,14 +94,17 @@ inline epiworld_double kernel_fun_uniform(
* @brief Gaussian kernel
*
* @tparam TData
* @param epsilon
* @param m
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_gaussian(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
);
Expand Down
27 changes: 15 additions & 12 deletions include/epiworld/math/lfmcmc/lfmcmc-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,24 @@ inline void proposal_fun_unif(
/**
* @brief Uses the uniform kernel with euclidean distance
*
* @param stats_now Vector of current statistics based on
* simulated data.
* @param stats_obs Vector of observed statistics
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model.
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_uniform(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
) {

epiworld_double ans = 0.0;
for (size_t p = 0u; p < m->get_n_params(); ++p)
ans += std::pow(stats_obs[p] - stats_now[p], 2.0);
ans += std::pow(observed_stats[p] - simulated_stats[p], 2.0);

Check warning on line 144 in include/epiworld/math/lfmcmc/lfmcmc-meat.hpp

View check run for this annotation

Codecov / codecov/patch

include/epiworld/math/lfmcmc/lfmcmc-meat.hpp#L143-L144

Added lines #L143 - L144 were not covered by tests

return std::sqrt(ans) < epsilon ? 1.0 : 0.0;

Expand All @@ -153,21 +153,24 @@ inline epiworld_double kernel_fun_uniform(
* @brief Gaussian kernel
*
* @tparam TData
* @param epsilon
* @param m
* @param simulated_stats Vector of statistics based on
* simulated data
* @param observed_stats Vector of observed statistics
* @param epsilon Epsilon parameter
* @param m LFMCMC model
* @return epiworld_double
*/
template<typename TData>
inline epiworld_double kernel_fun_gaussian(
const std::vector< epiworld_double >& stats_now,
const std::vector< epiworld_double >& stats_obs,
const std::vector< epiworld_double >& simulated_stats,
const std::vector< epiworld_double >& observed_stats,
epiworld_double epsilon,
LFMCMC<TData>* m
) {

epiworld_double ans = 0.0;
for (size_t p = 0u; p < m->get_n_params(); ++p)
ans += std::pow(stats_obs[p] - stats_now[p], 2.0);
ans += std::pow(observed_stats[p] - simulated_stats[p], 2.0);

return std::exp(
-.5 * (ans/std::pow(1 + std::pow(epsilon, 2.0)/3.0, 2.0))
Expand Down

0 comments on commit 2f42c2e

Please sign in to comment.