List of usage examples for weka.core SparseInstance numValues
@Override public int numValues()
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 w ww. ja v a2 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 *//* w ww .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; }