Skip to content

Commit

Permalink
Forcing model to reset agents (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon authored Apr 7, 2024
1 parent c643039 commit 10ebb03
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 349 deletions.
9 changes: 6 additions & 3 deletions examples/10-likelihood-free-mcmc/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// #include "../../include/epiworld/epiworld.hpp"
#include "../../include/epiworld/epiworld.hpp"

#define EPI_DEBUG
#include "../../include/epiworld/math/lfmcmc.hpp"



using namespace epiworld;

epimodels::ModelSIR<> model;
Expand Down Expand Up @@ -53,7 +57,7 @@ int main()
model, // Model
"covid", // Name of the virus
.1, // Initial prevalence
.9, // Infectiousness (par[1])
.1, // Infectiousness (par[1])
.3 // Immune Recovery (par[0])
);

Expand All @@ -69,7 +73,6 @@ int main()
lfmcmc.set_kernel_fun(kernel_fun_gaussian<std::vector<int>>);

// Simulating some data
model.set_backup();
model.verbose_off();
model.run(50, 122);
model.print();
Expand All @@ -82,7 +85,7 @@ int main()

std::vector< epiworld_double > par0 = {.5, .5};

lfmcmc.run(par0, 1000, 1);
lfmcmc.run(par0, 2000, 1);

lfmcmc.set_par_names({"Immune recovery", "Infectiousness"});
lfmcmc.set_stats_names(model.get_states());
Expand Down
7 changes: 7 additions & 0 deletions include/epiworld/math/lfmcmc/lfmcmc-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ inline LFMCMCProposalFun<TData> make_proposal_norm_reflective(

}

#ifdef EPI_DEBUG
for (auto & p : params_now)
if (p < lb || p > ub)
throw std::range_error("The parameter is out of bounds.");
#endif


return;

};
Expand Down
24 changes: 11 additions & 13 deletions include/epiworld/model-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2039,21 +2039,19 @@ inline void Model<TSeq>::reset() {
}
#endif

}
else
{
for (auto & p : population)
p.reset();
}

#ifdef EPI_DEBUG
for (auto & a: population)
{
if (a.get_state() != 0u)
throw std::logic_error("Model::reset population doesn't match."
"Some agents are not in the baseline state.");
}
#endif
for (auto & p : population)
p.reset();

#ifdef EPI_DEBUG
for (auto & a: population)
{
if (a.get_state() != 0u)
throw std::logic_error("Model::reset population doesn't match."
"Some agents are not in the baseline state.");
}
#endif

if (entities_backup.size() != 0)
{
Expand Down
Loading

0 comments on commit 10ebb03

Please sign in to comment.