/** * The number of set members. Calculated on first call and * cached for subsequent calls. * @return The number of set members */ public int size() { if (size == -1) { size = Utils.sum(labelSet); } return size; }
/** * Gets the squared error for all clusters * * @return the squared error */ public double getSquaredError() { return Utils.sum(m_squaredErrors); }
/** * Gets the squared error for all clusters. * * @return the squared error, NaN if fast distance calculation is used * @see #m_FastDistanceCalc */ public double getSquaredError() { if (m_FastDistanceCalc) { return Double.NaN; } else { return Utils.sum(m_squaredErrors); } }
/** * Gets the squared error for all clusters. * * @return the squared error, NaN if fast distance calculation is used * @see #m_FastDistanceCalc */ public double getSquaredError() { if (m_FastDistanceCalc) { return Double.NaN; } else { return Utils.sum(m_squaredErrors); } }
/** * EmptyVectors - percentage of empty vectors sum(y[i])==0 in Y. */ public static final double emptyVectors(int Y[][]) { int N = Y.length; int L = Y[0].length; double sum = 0.0; for(int i = 0; i < N; i++) { if (Utils.sum(Y[i]) <= 0.0) sum ++; } return (double)sum/(double)N; }
/** * EmptyVectors - percentage of empty vectors sum(y[i])==0 in Y. */ public static final double emptyVectors(int Y[][]) { int N = Y.length; int L = Y[0].length; double sum = 0.0; for(int i = 0; i < N; i++) { if (Utils.sum(Y[i]) <= 0.0) sum ++; } return (double)sum/(double)N; }
/** * Adds counts to given bag. */ public final void add(int bagIndex, double[] counts) { double sum = Utils.sum(counts); for (int i = 0; i < counts.length; i++) { m_perClassPerBag[bagIndex][i] += counts[i]; } m_perBag[bagIndex] = m_perBag[bagIndex] + sum; for (int i = 0; i < counts.length; i++) { m_perClass[i] = m_perClass[i] + counts[i]; } totaL = totaL + sum; }
/** * Adds counts to given bag. */ public final void add(int bagIndex, double[] counts) { double sum = Utils.sum(counts); for (int i = 0; i < counts.length; i++) { m_perClassPerBag[bagIndex][i] += counts[i]; } m_perBag[bagIndex] = m_perBag[bagIndex] + sum; for (int i = 0; i < counts.length; i++) { m_perClass[i] = m_perClass[i] + counts[i]; } totaL = totaL + sum; }
double eval(double[] args) { return Utils.sum(args); }
double eval(double[] args) { return Utils.sum(args); }
/** * Normalizes branch sizes so they contain frequencies (stored in "props") * instead of counts (stored in "dist"). Creates a new double[] which it * returns. */ protected static double[] countsToFreqs( double[][] dist ) { double[] props = new double[dist.length]; for (int k = 0; k < props.length; k++) { props[k] = Utils.sum(dist[k]); } if (Utils.eq(Utils.sum(props), 0)) { for (int k = 0; k < props.length; k++) { props[k] = 1.0 / (double) props.length; } } else { FastRfUtils.normalize(props); } return props; }
/** * Normalizes branch sizes so they contain frequencies (stored in "props") * instead of counts (stored in "dist"). <p> * * Overwrites the supplied "props"! <p> * * props.length must be == dist.length. */ protected static void countsToFreqs( double[][] dist, double[] props ) { for (int k = 0; k < props.length; k++) { props[k] = Utils.sum(dist[k]); } if (Utils.eq(Utils.sum(props), 0)) { for (int k = 0; k < props.length; k++) { props[k] = 1.0 / (double) props.length; } } else { FastRfUtils.normalize(props); } }
/** * Normalizes branch sizes so they contain frequencies (stored in "props") * instead of counts (stored in "dist"). Creates a new double[] which it * returns. */ protected static double[] countsToFreqs( double[][] dist ) { double[] props = new double[dist.length]; for (int k = 0; k < props.length; k++) { props[k] = Utils.sum(dist[k]); } if (Utils.eq(Utils.sum(props), 0)) { for (int k = 0; k < props.length; k++) { props[k] = 1.0 / (double) props.length; } } else { FastRfUtils.normalize(props); } return props; }
/** * Normalizes branch sizes so they contain frequencies (stored in "props") * instead of counts (stored in "dist"). <p> * * Overwrites the supplied "props"! <p> * * props.length must be == dist.length. */ protected static void countsToFreqs( double[][] dist, double[] props ) { for (int k = 0; k < props.length; k++) { props[k] = Utils.sum(dist[k]); } if (Utils.eq(Utils.sum(props), 0)) { for (int k = 0; k < props.length; k++) { props[k] = 1.0 / (double) props.length; } } else { FastRfUtils.normalize(props); } }
/** * Classifies a given instance. Either this or distributionForInstance() needs * to be implemented by subclasses. * * @param instance the instance to be assigned to a cluster * @return the number of the assigned cluster as an integer * @exception Exception if instance could not be clustered successfully */ @Override public int clusterInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } if (Utils.sum(dist) <= 0) { throw new Exception("Unable to cluster instance"); } return Utils.maxIndex(dist); }
/** * Classifies a given instance. Either this or distributionForInstance() needs * to be implemented by subclasses. * * @param instance the instance to be assigned to a cluster * @return the number of the assigned cluster as an integer * @exception Exception if instance could not be clustered successfully */ @Override public int clusterInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } if (Utils.sum(dist) <= 0) { throw new Exception("Unable to cluster instance"); } return Utils.maxIndex(dist); }