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

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

Introduction

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

Prototype

@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception 

Source Link

Document

Sets the format of the input instances.

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/*  www.  ja  v  a  2s.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;
}