CalcNumStrataRetainedExact
- class CalcNumStrataRetainedExact
Functor to provide member function implementation in Policy class.
- __init__(policy_spec: PolicySpec | None) None [source]
Methods
- __call__(policy: PolicyCouplerBase, num_strata_deposited: int) int [source]
Exactly how many strata are retained after n deposited?
The calculation can be written mathematically as,
weight of binary expansion of n (i.e., #1’s set in binary repr) + sum(
floor( log2(n//r) ) for r from 1 to r inclusive
) + 1
where
n = num_strata_deposited - 1 r = resolution
- This expression for exact number deposited was extrapolated from
resolution = 0, <https://oeis.org/A063787>
resolution = 1, <https://oeis.org/A056791>
and is unit tested extensively.
Note that the implementation must include a special case to account for n < r causing log2(0). In this case, the number of strata retained is equal to the number deposited (i.e., none have been discarded yet).
- __init__(policy_spec: PolicySpec | None) None [source]