Example usage for weka.filters.unsupervised.attribute MultiInstanceToPropositional setInputFormat

List of usage examples for weka.filters.unsupervised.attribute MultiInstanceToPropositional setInputFormat

Introduction

In this page you can find the example usage for weka.filters.unsupervised.attribute MultiInstanceToPropositional setInputFormat.

Prototype

@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception 

Source Link

Document

Sets the format of the input instances.

Usage

From source file:org.knime.knip.suise.node.boundarymodel.contourdata.IRI.java

License:Open Source License

private Instances toSingleInstanceDataset(Instances miData, Instances flatData) throws Exception {
    MultiInstanceToPropositional convertToProp = new MultiInstanceToPropositional();

    convertToProp.setInputFormat(miData);

    for (int i = 0; i < miData.numInstances(); i++) {
        convertToProp.input(miData.instance(i));
    }/*from  w  ww .ja v a 2  s  .co m*/
    convertToProp.batchFinished();

    if (flatData == null) {
        flatData = convertToProp.getOutputFormat();
        flatData.deleteAttributeAt(0); // remove the bag index attribute

    }

    Instance processed;
    while ((processed = convertToProp.output()) != null) {
        processed.setDataset(null);
        processed.deleteAttributeAt(0); // remove the bag index attribute
        flatData.add(processed);
    }

    // remove class attribute
    // flatData.setClassIndex(-1);
    // flatData.deleteAttributeAt(flatData.numAttributes() - 1);

    // set weights
    int instanceIdx = 0;
    for (Instance bag : miData) {
        for (Instance instance : bag.relationalValue(1)) {
            flatData.get(instanceIdx).setWeight(instance.weight());
            instanceIdx++;
        }
    }
    return flatData;
}