tisonkun commented on code in PR #59:
URL: https://github.com/apache/datasketches-rust/pull/59#discussion_r2660026906
##########
datasketches/src/theta/sketch.rs:
##########
@@ -116,6 +118,89 @@ impl ThetaSketch {
pub fn iter(&self) -> impl Iterator<Item = u64> + '_ {
self.table.iter()
}
+
+ /// Returns the approximate lower error bound given the specified number
of Standard Deviations.
+ ///
+ /// # Arguments
+ ///
+ /// * `num_std_devs` - The number of standard deviations from the mean for
the tail bounds. Must
+ /// be 1, 2, or 3, corresponding to approximately 67%, 95% and 99%
confidence intervals.
+ ///
+ /// # Returns
+ ///
+ /// Returns `Ok(lb)` where `lb` is the approximate lower bound value.
+ ///
+ /// # Errors
+ ///
+ /// Returns an error if `num_std_devs` is not 1, 2, or 3.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use datasketches::theta::ThetaSketch;
+ ///
+ /// let mut sketch = ThetaSketch::builder().lg_k(12).build();
+ /// for i in 0..10000 {
+ /// sketch.update(i);
+ /// }
+ ///
+ /// let estimate = sketch.estimate();
+ /// let lower_bound = sketch.lower_bound(2).unwrap();
+ /// let upper_bound = sketch.upper_bound(2).unwrap();
+ ///
+ /// assert!(lower_bound <= estimate);
+ /// assert!(estimate <= upper_bound);
+ /// ```
+ pub fn lower_bound(&self, num_std_devs: u32) -> Result<f64, Error> {
+ if !self.is_estimation_mode() {
+ return Ok(self.num_retained() as f64);
+ }
+ binomial_bounds::lower_bound(self.num_retained() as u64, self.theta(),
num_std_devs)
+ }
Review Comment:
We already have a `NumStdDev` enum:
https://github.com/apache/datasketches-rust/blob/9ade42d639afd013d19c3454a14773b6d54edc25/datasketches/src/hll/estimator.rs#L327-L341
You can reuse it by moving the struct to a shared module level and thus we
would never error here.
Besides, we may consider where to place these shared structs, including the
`ResizeFactor`. `datasketches::{NumStdDev, ResizeFactor}` is fair enough now,
but perhaps pollute the top-level namespace too much.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]