def test_bootstrapmoment_standard_distributions( with_weights: bool, generator: Callable[[], np.ndarray], mu: float, sigma: float, skewness: float, ) -> None: moment = BootstrapMoment(numsamples=100, rng=1234) values = generator() if with_weights: weight = np.random.default_rng(91011).uniform(size=values.shape) moment.fill(values, weight=weight) else: moment.fill(values) tolerance = 0.01 assert moment.mean().nominal == pytest.approx(mu, rel=tolerance, abs=tolerance) assert np.average(moment.mean().samples) == pytest.approx(mu, rel=tolerance, abs=tolerance) assert moment.std().nominal == pytest.approx(sigma, rel=tolerance, abs=tolerance) assert np.average(moment.std().samples) == pytest.approx(sigma, rel=tolerance, abs=tolerance) assert moment.skewness().nominal == pytest.approx(skewness, rel=tolerance, abs=tolerance) assert np.average(moment.skewness().samples) == pytest.approx( skewness, rel=tolerance, abs=tolerance)
def test_bootstrapmoment_std_deviation() -> None: moment = BootstrapMoment(numsamples=10000, rng=1234) values = np.arange(100, dtype=float) moment.fill(values) assert abs(moment.variance().nominal - np.var(values)) < 0.01 assert abs(np.average(moment.variance().samples) - np.var(values)) < 10.0 assert abs(moment.std().nominal - np.std(values)) < 0.01 assert abs(np.average(moment.std().samples) - np.std(values)) < 1.0
def test_bootstrapmoment_array_shapes() -> None: moment = BootstrapMoment(numsamples=3, rng=1234) values = np.arange(100, dtype=float) moment.fill(values) assert (moment.mean().samples.shape == moment.std().samples.shape == moment.variance().samples.shape == moment.skewness().samples.shape == (3, ))