def test_cv_update_batch(): cv1 = ContinuousValue() cv2 = ContinuousValue() nums = [random() for i in range(10)] for n in nums: cv1.update(n) cv2.update_batch(nums) assert cv1.unbiased_mean() == cv2.unbiased_mean() assert cv1.biased_std() == cv2.biased_std()
def test_cv_unbiased_std(): cv = ContinuousValue() assert cv.unbiased_std() == 0 true_std = 10 error_biased = [] error_unbiased = [] for _ in range(100): cv = ContinuousValue() for _ in range(4): cv.update(normalvariate(0, true_std)) error_biased.append(cv.biased_std() - true_std) error_unbiased.append(cv.unbiased_std() - true_std) assert abs(sum(error_unbiased)) < abs(sum(error_biased))
def test_cv_biased_std(): cv = ContinuousValue() for _ in range(1000): cv.update(normalvariate(0, 1)) assert cv.biased_std() - 1 <= 0.1