Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcing model to reset agents #12

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading