public MultipleObjectsBundle generate ( ) { // we actually need some clusters. if ( generators . isEmpty ( ) ) { throw new AbortException ( "No clusters specified." ) ; } // Assert that cluster dimensions agree. final int dim = generators . get ( 0 ) . getDim ( ) ; for ( GeneratorInterface c : generators ) { if ( c . getDim ( ) != dim ) { throw new AbortException ( "Cluster dimensions do not agree." ) ; } } // Prepare result bundle MultipleObjectsBundle bundle = new MultipleObjectsBundle ( ) ; VectorFieldTypeInformation < DoubleVector > type = new VectorFieldTypeInformation <> ( DoubleVector . FACTORY , dim ) ; bundle . appendColumn ( type , new ArrayList <> ( ) ) ; bundle . appendColumn ( TypeUtil . CLASSLABEL , new ArrayList <> ( ) ) ; bundle . appendColumn ( Model . TYPE , new ArrayList < Model > ( ) ) ; // generate clusters ClassLabel [ ] labels = new ClassLabel [ generators . size ( ) ] ; Model [ ] models = new Model [ generators . size ( ) ] ; initLabelsAndModels ( generators , labels , models , relabelClusters ) ; final AssignPoint assignment ; if ( ! testAgainstModel ) { assignment = new AssignPoint ( ) ; } else if ( relabelClusters == null ) { assignment = new TestModel ( ) ; } else if ( ! relabelDistance ) { assignment = new AssignLabelsByDensity ( labels ) ; } else { assignment = new AssignLabelsByDistance ( labels ) ; } for ( int i = 0 ; i < labels . length ; i ++ ) { final GeneratorInterface curclus = generators . get ( i ) ; assignment . newCluster ( i , curclus ) ; // Only dynamic generators allow rejection / model testing: GeneratorInterfaceDynamic cursclus = ( curclus instanceof GeneratorInterfaceDynamic ) ? ( GeneratorInterfaceDynamic ) curclus : null ; int kept = 0 ; while ( kept < curclus . getSize ( ) ) { // generate the "missing" number of points List < double [ ] > newp = curclus . generate ( curclus . getSize ( ) - kept ) ; for ( double [ ] p : newp ) { int bestc = assignment . getAssignment ( i , p ) ; if ( bestc < 0 ) { cursclus . incrementDiscarded ( ) ; continue ; } bundle . appendSimple ( DoubleVector . wrap ( p ) , labels [ bestc ] , models [ bestc ] ) ; ++ kept ; } } } return bundle ; }
Main loop to generate data set .