Example usage for weka.core SparseInstance index

List of usage examples for weka.core SparseInstance index

Introduction

In this page you can find the example usage for weka.core SparseInstance index.

Prototype

@Override
public int index(int position) 

Source Link

Document

Returns the index of the attribute stored at the given position.

Usage

From source file:cluster.ABC.ClusterUtils.java

License:Open Source License

/** Fast version of meanOrMode - streamlined from Instances.meanOrMode for efficiency 
 *  Does not check for missing attributes, assumes numeric attributes, assumes Sparse instances
 *///from  www  . j av a  2  s  .c o m

public static double[] meanOrMode(Instances insts) {

    int numAttributes = insts.numAttributes();
    double[] value = new double[numAttributes];
    double weight = 0;

    for (int i = 0; i < numAttributes; i++) {
        value[i] = 0;
    }

    for (int j = 0; j < insts.numInstances(); j++) {
        SparseInstance inst = (SparseInstance) (insts.instance(j));
        weight += inst.weight();

        for (int i = 0; i < inst.numValues(); i++) {
            int indexOfIndex = inst.index(i);
            value[indexOfIndex] += inst.weight() * inst.valueSparse(i);
        }
    }

    if (Utils.eq(weight, 0)) {
        for (int k = 0; k < numAttributes; k++) {
            value[k] = 0;
        }
    } else {
        for (int k = 0; k < numAttributes; k++) {
            value[k] = value[k] / weight;
        }
    }

    return value;
}

From source file:jkamal.ddbmssim.incmine.core.Segment.java

License:Open Source License

/**
 * Get sparse itemset representation of the current binary intastance
 * @param inst current transaction instance
 * @return an itemset composed by the indices of the non-zero elements in the instance
 *///  ww w.j  a  v a  2 s .c o m
private Itemset toItemset(SparseInstance inst) {
    Itemset itemset = new Itemset();

    for (int val = 0; val < inst.numValues(); val++) {
        itemset.addItem(inst.index(val));
    }
    return itemset;
}