/** * Returns number of classes actually occuring in given bag. */ public final int actualNumClasses(int bagIndex) { int returnValue = 0; int i; for (i = 0; i < m_perClass.length; i++) { if (Utils.gr(m_perClassPerBag[bagIndex][i], 0)) { returnValue++; } } return returnValue; }
/** * Returns number of classes actually occuring in distribution. */ public final int actualNumClasses() { int returnValue = 0; int i; for (i = 0; i < m_perClass.length; i++) { if (Utils.gr(m_perClass[i], 0)) { returnValue++; } } return returnValue; }
/** * Returns number of non-empty bags of distribution. */ public final int actualNumBags() { int returnValue = 0; int i; for (i = 0; i < m_perBag.length; i++) { if (Utils.gr(m_perBag[i], 0)) { returnValue++; } } return returnValue; }
/** * Returns number of non-empty bags of distribution. */ public final int actualNumBags() { int returnValue = 0; int i; for (i = 0; i < m_perBag.length; i++) { if (Utils.gr(m_perBag[i], 0)) { returnValue++; } } return returnValue; }
/** * Returns number of classes actually occuring in distribution. */ public final int actualNumClasses() { int returnValue = 0; int i; for (i = 0; i < m_perClass.length; i++) { if (Utils.gr(m_perClass[i], 0)) { returnValue++; } } return returnValue; }
/** * Returns number of classes actually occuring in given bag. */ public final int actualNumClasses(int bagIndex) { int returnValue = 0; int i; for (i = 0; i < m_perClass.length; i++) { if (Utils.gr(m_perClassPerBag[bagIndex][i], 0)) { returnValue++; } } return returnValue; }
/** * Returns class with highest frequency over all bags. */ public final int maxClass() { double maxCount = 0; int maxIndex = 0; int i; for (i = 0; i < m_perClass.length; i++) { if (Utils.gr(m_perClass[i], maxCount)) { maxCount = m_perClass[i]; maxIndex = i; } } return maxIndex; }
/** * Returns class with highest frequency over all bags. */ public final int maxClass() { double maxCount = 0; int maxIndex = 0; int i; for (i = 0; i < m_perClass.length; i++) { if (Utils.gr(m_perClass[i], maxCount)) { maxCount = m_perClass[i]; maxIndex = i; } } return maxIndex; }
/** * Returns relative frequency of class for given bag. */ public final double prob(int classIndex, int intIndex) { if (Utils.gr(m_perBag[intIndex], 0)) { return m_perClassPerBag[intIndex][classIndex] / m_perBag[intIndex]; } else { return prob(classIndex); } }
/** * Returns relative frequency of class for given bag. */ public final double laplaceProb(int classIndex, int intIndex) { if (Utils.gr(m_perBag[intIndex], 0)) { return (m_perClassPerBag[intIndex][classIndex] + 1.0) / (m_perBag[intIndex] + m_perClass.length); } else { return laplaceProb(classIndex); } }
/** * Returns relative frequency of class for given bag. */ public final double prob(int classIndex, int intIndex) { if (Utils.gr(m_perBag[intIndex], 0)) { return m_perClassPerBag[intIndex][classIndex] / m_perBag[intIndex]; } else { return prob(classIndex); } }
/** * Returns relative frequency of class for given bag. */ public final double laplaceProb(int classIndex, int intIndex) { if (Utils.gr(m_perBag[intIndex], 0)) { return (m_perClassPerBag[intIndex][classIndex] + 1.0) / (m_perBag[intIndex] + m_perClass.length); } else { return laplaceProb(classIndex); } }
/** * Returns the log-odds for a given probabilitiy. * * @param prob the probabilitiy * * @return the log-odds after the probability has been mapped to [Utils.SMALL, * 1-Utils.SMALL] */ public static/* @pure@ */double probToLogOdds(double prob) { if (gr(prob, 1) || (sm(prob, 0))) { throw new IllegalArgumentException("probToLogOdds: probability must " + "be in [0,1] " + prob); } double p = SMALL + (1.0 - 2 * SMALL) * prob; return Math.log(p / (1 - p)); }
/** * Returns the log-odds for a given probabilitiy. * * @param prob the probabilitiy * * @return the log-odds after the probability has been mapped to [Utils.SMALL, * 1-Utils.SMALL] */ public static/* @pure@ */double probToLogOdds(double prob) { if (gr(prob, 1) || (sm(prob, 0))) { throw new IllegalArgumentException("probToLogOdds: probability must " + "be in [0,1] " + prob); } double p = SMALL + (1.0 - 2 * SMALL) * prob; return Math.log(p / (1 - p)); }
/** * Subset description length: <br> * S(t,k,p) = -k*log2(p)-(n-k)log2(1-p) * * Details see Quilan: "MDL and categorical theories (Continued)",ML95 * * @param t the number of elements in a known set * @param k the number of elements in a subset * @param p the expected proportion of subset known by recipient * @return the subset description length */ public static double subsetDL(double t, double k, double p) { double rt = Utils.gr(p, 0.0) ? (-k * Utils.log2(p)) : 0.0; rt -= (t - k) * Utils.log2(1 - p); return rt; }
/** * Subset description length: <br> * S(t,k,p) = -k*log2(p)-(n-k)log2(1-p) * * Details see Quilan: "MDL and categorical theories (Continued)",ML95 * * @param t the number of elements in a known set * @param k the number of elements in a subset * @param p the expected proportion of subset known by recipient * @return the subset description length */ public static double subsetDL(double t, double k, double p) { double rt = Utils.gr(p, 0.0) ? (-k * Utils.log2(p)) : 0.0; rt -= (t - k) * Utils.log2(1 - p); return rt; }
/** * Prints label for subset index of instances (eg class). * * @exception Exception if something goes wrong */ public final String dumpLabel(int index,Instances data) throws Exception { StringBuffer text; text = new StringBuffer(); text.append(((Instances)data).classAttribute(). value(m_distribution.maxClass(index))); text.append(" ("+Utils.roundDouble(m_distribution.perBag(index),2)); if (Utils.gr(m_distribution.numIncorrect(index),0)) text.append("/"+Utils.roundDouble(m_distribution.numIncorrect(index),2)); text.append(")"); return text.toString(); }
/** * Prints label for subset index of instances (eg class). * * @exception Exception if something goes wrong */ public final String dumpLabel(int index,Instances data) throws Exception { StringBuffer text; text = new StringBuffer(); text.append(((Instances)data).classAttribute(). value(m_distribution.maxClass(index))); text.append(" ("+Utils.roundDouble(m_distribution.perBag(index),2)); if (Utils.gr(m_distribution.numIncorrect(index),0)) text.append("/"+Utils.roundDouble(m_distribution.numIncorrect(index),2)); text.append(")"); return text.toString(); }
/** * Help method for computing the split entropy. */ private final double splitEnt(Distribution bags, double totalnoInst) { double returnValue = 0; double noUnknown; int i; noUnknown = totalnoInst - bags.total(); if (Utils.gr(bags.total(), 0)) { for (i = 0; i < bags.numBags(); i++) { returnValue = returnValue - lnFunc(bags.perBag(i)); } returnValue = returnValue - lnFunc(noUnknown); returnValue = returnValue + lnFunc(totalnoInst); } return returnValue / ContingencyTables.log2; }
/** * Help method for computing the split entropy. */ private final double splitEnt(Distribution bags, double totalnoInst) { double returnValue = 0; double noUnknown; int i; noUnknown = totalnoInst - bags.total(); if (Utils.gr(bags.total(), 0)) { for (i = 0; i < bags.numBags(); i++) { returnValue = returnValue - lnFunc(bags.perBag(i)); } returnValue = returnValue - lnFunc(noUnknown); returnValue = returnValue + lnFunc(totalnoInst); } return returnValue / ContingencyTables.log2; }