List of usage examples for weka.core ContingencyTables symmetricalUncertainty
public static double symmetricalUncertainty(double matrix[][])
From source file:moa.reduction.bayes.IncrInfoThAttributeEval.java
License:Open Source License
@Override /**/* w ww . j a v a 2 s . c om*/ * Update the contingency tables and the rankings for each features using the counters. * Counters are updated in each iteration. */ public void applySelection() { if (counts != null && updated) { m_InfoValues = new double[counts.length]; for (int i = 0; i < counts.length; i++) { if (i != classIndex) { Set<Key> keys = counts[i].keySet(); Set<Entry<Key, Float>> entries = counts[i].entrySet(); Set<Float> avalues = new HashSet<Float>(); Set<Float> cvalues = new HashSet<Float>(); for (Iterator<Key> it = keys.iterator(); it.hasNext();) { Key key = it.next(); avalues.add(key.x); cvalues.add(key.y); } Map<Float, Integer> apos = new HashMap<Float, Integer>(); Map<Float, Integer> cpos = new HashMap<Float, Integer>(); int aidx = 0; for (Iterator<Float> it = avalues.iterator(); it.hasNext();) { Float f = it.next(); apos.put(f, aidx++); } int cidx = 0; for (Iterator<Float> it = cvalues.iterator(); it.hasNext();) { Float f = it.next(); cpos.put(f, cidx++); } double[][] lcounts = new double[avalues.size()][cvalues.size()]; for (Iterator<Entry<Key, Float>> it = entries.iterator(); it.hasNext();) { Entry<Key, Float> entry = it.next(); lcounts[apos.get(entry.getKey().x)][cpos.get(entry.getKey().y)] = entry.getValue(); } switch (method) { case 1: m_InfoValues[i] = ContingencyTables.symmetricalUncertainty(lcounts); break; default: m_InfoValues[i] = (ContingencyTables.entropyOverColumns(lcounts) - ContingencyTables.entropyConditionedOnRows(lcounts)); break; } } } //System.out.println("Attribute values: " + Arrays.toString(m_InfoValues)); updated = false; } }