Skip to content

Commit

Permalink
Merge pull request #349 from NOAA-OWP/issue342
Browse files Browse the repository at this point in the history
Fix a bug in determining the minimum sample size for sampling uncerta…
  • Loading branch information
james-d-brown authored Oct 28, 2024
2 parents 769e5c5 + b5bc780 commit fbe4fb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class BootstrapUtilities
* @param <R> 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 <R> Pair<Long, Duration> getOptimalBlockSizeForStationaryBootstrap( Pool<TimeSeries<Pair<Double, R>>> pool )
{
Expand Down Expand Up @@ -110,7 +111,7 @@ public static <R> Pair<Long, Duration> 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 <T> the type of time-series data
* @param data the time-series data
* @return whether there is sufficient data for the stationary bootstrap
Expand All @@ -120,10 +121,13 @@ public static <T> boolean hasSufficientDataForStationaryBootstrap( List<TimeSeri
{
Objects.requireNonNull( data );

// Consolidate the time-series by event datetime and count the number of events
long eventCount = data.stream()
.mapToLong( t -> t.getEvents()
.size() )
.sum();
.flatMap( t -> t.getEvents()
.stream()
.map( Event::getTime ) )
.distinct()
.count();

if ( LOGGER.isDebugEnabled() )
{
Expand Down Expand Up @@ -413,6 +417,7 @@ private static void addQuantileForBoxplot( List<BoxplotStatistic> quantile,
* @param <T> 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 <T> Pair<Long, Duration> getOptimalBlockSizeForStationaryBootstrap( List<TimeSeries<Pair<Double, T>>> pool )
{
Expand Down
12 changes: 6 additions & 6 deletions wres-datamodel/test/wres/datamodel/time/TimeSeriesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* Tests the {@link TimeSeries}
*
*
* @author James Brown
*/

Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -146,7 +146,7 @@ public void testHashCode()
@Test
public void testEquals()
{
// Reflexive
// Reflexive
assertEquals( this.testSeries, this.testSeries );

// Symmetric
Expand Down

0 comments on commit fbe4fb1

Please sign in to comment.