Trait ndarray_stats::SummaryStatisticsExt
source · pub trait SummaryStatisticsExt<A, S, D>{
Show 16 methods
// Required methods
fn mean(&self) -> Result<A, EmptyInput>
where A: Clone + FromPrimitive + Add<Output = A> + Div<Output = A> + Zero;
fn weighted_mean(&self, weights: &Self) -> Result<A, MultiInputError>
where A: Copy + Div<Output = A> + Mul<Output = A> + Zero;
fn weighted_sum(&self, weights: &Self) -> Result<A, MultiInputError>
where A: Copy + Mul<Output = A> + Zero;
fn weighted_mean_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
) -> Result<Array<A, D::Smaller>, MultiInputError>
where A: Copy + Div<Output = A> + Mul<Output = A> + Zero,
D: RemoveAxis;
fn weighted_sum_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
) -> Result<Array<A, D::Smaller>, MultiInputError>
where A: Copy + Mul<Output = A> + Zero,
D: RemoveAxis;
fn harmonic_mean(&self) -> Result<A, EmptyInput>
where A: Float + FromPrimitive;
fn geometric_mean(&self) -> Result<A, EmptyInput>
where A: Float + FromPrimitive;
fn weighted_var(
&self,
weights: &Self,
ddof: A,
) -> Result<A, MultiInputError>
where A: AddAssign + Float + FromPrimitive;
fn weighted_std(
&self,
weights: &Self,
ddof: A,
) -> Result<A, MultiInputError>
where A: AddAssign + Float + FromPrimitive;
fn weighted_var_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
ddof: A,
) -> Result<Array<A, D::Smaller>, MultiInputError>
where A: AddAssign + Float + FromPrimitive,
D: RemoveAxis;
fn weighted_std_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
ddof: A,
) -> Result<Array<A, D::Smaller>, MultiInputError>
where A: AddAssign + Float + FromPrimitive,
D: RemoveAxis;
fn kurtosis(&self) -> Result<A, EmptyInput>
where A: Float + FromPrimitive;
fn skewness(&self) -> Result<A, EmptyInput>
where A: Float + FromPrimitive;
fn central_moment(&self, order: u16) -> Result<A, EmptyInput>
where A: Float + FromPrimitive;
fn central_moments(&self, order: u16) -> Result<Vec<A>, EmptyInput>
where A: Float + FromPrimitive;
fn __private__(&self, _: PrivateMarker);
}
Expand description
Extension trait for ArrayBase
providing methods
to compute several summary statistics (e.g. mean, variance, etc.).
Required Methods§
sourcefn mean(&self) -> Result<A, EmptyInput>
fn mean(&self) -> Result<A, EmptyInput>
Returns the arithmetic mean
x̅ of all elements in the array:
1 n
x̅ = ― ∑ xᵢ
n i=1
If the array is empty, Err(EmptyInput)
is returned.
Panics if A::from_usize()
fails to convert the number of elements in the array.
sourcefn weighted_mean(&self, weights: &Self) -> Result<A, MultiInputError>
fn weighted_mean(&self, weights: &Self) -> Result<A, MultiInputError>
Returns the [arithmetic weighted mean
] x̅ of all elements in the array. Use weighted_sum
if the weights
are normalized (they sum up to 1.0).
n
∑ wᵢxᵢ
i=1
x̅ = ―――――――――
n
∑ wᵢ
i=1
Panics if division by zero panics for type A.
The following errors may be returned:
MultiInputError::EmptyInput
ifself
is emptyMultiInputError::ShapeMismatch
ifself
andweights
don’t have the same shape
[arithmetic weighted mean
] https://en.wikipedia.org/wiki/Weighted_arithmetic_mean
sourcefn weighted_sum(&self, weights: &Self) -> Result<A, MultiInputError>
fn weighted_sum(&self, weights: &Self) -> Result<A, MultiInputError>
Returns the weighted sum of all elements in the array, that is, the dot product of the
arrays self
and weights
. Equivalent to weighted_mean
if the weights
are normalized.
n
x̅ = ∑ wᵢxᵢ
i=1
The following errors may be returned:
MultiInputError::ShapeMismatch
ifself
andweights
don’t have the same shape
sourcefn weighted_mean_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
) -> Result<Array<A, D::Smaller>, MultiInputError>
fn weighted_mean_axis( &self, axis: Axis, weights: &ArrayBase<S, Ix1>, ) -> Result<Array<A, D::Smaller>, MultiInputError>
Returns the [arithmetic weighted mean
] x̅ along axis
. Use weighted_mean_axis
if the
weights
are normalized.
n
∑ wᵢxᵢ
i=1
x̅ = ―――――――――
n
∑ wᵢ
i=1
Panics if axis
is out of bounds.
The following errors may be returned:
MultiInputError::EmptyInput
ifself
is emptyMultiInputError::ShapeMismatch
ifself
length along axis is not equal toweights
length
[arithmetic weighted mean
] https://en.wikipedia.org/wiki/Weighted_arithmetic_mean
sourcefn weighted_sum_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
) -> Result<Array<A, D::Smaller>, MultiInputError>
fn weighted_sum_axis( &self, axis: Axis, weights: &ArrayBase<S, Ix1>, ) -> Result<Array<A, D::Smaller>, MultiInputError>
Returns the weighted sum along axis
, that is, the dot product of weights
and each lane
of self
along axis
. Equivalent to weighted_mean_axis
if the weights
are normalized.
n
x̅ = ∑ wᵢxᵢ
i=1
Panics if axis
is out of bounds.
The following errors may be returned
MultiInputError::ShapeMismatch
ifself
andweights
don’t have the same shape
sourcefn harmonic_mean(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
fn harmonic_mean(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
Returns the harmonic mean
HM(X)
of all elements in the array:
⎛ n ⎞⁻¹
HM(X) = n ⎜ ∑ xᵢ⁻¹⎟
⎝i=1 ⎠
If the array is empty, Err(EmptyInput)
is returned.
Panics if A::from_usize()
fails to convert the number of elements in the array.
sourcefn geometric_mean(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
fn geometric_mean(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
Returns the geometric mean
GM(X)
of all elements in the array:
⎛ n ⎞¹⁄ₙ
GM(X) = ⎜ ∏ xᵢ⎟
⎝i=1 ⎠
If the array is empty, Err(EmptyInput)
is returned.
Panics if A::from_usize()
fails to convert the number of elements in the array.
sourcefn weighted_var(&self, weights: &Self, ddof: A) -> Result<A, MultiInputError>
fn weighted_var(&self, weights: &Self, ddof: A) -> Result<A, MultiInputError>
Return weighted variance of all elements in the array.
The weighted variance is computed using the West, D. H. D.
incremental algorithm.
Equivalent to var_axis
if the weights
are normalized.
The parameter ddof
specifies the “delta degrees of freedom”. For example, to calculate the
population variance, use ddof = 0
, or to calculate the sample variance, use ddof = 1
.
Panics if ddof
is less than zero or greater than one, or if axis
is out of bounds,
or if A::from_usize()
fails for zero or one.
sourcefn weighted_std(&self, weights: &Self, ddof: A) -> Result<A, MultiInputError>
fn weighted_std(&self, weights: &Self, ddof: A) -> Result<A, MultiInputError>
Return weighted standard deviation of all elements in the array.
The weighted standard deviation is computed using the West, D. H. D.
incremental
algorithm. Equivalent to var_axis
if the weights
are normalized.
The parameter ddof
specifies the “delta degrees of freedom”. For example, to calculate the
population variance, use ddof = 0
, or to calculate the sample variance, use ddof = 1
.
Panics if ddof
is less than zero or greater than one, or if axis
is out of bounds,
or if A::from_usize()
fails for zero or one.
sourcefn weighted_var_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
ddof: A,
) -> Result<Array<A, D::Smaller>, MultiInputError>
fn weighted_var_axis( &self, axis: Axis, weights: &ArrayBase<S, Ix1>, ddof: A, ) -> Result<Array<A, D::Smaller>, MultiInputError>
Return weighted variance along axis
.
The weighted variance is computed using the West, D. H. D.
incremental algorithm.
Equivalent to var_axis
if the weights
are normalized.
The parameter ddof
specifies the “delta degrees of freedom”. For example, to calculate the
population variance, use ddof = 0
, or to calculate the sample variance, use ddof = 1
.
Panics if ddof
is less than zero or greater than one, or if axis
is out of bounds,
or if A::from_usize()
fails for zero or one.
sourcefn weighted_std_axis(
&self,
axis: Axis,
weights: &ArrayBase<S, Ix1>,
ddof: A,
) -> Result<Array<A, D::Smaller>, MultiInputError>
fn weighted_std_axis( &self, axis: Axis, weights: &ArrayBase<S, Ix1>, ddof: A, ) -> Result<Array<A, D::Smaller>, MultiInputError>
Return weighted standard deviation along axis
.
The weighted standard deviation is computed using the West, D. H. D.
incremental
algorithm. Equivalent to var_axis
if the weights
are normalized.
The parameter ddof
specifies the “delta degrees of freedom”. For example, to calculate the
population variance, use ddof = 0
, or to calculate the sample variance, use ddof = 1
.
Panics if ddof
is less than zero or greater than one, or if axis
is out of bounds,
or if A::from_usize()
fails for zero or one.
sourcefn kurtosis(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
fn kurtosis(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
Returns the kurtosis Kurt[X]
of all elements in the array:
Kurt[X] = μ₄ / σ⁴
where μ₄ is the fourth central moment and σ is the standard deviation of the elements in the array.
This is sometimes referred to as Pearson’s kurtosis. Fisher’s kurtosis can be computed by subtracting 3 from Pearson’s kurtosis.
If the array is empty, Err(EmptyInput)
is returned.
Panics if A::from_usize()
fails to convert the number of elements in the array.
sourcefn skewness(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
fn skewness(&self) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
Returns the Pearson’s moment coefficient of skewness γ₁ of all elements in the array:
γ₁ = μ₃ / σ³
where μ₃ is the third central moment and σ is the standard deviation of the elements in the array.
If the array is empty, Err(EmptyInput)
is returned.
Panics if A::from_usize()
fails to convert the number of elements in the array.
sourcefn central_moment(&self, order: u16) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
fn central_moment(&self, order: u16) -> Result<A, EmptyInput>where
A: Float + FromPrimitive,
Returns the p-th central moment of all elements in the array, μₚ:
1 n
μₚ = ― ∑ (xᵢ-x̅)ᵖ
n i=1
If the array is empty, Err(EmptyInput)
is returned.
The p-th central moment is computed using a corrected two-pass algorithm (see Section 3.5 in Pébay et al., 2016). Complexity is O(np) when n >> p, p > 1.
Panics if A::from_usize()
fails to convert the number of elements
in the array or if order
overflows i32
.
sourcefn central_moments(&self, order: u16) -> Result<Vec<A>, EmptyInput>where
A: Float + FromPrimitive,
fn central_moments(&self, order: u16) -> Result<Vec<A>, EmptyInput>where
A: Float + FromPrimitive,
Returns the first p central moments of all elements in the array, see central moment for more details.
If the array is empty, Err(EmptyInput)
is returned.
This method reuses the intermediate steps for the k-th moment to compute the (k+1)-th, being thus more efficient than repeated calls to central moment if the computation of central moments of multiple orders is required.
Panics if A::from_usize()
fails to convert the number of elements
in the array or if order
overflows i32
.
sourcefn __private__(&self, _: PrivateMarker)
fn __private__(&self, _: PrivateMarker)
This method makes this trait impossible to implement outside of
ndarray-stats
so that we can freely add new methods, etc., to
this trait without breaking changes.
We don’t anticipate any other crates needing to implement this trait, but if you do have such a use-case, please let us know.
Warning This method is not considered part of the public API, and client code should not rely on it being present. It may be removed in a non-breaking release.