Buggy code:
public class GapStatistic implements Clustering { private static final Logger LOGGER = Logger . getLogger ( GapStatistic . class . getName ( ) ) ; public static final String PROPERTY_PREFIX = "edu.ucla.sspace.clustering.GapStatistic" ; public static final String NUM_CLUSTERS_START = ( GapStatistic . PROPERTY_PREFIX ) + ".numClusterStart" ; public static final String NUM_REFERENCE_DATA_SETS = ( GapStatistic . PROPERTY_PREFIX ) + ".numReferenceDataSets" ; public static final String METHOD_PROPERTY = ( GapStatistic . PROPERTY_PREFIX ) + ".method" ; private static final String DEFAULT_NUM_CLUSTERS_START = "1" ; private static final String DEFAULT_NUM_CLUSTERS_END = "10" ; private static final String DEFAULT_NUM_REFERENCE_DATA_SETS = "5" ; private static final String DEFAULT_METHOD = "edu.ucla.sspace.clustering.criterion.H2Function" ; private static final Random random = new Random ( ) ; public Assignments cluster ( Matrix matrix , Properties props ) { } public Assignments cluster ( Matrix m , int maxClusters , Properties props ) { } private void clusterIteration ( int i , int startSize , String methodName , Matrix matrix , Matrix [ ] gapMatrices , double [ ] gapResults , double [ ] gapStds , Assignments [ ] gapAssignments ) { int k = i + startSize ; double numGaps = gapMatrices . length ; CriterionFunction function = ReflectionUtil . getObjectInstance ( methodName ) ; verbose ( "Clustering<seq2seq4repair_space>reference<seq2seq4repair_space>data<seq2seq4repair_space>for<seq2seq4repair_space>%d<seq2seq4repair_space>clusters\n" , k ) ; double referenceScore = 0 ; double [ ] referenceScores = new double [ gapMatrices . length ] ; for ( int j = 0 ; j < ( gapMatrices . length ) ; ++ j ) { verbose ( "Clustering<seq2seq4repair_space>reference<seq2seq4repair_space>data<seq2seq4repair_space>%d<seq2seq4repair_space>\n" , j ) ; Assignments result = DirectClustering . cluster ( gapMatrices [ j ] , k , 1 , function ) ; referenceScores [ j ] = Math . log ( function . score ( ) ) ; referenceScore += referenceScores [ j ] ; } referenceScore //= numGaps ; double referenceStdev = 0 ; for ( double score : referenceScores ) referenceStdev += Math . pow ( ( score - referenceScore ) , 2 ) ; referenceStdev //= numGaps ; referenceStdev = ( Math . sqrt ( referenceStdev ) ) * ( Math . sqrt ( ( 1 + ( 1 // numGaps ) ) ) ) ; verbose ( "Clustering<seq2seq4repair_space>original<seq2seq4repair_space>data<seq2seq4repair_space>for<seq2seq4repair_space>%d<seq2seq4repair_space>clusters\n" , k ) ; Assignments result = DirectClustering . cluster ( matrix , k , 1 , function ) ; double gap = Math . log ( function . score ( ) ) ; verbose ( "Completed<seq2seq4repair_space>iteration<seq2seq4repair_space>with<seq2seq4repair_space>referenceScore:<seq2seq4repair_space>%f,<seq2seq4repair_space>gap:%f\n" , referenceScore , gap ) ; gap = referenceScore - gap ; <START_BUG> System . out . printf ( "k:<seq2seq4repair_space>%d<seq2seq4repair_space>gap:<seq2seq4repair_space>%f<seq2seq4repair_space>std:<seq2seq4repair_space>%f\n" , i , gap , referenceStdev ) ; <END_BUG> gapResults [ i ] = gap ; gapStds [ i ] = referenceStdev ; gapAssignments [ i ] = result ; } private class ReferenceDataGenerator { private final double [ ] minValues ; private final double [ ] maxValues ; private final double averageNumValuesPerRow ; private final double stdevNumValuesPerRow ; private final int rows ; private Set < Integer > nonZeroFeatures ; public ReferenceDataGenerator ( Matrix m ) { } public Matrix generateTestData ( ) { } private int getNonZeroColumn ( ) { } } protected void verbose ( String msg ) { } protected void verbose ( String format , Object ... args ) { } }

Fix:
System . err . printf ( "k:<seq2seq4repair_space>%d<seq2seq4repair_space>gap:<seq2seq4repair_space>%f<seq2seq4repair_space>std:<seq2seq4repair_space>%f\n" , i , gap , referenceStdev ) ;