throw new IllegalArgumentException( "given selection strategy must support parallel models, got: " + ensembleSpec.getSelectionStrategy() );
if( ensembleSpec.getModelSpecs().size() < 2 )
throw new IllegalArgumentException( "ensembles must have more than 1 model" );
ModelSchema modelSchema = ensembleSpec.getModelSchema();
Fields predictedFields = modelSchema.getPredictedFields();
Fields keyFields = modelSchema.getKeyFields();
if( keyFields.isNone() )
{
keyFields = new Fields( "ensemble-primary-key", String.class );
pipe = new InsertGUID( pipe, keyFields );
}
boolean isCategorical = ensembleSpec.isPredictedCategorical();
// the parallel bits
List<Pipe> pipes = new ArrayList<Pipe>();
for( int i = 0; i < ensembleSpec.getModelSpecs().size(); i++ )
{
Spec spec = (Spec) ensembleSpec.getModelSpecs().get( i );
if( spec instanceof TreeSpec )
pipes.add( createScoringPipe( i, pipe, modelSchema, new TreeFunction( (TreeSpec) spec, isCategorical, false ) ) );
}
pipe = new GroupBy( "vote", pipes.toArray( new Pipe[ pipes.size() ] ), keyFields );
SelectionBuffer buffer;
if( isCategorical )
buffer = new CategoricalSelectionBuffer( ensembleSpec );
else
buffer = new PredictionSelectionBuffer( ensembleSpec );
pipe = new Every( pipe, predictedFields, buffer, Fields.SWAP );
if( modelSchema.getKeyFields().isNone() )
pipe = new Discard( pipe, keyFields );
setTails( pipe );
}