List of usage examples for weka.core SparseInstance weight
@Override
public finaldouble weight()
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 ww w. ja v a2 s . co 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; }