PsiACE commented on code in PR #59:
URL: https://github.com/apache/datasketches-rust/pull/59#discussion_r2656250848
##########
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.get_lower_bound(2).unwrap();
+ /// let upper_bound = sketch.get_upper_bound(2).unwrap();
+ ///
+ /// assert!(lower_bound <= estimate);
+ /// assert!(estimate <= upper_bound);
+ /// ```
+ pub fn get_lower_bound(&self, num_std_devs: u32) -> Result<f64, Error> {
Review Comment:
As mentioned in the other PR, we don't need the `get_` prefix.
##########
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.get_lower_bound(2).unwrap();
+ /// let upper_bound = sketch.get_upper_bound(2).unwrap();
+ ///
+ /// assert!(lower_bound <= estimate);
+ /// assert!(estimate <= upper_bound);
+ /// ```
+ pub fn get_lower_bound(&self, num_std_devs: u32) -> Result<f64, Error> {
+ if !self.is_estimation_mode() {
+ return Ok(self.num_retained() as f64);
+ }
+ binomial_bounds::get_lower_bound(self.num_retained() as u64,
self.theta(), num_std_devs)
+ }
+
+ /// Returns the approximate upper 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(ub)` where `ub` is the approximate upper 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.get_lower_bound(2).unwrap();
+ /// let upper_bound = sketch.get_upper_bound(2).unwrap();
+ ///
+ /// assert!(lower_bound <= estimate);
+ /// assert!(estimate <= upper_bound);
+ /// ```
+ pub fn get_upper_bound(&self, num_std_devs: u32) -> Result<f64, Error> {
Review Comment:
Same as above
--
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]