-
Notifications
You must be signed in to change notification settings - Fork 2
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
Correcting minor bug in dist functions and adding optional overwrite to read and add params #54
base: master
Are you sure you want to change the base?
Changes from all commits
277db63
5d3269a
79b8bd3
17a4816
2a6700a
e60f528
fce8670
1a2af8c
82472d7
331845c
56ccc2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2035,18 +2035,23 @@ | |
template<typename TSeq> | ||
inline epiworld_double Model<TSeq>::add_param( | ||
epiworld_double initial_value, | ||
std::string pname | ||
std::string pname, | ||
bool overwrite | ||
) { | ||
|
||
if (parameters.find(pname) == parameters.end()) | ||
parameters[pname] = initial_value; | ||
else if (!overwrite) | ||
throw std::logic_error("The parameter " + pname + " already exists."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests to cover this case and specific error message |
||
else | ||
parameters[pname] = initial_value; | ||
|
||
return initial_value; | ||
|
||
} | ||
|
||
template<typename TSeq> | ||
inline void Model<TSeq>::read_params(std::string fn) | ||
inline void Model<TSeq>::read_params(std::string fn, bool overwrite) | ||
{ | ||
|
||
std::ifstream paramsfile(fn); | ||
|
@@ -2084,7 +2089,8 @@ | |
std::regex_replace( | ||
match[1u].str(), | ||
std::regex("^\\s+|\\s+$"), | ||
"") | ||
""), | ||
overwrite | ||
); | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,8 +64,10 @@ | |
{ | ||
n_to_distribute = static_cast<int>(std::floor(prevalence * n)); | ||
|
||
if (n_to_distribute == n) | ||
n_to_distribute--; | ||
// Correcting for possible rounding errors | ||
if (n_to_distribute == (n + 1)) | ||
--n_to_distribute; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same questions as above: why not set |
||
|
||
} | ||
else | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,15 +62,18 @@ | |
idx.push_back(agent.get_id()); | ||
|
||
// Picking how many | ||
size_t n = model->size(); | ||
int n = model->size(); | ||
int n_available = static_cast<int>(idx.size()); | ||
int n_to_sample; | ||
if (prevalence_as_proportion) | ||
{ | ||
n_to_sample = static_cast<int>(std::floor(prevalence * n)); | ||
n_to_sample = static_cast<int>(std::floor( | ||
prevalence * static_cast< epiworld_double >(n) | ||
)); | ||
|
||
if (n_to_sample == static_cast<int>(n)) | ||
n_to_sample--; | ||
// Correcting for possible overflow | ||
if (n_to_sample == (n + 1)) | ||
--n_to_sample; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same questions as above |
||
} | ||
else | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions here:
n_to_sample = static_cast<int>(n);
instead of--n_to_sample
?n_to_sample
to be greater than(static_cast<int>(n) + 1))
? Or does it just not need to be corrected if so?