Skip to content

Commit

Permalink
Fix code for resolver=1 and resolver=2
Browse files Browse the repository at this point in the history
  • Loading branch information
vks committed Apr 30, 2021
1 parent 9eaef07 commit 88279ad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/moments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,23 @@ macro_rules! define_moments_common {
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "libm"))))]
#[inline]
pub fn sample_skewness(&self) -> f64 {
use num_traits::Float;

if self.n < 2 {
return 0.;
}
let n = self.n.to_f64().unwrap();
if self.n < 3 {
// Method of moments
return self.central_moment(3) /
num_traits::Float::powf(
Float::powf(
n * (self.central_moment(2) / (n - 1.)), 1.5
)
}
// Adjusted Fisher-Pearson standardized moment coefficient
num_traits::Float::sqrt(n * (n - 1.)) /
Float::sqrt(n * (n - 1.)) /
(n * (n - 2.)) *
num_traits::Float::powf(
Float::powf(
self.central_moment(3) / (self.central_moment(2) / n),
1.5
)
Expand Down
5 changes: 3 additions & 2 deletions src/moments/skewness.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use num_traits::Float;

/// Estimate the arithmetic mean, the variance and the skewness of a sequence of
/// numbers ("population").
///
Expand Down Expand Up @@ -98,8 +100,7 @@ impl Skewness {
let n = self.len().to_f64().unwrap();
let sum_2 = self.avg.sum_2;
debug_assert_ne!(sum_2, 0.);
num_traits::Float::sqrt(n) * self.sum_3
/ num_traits::Float::sqrt(sum_2*sum_2*sum_2)
Float::sqrt(n) * self.sum_3 / Float::sqrt(sum_2*sum_2*sum_2)
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/quantile.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use core::cmp::min;

use easy_cast::{Conv, ConvFloat};
use num_traits::ToPrimitive;
#[cfg(not(feature = "std"))]
use num_traits::Float;
use num_traits::{ToPrimitive, Float};
use float_ord::sort as sort_floats;
#[cfg(feature = "serde1")] use serde::{Serialize, Deserialize};

Expand Down Expand Up @@ -182,7 +180,7 @@ impl Estimate for Quantile {
let d = self.m[i] - self.n[i].to_f64().unwrap();
if d >= 1. && self.n[i + 1] - self.n[i] > 1 ||
d <= -1. && self.n[i - 1] - self.n[i] < -1 {
let d = d.signum();
let d = Float::signum(d);
let q_new = self.parabolic(i, d);
if self.q[i - 1] < q_new && q_new < self.q[i + 1] {
self.q[i] = q_new;
Expand Down
3 changes: 2 additions & 1 deletion src/weighted_mean.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[cfg(feature = "serde1")] use serde::{Serialize, Deserialize};
use num_traits::Float;
use super::{MeanWithError, Estimate, Merge};

/// Estimate the weighted and unweighted arithmetic mean of a sequence of
Expand Down Expand Up @@ -283,7 +284,7 @@ impl WeightedMeanWithError {
#[cfg_attr(doc_cfg, doc(cfg(any(feature = "std", feature = "libm"))))]
#[inline]
pub fn error(&self) -> f64 {
num_traits::Float::sqrt(self.variance_of_weighted_mean())
Float::sqrt(self.variance_of_weighted_mean())
}
}

Expand Down

0 comments on commit 88279ad

Please sign in to comment.