예제 #1
0
def test_bootstrapmoment_skewness() -> None:
    moment = BootstrapMoment(numsamples=10000, rng=1234)
    values = np.arange(100, dtype=float)
    moment.fill(values)
    assert abs(moment.skewness().nominal - _skewness(values)) < 0.01
    assert abs(np.average(moment.skewness().samples) -
               _skewness(values)) < 10.0
예제 #2
0
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)
예제 #3
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, ))