@ Override public void filterAndStrip ( int [ ] labels ) { DataSet filtered = filterBy ( labels ) ; List < Integer > newLabels = new ArrayList <> ( ) ; //map new labels to index according to passed in labels Map < Integer , Integer > labelMap = new HashMap <> ( ) ; for ( int i = 0 ; i < labels . length ; i ++ ) labelMap . put ( labels [ i ] , i ) ; //map examples for ( int i = 0 ; i < filtered . numExamples ( ) ; i ++ ) { DataSet example = filtered . get ( i ) ; int o2 = example . outcome ( ) ; Integer outcome = labelMap . get ( o2 ) ; newLabels . add ( outcome ) ; } INDArray newLabelMatrix = Nd4j . create ( filtered . numExamples ( ) , labels . length ) ; if ( newLabelMatrix . rows ( ) != newLabels . size ( ) ) throw new IllegalStateException ( "Inconsistent label sizes" ) ; for ( int i = 0 ; i < newLabelMatrix . rows ( ) ; i ++ ) { Integer i2 = newLabels . get ( i ) ; if ( i2 == null ) throw new IllegalStateException ( "Label not found on row " + i ) ; INDArray newRow = FeatureUtil . toOutcomeVector ( i2 , labels . length ) ; newLabelMatrix . putRow ( i , newRow ) ; } setFeatures ( filtered . getFeatures ( ) ) ; setLabels ( newLabelMatrix ) ; }
Strips the dataset down to the specified labels and remaps them