def test_cv_unbiased_std(): for i in range(10): values = [random.normalvariate(0, 1) for i in range(10)] cv = ContinuousValue() cv.update_batch(values) assert (cv.unbiased_std() - ((len(values) * utils.std(values) / (len(values) - 1)) / utils.c4(len(values))) < 0.00000000001)
def unbiased_std(self): """Returns an unbiased estimate of the std This implementation uses Bessel's correction and Cochran's theorem: `<https://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation#Bias_correction>`_ :return: an unbiased estimate of the std :rtype: float .. seealso:: :meth:`concept_formation.utils.c4` """ if self.num < 2: return 0.0 return sqrt(self.meanSq / (self.num - 1)) / c4(self.num)
def unbiased_std(self): """ Returns an unbiased estimate of the std, but for n < 2 the std is estimated to be 0.0. This implementation uses Bessel's correction and Cochran's theorem: `<https://en.wikipedia.org/wiki/Unbiased_estimation_of_standard_deviation#Bias_correction>`_ :return: an unbiased estimate of the std :rtype: float .. seealso:: :meth:`concept_formation.utils.c4` """ if self.num < 2: return 0.0 return sqrt(self.meanSq / (self.num - 1)) / c4(self.num)
def test_c4(): with pytest.raises(ValueError): utils.c4(1)