(
op: &Operator,
left: &Distribution,
right: &Distribution,
)
| 821 | note = "Part of the unused Statistics V2 framework; see https://github.com/apache/datafusion/pull/22071" |
| 822 | )] |
| 823 | pub fn compute_mean( |
| 824 | op: &Operator, |
| 825 | left: &Distribution, |
| 826 | right: &Distribution, |
| 827 | ) -> Result<ScalarValue> { |
| 828 | let (left_mean, right_mean) = (left.mean()?, right.mean()?); |
| 829 | |
| 830 | match op { |
| 831 | Operator::Plus => return left_mean.add_checked(right_mean), |
| 832 | Operator::Minus => return left_mean.sub_checked(right_mean), |
| 833 | // Note the independence assumption below: |
| 834 | Operator::Multiply => return left_mean.mul_checked(right_mean), |
| 835 | // TODO: We can calculate the mean for division when we support reciprocals, |
| 836 | // or know the distributions of the operands. For details, see: |
| 837 | // |
| 838 | // <https://en.wikipedia.org/wiki/Algebra_of_random_variables> |
| 839 | // <https://stats.stackexchange.com/questions/185683/distribution-of-ratio-between-two-independent-uniform-random-variables> |
| 840 | // |
| 841 | // Fall back to an unknown mean value for division: |
| 842 | Operator::Divide => {} |
| 843 | // Fall back to an unknown mean value for other cases: |
| 844 | _ => {} |
| 845 | } |
| 846 | let target_type = Distribution::target_type(&[&left_mean, &right_mean])?; |
| 847 | ScalarValue::try_from(target_type) |
| 848 | } |
| 849 | |
| 850 | /// Computes the median value for the result of the given binary operation on |
| 851 | /// two unknown quantities represented by its [`Distribution`] objects. Currently, |
no test coverage detected
searching dependent graphs…