Add support for weighted fraction accumulator #385
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.
This PR extends
fraction
to weighted samples to address issue #367.I took the approach of creating a new
weighted_fraction
class. This class is a composition of two classes:fraction
and a new internal classsum_of_weights_squared
. I explain the thought process behind these choices.The classes$\sum (w^2)$ . So, I turned this piece of information into a class
sum
,mean
, andfraction
are non-weighted. Each of these classes could almost function as a weighted class, but requires one additional piece of information: the sum of the weights squared, that is to saysum_of_weights_squared
. I created the classweighted_fraction
by puttingfraction
andsum_of_weights_squared
together.The code passes all unit tests (locally), but has
Wpedantic
warnings becausewilson_solve
uses a designated initializer (i.e.,wilson_solve({.n_eff=n_eff, .p_hat=p_hat, .correction=correction})
). There's likely a good way to avoid getting this warning, while also enforcing input meaning, but I'm missing it.