traitecoevo / plant

Trait-Driven Models of Ecology and Evolution :evergreen_tree:
https://traitecoevo.github.io/plant
53 stars 20 forks source link

Small numerical variance in `demographic_equilibrium` tests #357

Closed aornugent closed 1 year ago

aornugent commented 1 year ago

As identified in #355, some fitness related functions are broken. The fitness branch brings these functions in line with latest version of the plant API.

The tests recently added in #355 nearly pass. I obtain a slightly different equilibrium birth rate at https://github.com/traitecoevo/plant/blob/2aab5cf6563d17546333482ca733fb0edcc87bd6/tests/testthat/test-support-fitness.R#L191

expect_equal(attr(patch_eq2, "offspring_production"), 17.31023, tolerance = 1e-4)
Error: attr(patch_eq2, "offspring_production") not equal to 17.31023.
1/1 mismatches
[1] 17.3 - 17.3 == 0.00706

attr(patch_eq2, "offspring_production")
[1] 17.31729

I also encounter a small difference at https://github.com/traitecoevo/plant/blob/d87ad24b79245e67fdcc76cad9077a2210a344dd/tests/testthat/test-support-fitness.R#L198

expect_equal(attr(patch_eq3, "offspring_production"), 17.30623, tolerance = 1e-4)
Error: attr(patch_eq3, "offspring_production") not equal to 17.30623.
1/1 mismatches
[1] 17.3 - 17.3 == 0.011

attr(patch_eq3, "offspring_production")
[1] 17.31727

Strangely, no error is encountered for the two species case that shortly follows.

dfalster commented 1 year ago

hi @aornugent

Yes! I also got small variations with the two species case in fitness branch compared to the PR on master (#355). You can see here that I updated the vals for 1 sp and 2sp tests

https://github.com/traitecoevo/plant/commit/453139a68d8438748a80ef9ca05f1459c4df51b0#diff-44125c38064dd77b4352946e0c5bbca191dc38081f4fabef600ba20139bf03a2L184

https://github.com/traitecoevo/plant/commit/453139a68d8438748a80ef9ca05f1459c4df51b0#diff-44125c38064dd77b4352946e0c5bbca191dc38081f4fabef600ba20139bf03a2L216

I wasn't able to run patch_eq2 and patch_eq3 so didn't update those

After all the changes in interface, these numbers are reassuringly concisent with the original, so I'm happy to accept them