@ Override public DataSet sample ( int numSamples , org . nd4j . linalg . api . rng . Random rng , boolean withReplacement ) { Set < Integer > added = new HashSet <> ( ) ; List < DataSet > toMerge = new ArrayList <> ( ) ; boolean terminate = false ; for ( int i = 0 ; i < numSamples && ! terminate ; i ++ ) { int picked = rng . nextInt ( numExamples ( ) ) ; if ( ! withReplacement ) { while ( added . contains ( picked ) ) { picked = rng . nextInt ( numExamples ( ) ) ; if ( added . size ( ) == numExamples ( ) ) { terminate = true ; break ; } } } added . add ( picked ) ; toMerge . add ( get ( picked ) ) ; } return DataSet . merge ( toMerge ) ; }
Sample a dataset