ncsu-landscape-dynamics / pops-core

PoPS Core: C++ library for the Pest or Pathogen Spread Model
https://ncsu-landscape-dynamics.github.io/pops-core
GNU General Public License v2.0
5 stars 2 forks source link

Round to the nearest integer value #218

Open wenzeslaus opened 6 months ago

wenzeslaus commented 6 months ago

Instead of floor or ceil, always round to the nearest integer value as soon as the floating point calculation is finished.

This changes results in r.pops.spread and presumably in rpops, too.

wenzeslaus commented 6 months ago

I computed a raster which is a difference original_dead - new_dead.

There are only cells with -1 in the first year (sum -414):

Screenshot from 2024-03-13 16-43-41

For the last year, it is more variable (min: -10, max: 13, sum: 5650, mean: 0.201901, mean excluding zeros: 1.13614):

Screenshot from 2024-03-13 16-44-42

The pattern copies the data.

The overall impact on the average infected count (5 runs) is significant:

Before (max 6)

Screenshot from 2024-03-13 17-16-02

After (max 3.8)

Screenshot from 2024-03-13 17-15-52

wenzeslaus commented 6 months ago

Modified code and modified test

For a selected r.pops.spread test (test_outputs_mortality_treatment, Check mortality together with treatment), the following counts of dead hosts are produced for the original version with floor (and some ceil) and the version with round.

In the test, I changed mortality from 0.5 to 0.4 for the new version with round which creates more aligned totals and the image is visually also more aligned with the original. This similarity is supported by the differences between average of infected.

year floor, 0.5 round, 0.4
2019 782 713
2020 2483 2374
2021 6552 6771
2022 15037 16143

Screenshot from 2024-03-15 10-24-15

Relative difference for average infected

old - new) / ((old + new) / 2)

Screenshot from 2024-03-15 10-06-47

n: 15188
minimum: -2
maximum: 2
range: 4
mean: -0.0647932
mean of absolute values: 1.04301
standard deviation: 1.31813
sum: -984.079422039648

total null and non-null cells: 27984
total null cells: 12796

Difference for average infected

old - new

Screenshot from 2024-03-15 09-59-26

n: 27984
minimum: -4
maximum: 3.2
range: 7.2
mean: -0.0437536
mean of absolute values: 0.272727
standard deviation: 0.512051
sum: -1224.4
wenzeslaus commented 1 month ago

TODO: Split this into multiple PR to clear identify the source of differences.