public static List < List < DataPoint > > createClusterListFromAssignmentArray ( int [ ] assignments , DataSet dataSet ) { List < List < DataPoint >> clusterings = new ArrayList <> ( ) ; for ( int i = 0 ; i < dataSet . size ( ) ; i ++ ) { while ( clusterings . size ( ) <= assignments [ i ] ) clusterings . add ( new ArrayList <> ( ) ) ; if ( assignments [ i ] >= 0 ) clusterings . get ( assignments [ i ] ) . add ( dataSet . getDataPoint ( i ) ) ; } return clusterings ; }
Convenient helper method . A list of lists to represent a cluster may be desirable . In such a case this method will take in an array of cluster assignments and return a list of lists .