def test_valuewithsamples_equality() -> None:
    value = ValueWithSamples(1, np.array([1, 2, 3]))
    isequal = ValueWithSamples(1, np.array([1, 2, 3]))
    isnotequal_1 = ValueWithSamples(2, np.array([1, 2, 3]))
    isnotequal_2 = ValueWithSamples(1, np.array([2, 2, 3]))
    isnotequal_3 = ValueWithSamples(2, np.array([2, 2, 3]))
    assert value == isequal
    assert value != isnotequal_1
    assert value != isnotequal_2
    assert value != isnotequal_3
Beispiel #2
0
    def std(self) -> ValueWithSamples[float]:
        """
        Compute the standard deviation.

        Returns
        -------
        ValueWithSamples
            the (weighted) standard deviation of the (weighted) fill values and
            bootstrap resamples.
        """
        variance = self.variance()
        return ValueWithSamples(np.sqrt(variance.nominal),
                                np.sqrt(variance.samples))
Beispiel #3
0
    def mean(self) -> ValueWithSamples[float]:
        """
        Compute the mean.

        Returns
        -------
        ValueWithSamples
            the (weighted) mean of the (weighted) fill values and bootstrap resamples.
        """
        nominal = float(
            _mean(sumwt=self._sum_wt.nominal.view(),
                  sumw=self._sum_w.nominal.view()))
        samples = _mean(sumwt=self._sum_wt.samples.view(),
                        sumw=self._sum_w.samples.view())
        return ValueWithSamples(nominal, samples.flatten())
Beispiel #4
0
    def variance(self) -> ValueWithSamples[float]:
        """
        Compute the variance.

        Returns
        -------
        ValueWithSamples
            the (weighted) variance of the (weighted) fill values and bootstrap
            resamples.
        """
        nominal = float(
            _variance(
                sumw=self._sum_w.nominal.view(),
                sumwt=self._sum_wt.nominal.view(),
                sumwt2=self._sum_wt2.nominal.view(),
            ))
        samples = _variance(
            sumw=self._sum_w.samples.view(),
            sumwt=self._sum_wt.samples.view(),
            sumwt2=self._sum_wt2.samples.view(),
        )
        return ValueWithSamples(nominal, samples.flatten())
Beispiel #5
0
    def skewness(self) -> ValueWithSamples[float]:
        """
        Compute the skewness.

        Returns
        -------
        ValueWithSamples
            the (weighted) skewness of the (weighted) fill values and bootstrap
            resamples.
        """
        nominal = float(
            _skewness(
                sumw=self._sum_w.nominal.view(),
                sumwt=self._sum_wt.nominal.view(),
                sumwt2=self._sum_wt2.nominal.view(),
                sumwt3=self._sum_wt3.nominal.view(),
            ))
        samples = _skewness(
            sumw=self._sum_w.samples.view(),
            sumwt=self._sum_wt.samples.view(),
            sumwt2=self._sum_wt2.samples.view(),
            sumwt3=self._sum_wt3.samples.view(),
        )
        return ValueWithSamples(nominal, samples.flatten())
def test_valuewithsamples_addition() -> None:
    lhs = ValueWithSamples(1, np.array([1, 2, 3]))
    rhs = ValueWithSamples(2, np.array([4, 5, 6]))
    total = lhs + rhs
    assert total.nominal == 3
    assert np.array_equal(total.samples, [5, 7, 9])
def test_valuewithsamples_division() -> None:
    lhs = ValueWithSamples(4, np.array([4, 9, 16]))
    rhs = ValueWithSamples(2, np.array([2, 3, 4]))
    total = lhs / rhs
    assert total.nominal == 2
    assert np.array_equal(total.samples, [2, 3, 4])
def test_valuewithsamples_multiplication() -> None:
    lhs = ValueWithSamples(2, np.array([1, 2, 3]))
    rhs = ValueWithSamples(3, np.array([4, 5, 6]))
    total = lhs * rhs
    assert total.nominal == 6
    assert np.array_equal(total.samples, [4, 10, 18])
def test_valuewithsamples_subtraction() -> None:
    lhs = ValueWithSamples(1, np.array([1, 2, 3]))
    rhs = ValueWithSamples(2, np.array([4, 5, 6]))
    total = lhs - rhs
    assert total.nominal == -1
    assert np.array_equal(total.samples, [-3, -3, -3])