/** * Returns the <a * href="http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values"> * population standard deviation</a> of the values. The count must be non-zero. * * <p>This is guaranteed to return zero if the dataset contains only exactly one finite value. It * is not guaranteed to return zero when the dataset consists of the same value multiple times, * due to numerical errors. However, it is guaranteed never to return a negative result. * * <h3>Non-finite values</h3> * * <p>If the dataset contains any non-finite values ({@link Double#POSITIVE_INFINITY}, {@link * Double#NEGATIVE_INFINITY}, or {@link Double#NaN}) then the result is {@link Double#NaN}. * * @throws IllegalStateException if the dataset is empty */ public double populationStandardDeviation() { return Math.sqrt(populationVariance()); }
/** * Returns the <a * href="http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values"> * population standard deviation</a> of the values. The count must be non-zero. * * <p>This is guaranteed to return zero if the dataset contains only exactly one finite value. It * is not guaranteed to return zero when the dataset consists of the same value multiple times, * due to numerical errors. However, it is guaranteed never to return a negative result. * * <h3>Non-finite values</h3> * * <p>If the dataset contains any non-finite values ({@link Double#POSITIVE_INFINITY}, {@link * Double#NEGATIVE_INFINITY}, or {@link Double#NaN}) then the result is {@link Double#NaN}. * * @throws IllegalStateException if the dataset is empty */ public double populationStandardDeviation() { return Math.sqrt(populationVariance()); }
/** * Returns the <a * href="http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values"> * population standard deviation</a> of the values. The count must be non-zero. * * <p>This is guaranteed to return zero if the dataset contains only exactly one finite value. It * is not guaranteed to return zero when the dataset consists of the same value multiple times, * due to numerical errors. However, it is guaranteed never to return a negative result. * * <h3>Non-finite values</h3> * * <p>If the dataset contains any non-finite values ({@link Double#POSITIVE_INFINITY}, {@link * Double#NEGATIVE_INFINITY}, or {@link Double#NaN}) then the result is {@link Double#NaN}. * * @throws IllegalStateException if the dataset is empty */ public double populationStandardDeviation() { return Math.sqrt(populationVariance()); }
public void testPopulationVariance() { try { EMPTY_STATS_VARARGS.populationVariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { EMPTY_STATS_ITERABLE.populationVariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { assertThat(ONE_VALUE_STATS.populationVariance()).isWithin(0.0).of(0.0); assertThat(Stats.of(POSITIVE_INFINITY).populationVariance()).isNaN(); assertThat(Stats.of(NEGATIVE_INFINITY).populationVariance()).isNaN(); assertThat(Stats.of(NaN).populationVariance()).isNaN(); assertThat(TWO_VALUES_STATS.populationVariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS / 2); assertThat(MANY_VALUES_STATS_VARARGS.populationVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT); double populationVariance = Stats.of(values.asIterable()).populationVariance(); if (values.hasAnyNonFinite()) { assertThat(populationVariance).named("population variance of " + values).isNaN(); assertThat(MANY_VALUES_STATS_ITERATOR.populationVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_SNAPSHOT.populationVariance()) .isWithin(ALLOWED_ERROR)
actualStats.populationVariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { assertThat(actualStats.populationVariance()).isWithin(0.0).of(0.0); assertThat(actualStats.min()).isWithin(ALLOWED_ERROR).of(expectedStats.min()); assertThat(actualStats.max()).isWithin(ALLOWED_ERROR).of(expectedStats.max()); } else { assertThat(actualStats.mean()).isWithin(ALLOWED_ERROR).of(expectedStats.mean()); assertThat(actualStats.populationVariance()) .isWithin(ALLOWED_ERROR) .of(expectedStats.populationVariance()); assertThat(actualStats.min()).isWithin(ALLOWED_ERROR).of(expectedStats.min()); assertThat(actualStats.max()).isWithin(ALLOWED_ERROR).of(expectedStats.max());
twoValuesAccumulator.xStats().mean(), twoValuesAccumulator.yStats().mean(), twoValuesAccumulator.xStats().populationVariance(), twoValuesAccumulator.populationCovariance()); assertDiagonalLinearTransformation( twoValuesAccumulatorByAddAllPartitionedPairedStats.xStats().mean(), twoValuesAccumulatorByAddAllPartitionedPairedStats.yStats().mean(), twoValuesAccumulatorByAddAllPartitionedPairedStats.xStats().populationVariance(), twoValuesAccumulatorByAddAllPartitionedPairedStats.populationCovariance()); assertDiagonalLinearTransformation( manyValuesAccumulator.xStats().mean(), manyValuesAccumulator.yStats().mean(), manyValuesAccumulator.xStats().populationVariance(), manyValuesAccumulator.populationCovariance()); assertDiagonalLinearTransformation( manyValuesAccumulatorByAddAllPartitionedPairedStats.xStats().mean(), manyValuesAccumulatorByAddAllPartitionedPairedStats.yStats().mean(), manyValuesAccumulatorByAddAllPartitionedPairedStats.xStats().populationVariance(), manyValuesAccumulatorByAddAllPartitionedPairedStats.populationCovariance()); accumulator.xStats().mean(), accumulator.yStats().mean(), accumulator.xStats().populationVariance(), accumulator.populationCovariance()); assertDiagonalLinearTransformation(
TWO_VALUES_PAIRED_STATS.xStats().mean(), TWO_VALUES_PAIRED_STATS.yStats().mean(), TWO_VALUES_PAIRED_STATS.xStats().populationVariance(), TWO_VALUES_PAIRED_STATS.populationCovariance()); stats.xStats().mean(), stats.yStats().mean(), stats.xStats().populationVariance(), stats.populationCovariance());
/** * Returns the <a * href="http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values"> * population standard deviation</a> of the values. The count must be non-zero. * * <p>This is guaranteed to return zero if the dataset contains only exactly one finite value. It * is not guaranteed to return zero when the dataset consists of the same value multiple times, * due to numerical errors. However, it is guaranteed never to return a negative result. * * <h3>Non-finite values</h3> * * <p>If the dataset contains any non-finite values ({@link Double#POSITIVE_INFINITY}, {@link * Double#NEGATIVE_INFINITY}, or {@link Double#NaN}) then the result is {@link Double#NaN}. * * @throws IllegalStateException if the dataset is empty */ public double populationStandardDeviation() { return Math.sqrt(populationVariance()); }
/** * Returns the <a * href="http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values"> * population standard deviation</a> of the values. The count must be non-zero. * * <p>This is guaranteed to return zero if the dataset contains only exactly one finite value. It * is not guaranteed to return zero when the dataset consists of the same value multiple times, * due to numerical errors. However, it is guaranteed never to return a negative result. * * <h3>Non-finite values</h3> * * <p>If the dataset contains any non-finite values ({@link Double#POSITIVE_INFINITY}, {@link * Double#NEGATIVE_INFINITY}, or {@link Double#NaN}) then the result is {@link Double#NaN}. * * @throws IllegalStateException if the dataset is empty */ public double populationStandardDeviation() { return Math.sqrt(populationVariance()); }
public void testPopulationVariance() { try { EMPTY_STATS_VARARGS.populationVariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { EMPTY_STATS_ITERABLE.populationVariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { assertThat(ONE_VALUE_STATS.populationVariance()).isWithin(0.0).of(0.0); assertThat(Stats.of(POSITIVE_INFINITY).populationVariance()).isNaN(); assertThat(Stats.of(NEGATIVE_INFINITY).populationVariance()).isNaN(); assertThat(Stats.of(NaN).populationVariance()).isNaN(); assertThat(TWO_VALUES_STATS.populationVariance()) .isWithin(ALLOWED_ERROR) .of(TWO_VALUES_SUM_OF_SQUARES_OF_DELTAS / 2); assertThat(MANY_VALUES_STATS_VARARGS.populationVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT); double populationVariance = Stats.of(values.asIterable()).populationVariance(); if (values.hasAnyNonFinite()) { assertThat(populationVariance).named("population variance of " + values).isNaN(); assertThat(MANY_VALUES_STATS_ITERATOR.populationVariance()) .isWithin(ALLOWED_ERROR) .of(MANY_VALUES_SUM_OF_SQUARES_OF_DELTAS / MANY_VALUES_COUNT); assertThat(MANY_VALUES_STATS_SNAPSHOT.populationVariance()) .isWithin(ALLOWED_ERROR)
actualStats.populationVariance(); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { assertThat(actualStats.populationVariance()).isWithin(0.0).of(0.0); assertThat(actualStats.min()).isWithin(ALLOWED_ERROR).of(expectedStats.min()); assertThat(actualStats.max()).isWithin(ALLOWED_ERROR).of(expectedStats.max()); } else { assertThat(actualStats.mean()).isWithin(ALLOWED_ERROR).of(expectedStats.mean()); assertThat(actualStats.populationVariance()) .isWithin(ALLOWED_ERROR) .of(expectedStats.populationVariance()); assertThat(actualStats.min()).isWithin(ALLOWED_ERROR).of(expectedStats.min()); assertThat(actualStats.max()).isWithin(ALLOWED_ERROR).of(expectedStats.max());
twoValuesAccumulator.xStats().mean(), twoValuesAccumulator.yStats().mean(), twoValuesAccumulator.xStats().populationVariance(), twoValuesAccumulator.populationCovariance()); assertDiagonalLinearTransformation( twoValuesAccumulatorByAddAllPartitionedPairedStats.xStats().mean(), twoValuesAccumulatorByAddAllPartitionedPairedStats.yStats().mean(), twoValuesAccumulatorByAddAllPartitionedPairedStats.xStats().populationVariance(), twoValuesAccumulatorByAddAllPartitionedPairedStats.populationCovariance()); assertDiagonalLinearTransformation( manyValuesAccumulator.xStats().mean(), manyValuesAccumulator.yStats().mean(), manyValuesAccumulator.xStats().populationVariance(), manyValuesAccumulator.populationCovariance()); assertDiagonalLinearTransformation( manyValuesAccumulatorByAddAllPartitionedPairedStats.xStats().mean(), manyValuesAccumulatorByAddAllPartitionedPairedStats.yStats().mean(), manyValuesAccumulatorByAddAllPartitionedPairedStats.xStats().populationVariance(), manyValuesAccumulatorByAddAllPartitionedPairedStats.populationCovariance()); accumulator.xStats().mean(), accumulator.yStats().mean(), accumulator.xStats().populationVariance(), accumulator.populationCovariance()); assertDiagonalLinearTransformation(
TWO_VALUES_PAIRED_STATS.xStats().mean(), TWO_VALUES_PAIRED_STATS.yStats().mean(), TWO_VALUES_PAIRED_STATS.xStats().populationVariance(), TWO_VALUES_PAIRED_STATS.populationCovariance()); stats.xStats().mean(), stats.yStats().mean(), stats.xStats().populationVariance(), stats.populationCovariance());