Example usage for weka.filters.unsupervised.attribute MultiInstanceWrapper MultiInstanceWrapper

List of usage examples for weka.filters.unsupervised.attribute MultiInstanceWrapper MultiInstanceWrapper

Introduction

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

Prototype

MultiInstanceWrapper

Source Link

Usage

From source file:net.sf.jclal.util.dataset.DatasetUtils.java

License:Open Source License

/**
 *
 * Wrapper method, it modifies the Multi-Instance data by assigning the bag
 * label to each instance of the corresponding bag and then builds a
 * classifier based on the modified data (DONG, Lin, 2006, A
 * Comparison of Multi-instance Learning Algorithms, University of Waikato)
 *
 * @param source An array of instances/*from  www.j  a v a 2 s .c  o m*/
 * @return The dataset
 * @throws Exception The exception to launch
 */
public static Instances multiInstanceWrapperFormat(Instances source[]) throws Exception {

    int size = 0;
    for (Instances instances : source) {
        size += instances.numInstances();
    }

    Instances all = new Instances(source[0], size);
    for (Instances curr : source) {
        all.addAll(curr);
    }

    MultiInstanceWrapper wrapper = new MultiInstanceWrapper();
    wrapper.setInputFormat(all);
    Instances process = MultiInstanceWrapper.useFilter(all, wrapper);

    //clean
    all.delete();
    all = null;
    wrapper = null;

    return process;
}