public void debugVector ( ConcatVector vector , BufferedWriter bw ) throws IOException { List < String > features = new ArrayList <> ( ) ; Map < String , List < Integer > > sortedFeatures = new HashMap <> ( ) ; for ( ObjectCursor < String > key : featureToIndex . keys ( ) ) { features . add ( key . value ) ; int i = featureToIndex . getOrDefault ( key . value , - 1 ) ; List < Integer > featureIndices = new ArrayList <> ( ) ; if ( vector . isComponentSparse ( i ) ) { int [ ] indices = vector . getSparseIndices ( i ) ; for ( int j : indices ) { featureIndices . add ( j ) ; } } else { double [ ] arr = vector . getDenseComponent ( i ) ; for ( int j = 0 ; j < arr . length ; j ++ ) { featureIndices . add ( j ) ; } } featureIndices . sort ( ( a , b ) -> { if ( Math . abs ( vector . getValueAt ( i , a ) ) < Math . abs ( vector . getValueAt ( i , b ) ) ) { return 1 ; } else if ( Math . abs ( vector . getValueAt ( i , a ) ) > Math . abs ( vector . getValueAt ( i , b ) ) ) { return - 1 ; } else { return 0 ; } } ) ; sortedFeatures . put ( key . value , featureIndices ) ; } features . sort ( ( a , b ) -> { double bestAValue = sortedFeatures . get ( a ) . size ( ) == 0 ? 0.0 : Math . abs ( vector . getValueAt ( featureToIndex . getOrDefault ( a , - 1 ) , sortedFeatures . get ( a ) . get ( 0 ) ) ) ; double bestBValue = sortedFeatures . get ( b ) . size ( ) == 0 ? 0.0 : Math . abs ( vector . getValueAt ( featureToIndex . getOrDefault ( b , - 1 ) , sortedFeatures . get ( b ) . get ( 0 ) ) ) ; if ( bestAValue < bestBValue ) { return 1 ; } else if ( bestAValue > bestBValue ) { return - 1 ; } else return 0 ; } ) ; for ( String key : features ) { bw . write ( "FEATURE: \"" + key ) ; bw . write ( "\"\n" ) ; for ( int j : sortedFeatures . get ( key ) ) { debugFeatureValue ( key , j , vector , bw ) ; } } // Flush the writer bw . flush ( ) ; }
This prints out a ConcatVector by mapping to the namespace to make debugging learning algorithms easier .