Widen RateStatistic domain to NonNegativeReal - #138
Merged
Conversation
The statistic exposes mean, variance and coefficient of variation through one RealVector domain, so that domain has to admit every value the three can take. Variance and coefficient of variation are exactly 0 whenever the branches share a rate, which is the ordinary state of affairs under a strict clock, and PositiveReal excludes 0 (lowerInclusive() is false): strict clock: mean=1.0 variance=0.0 cv=0.0 isValid() over all 3 : false Nothing in parser, core or inference calls isValid() yet, so this is latent rather than a crash today -- but the spec migration plainly intends that enforcement, and by then the class will have shipped and been adopted. NonNegativeReal still rejects negatives, which none of the three statistics can be. Adds RateStatisticTest: the strict-clock case (fails against PositiveReal), that negatives are still rejected, the weighted-mean and unweighted-variance values for varying rates, and the index guard on get() that this migration tightened from the legacy `dim > 3` check. beast-base suite: 462 tests, 0 failures.
Member
|
I think we need to review the domain of all rates. see also #68. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Targets
RateStatistic(#120) rather thanmaster, so it can go in before that PR merges.The problem
The new spec
RateStatisticdeclaresRealVector<PositiveReal>. It exposes three elements through that one domain — mean, variance, coefficient of variation — so the domain has to admit every value all three can take.Variance and coefficient of variation are exactly 0 whenever every branch carries the same rate. That is not a corner case: it is the ordinary state of affairs under a strict clock.
PositiveRealexcludes 0 (lowerInclusive()returns false), so:Nothing in
parser,coreorinferencecallsisValid()today, so this is latent rather than a crash. But the spec migration plainly intends that enforcement, and by the time it arrives the class will have shipped in a release and been adopted — so it is much cheaper to correct the type parameter now than to change it under users later.The change
PositiveReal→NonNegativeReal, plus a comment ongetDomain()recording why, so it does not get tightened back.NonNegativeRealstill rejects negatives, which none of the three statistics can be — the domain is widened by exactly the one value that was wrongly excluded, not loosened to plainReal.For what it is worth, the sibling migrated class in the same package,
beast.base.spec.evolution.Sum, declaresRealScalar<Real>rather than a tighter positive domain, so declaring only what is actually guaranteed looks like the established convention.Tests
Adds
RateStatisticTestwith four cases:isValid()holds. This one fails againstPositiveRealwith "the declared domain must admit zero", so it pins the fix down.get(). Worth locking in: the legacygetArrayValue(dim)guarded withdim > 3, sodim == 3fell through to anArrayIndexOutOfBoundsExceptionand negatives went unchecked. Rate statistic #120 quietly fixes that and the test records it.beast-base suite on this branch: 462 tests, 0 failures.