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

Correcting minor bug in dist functions and adding optional overwrite to read and add params #54

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

gvegayon
Copy link
Member

This pull request includes several changes to the epiworld library, focusing on version updates, parameter handling, and correcting potential overflow and rounding errors in distribution functions. The most important changes are summarized below:

Version Update:

  • Updated the patch version from 0 to 1 in epiworld.hpp and include/epiworld/epiworld.hpp. [1] [2]

Parameter Handling:

  • Modified the add_param and read_params methods in class Model to include an overwrite flag, allowing parameters to be overwritten if they already exist. [1] [2]
  • Updated the implementation of add_param and read_params methods to handle the overwrite flag correctly in epiworld.hpp and include/epiworld/model-meat.hpp. [1] [2] [3] [4]

Overflow and Rounding Corrections:

  • Corrected potential overflow and rounding errors in the distribute_virus_randomly, distribute_tool_randomly, and distribute_entity_randomly functions by adjusting the conditions under which the number of items to distribute is decremented. [1] [2] [3] [4] [5]

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.03%. Comparing base (08b0c2e) to head (56ccc2d).

Files with missing lines Patch % Lines
include/epiworld/model-meat.hpp 0.00% 3 Missing ⚠️
include/epiworld/entity-distribute-meat.hpp 0.00% 1 Missing ⚠️
include/epiworld/tool-distribute-meat.hpp 0.00% 1 Missing ⚠️
include/epiworld/virus-distribute-meat.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #54      +/-   ##
==========================================
- Coverage   84.12%   84.03%   -0.09%     
==========================================
  Files          42       42              
  Lines        2822     2825       +3     
==========================================
  Hits         2374     2374              
- Misses        448      451       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Base automatically changed from geometric-dist to master February 24, 2025 20:01
@gvegayon gvegayon requested a review from apulsipher February 26, 2025 16:24
Copy link
Contributor

@apulsipher apulsipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things to address before merging this, but mostly looking good!

if (n_to_sample > static_cast<int>(n))

// Correcting for possible overflow
if (n_to_sample == (static_cast<int>(n) + 1))
--n_to_sample;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions here:

  1. Why not set n_to_sample = static_cast<int>(n); instead of --n_to_sample?
  2. Is it impossible for n_to_sample to be greater than (static_cast<int>(n) + 1))? Or does it just not need to be corrected if so?

n_to_distribute--;
// Correcting for possible rounding errors
if (n_to_distribute == (n + 1))
--n_to_distribute;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same questions as above: why not set = n? and can n_to_distribute exceed (n+1)?

n_to_sample--;
// Correcting for possible overflow
if (n_to_sample == (n + 1))
--n_to_sample;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same questions as above

) {

if (parameters.find(pname) == parameters.end())
parameters[pname] = initial_value;
else if (!overwrite)
throw std::logic_error("The parameter " + pname + " already exists.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests to cover this case and specific error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants