From b5bc780b66647f1ce2834d825b61fb2bd36294cd Mon Sep 17 00:00:00 2001 From: James Brown <64858662+james-d-brown@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:52:29 +0000 Subject: [PATCH] Fix a bug in determining the minimum sample size for sampling uncertainty assessment, #342. --- .../datamodel/bootstrap/BootstrapUtilities.java | 13 +++++++++---- .../test/wres/datamodel/time/TimeSeriesTest.java | 12 ++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapUtilities.java b/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapUtilities.java index 13c06538a3..55b218bb1d 100644 --- a/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapUtilities.java +++ b/wres-datamodel/src/wres/datamodel/bootstrap/BootstrapUtilities.java @@ -47,6 +47,7 @@ public class BootstrapUtilities * @param the type of right-ish time-series data * @param pool the pool * @return the optimal block size for the stationary bootstrap in timestep units, together with the timestep + * @throws InsufficientDataForResamplingException if there is insufficient data to calculate the optimal block size */ public static Pair getOptimalBlockSizeForStationaryBootstrap( Pool>> pool ) { @@ -110,7 +111,7 @@ public static Pair getOptimalBlockSizeForStationaryBootstrap /** * Determines whether sufficient data is available for bootstrap resampling. There must be more than one event - * across time time-series present. + * across the consolidated time-series present. * @param the type of time-series data * @param data the time-series data * @return whether there is sufficient data for the stationary bootstrap @@ -120,10 +121,13 @@ public static boolean hasSufficientDataForStationaryBootstrap( List t.getEvents() - .size() ) - .sum(); + .flatMap( t -> t.getEvents() + .stream() + .map( Event::getTime ) ) + .distinct() + .count(); if ( LOGGER.isDebugEnabled() ) { @@ -413,6 +417,7 @@ private static void addQuantileForBoxplot( List quantile, * @param the type of time-series data * @param pool the pool * @return the optimal block size for the stationary bootstrap + * @throws InsufficientDataForResamplingException if there are fewer than two events across the consolidated series */ private static Pair getOptimalBlockSizeForStationaryBootstrap( List>> pool ) { diff --git a/wres-datamodel/test/wres/datamodel/time/TimeSeriesTest.java b/wres-datamodel/test/wres/datamodel/time/TimeSeriesTest.java index 716a40ad76..4219e268df 100644 --- a/wres-datamodel/test/wres/datamodel/time/TimeSeriesTest.java +++ b/wres-datamodel/test/wres/datamodel/time/TimeSeriesTest.java @@ -26,7 +26,7 @@ /** * Tests the {@link TimeSeries} - * + * * @author James Brown */ @@ -79,10 +79,10 @@ public void runBeforeEachTest() FEATURE_NAME, UNIT ); this.testSeries = builder.setMetadata( metadata ) - .addEvent( iterator.next() ) - .addEvent( iterator.next() ) - .addEvent( iterator.next() ) - .build(); + .addEvent( iterator.next() ) + .addEvent( iterator.next() ) + .addEvent( iterator.next() ) + .build(); } /** @@ -146,7 +146,7 @@ public void testHashCode() @Test public void testEquals() { - // Reflexive + // Reflexive assertEquals( this.testSeries, this.testSeries ); // Symmetric