@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selrow); final double rowMean = rowM[row]; double v = val - rowMean - bias; colResidue.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selrow && selcol); double v = val - rowM[row] - colM[col] + allM; msr.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selcol); final double rowMean = rowM[row]; final double colMean = colM[col]; double v = ((!rowinverted) ? (val - rowMean) : (rowMean - val)) - colMean + allM; rowResidue.put(v * v); return false; } });
/** * Add values with weight 1.0 * * @param vals Values * @return this */ public Mean put(double[] vals) { for(double v : vals) { put(v); } return this; }
/** * Add values with weight 1.0 * * @param vals Values * @return this */ public Mean put(double[] vals) { for(double v : vals) { put(v); } return this; }
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selrow && selcol); double v = val - rowM[row] - colM[col] + allM; msr.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selrow); final double rowMean = rowM[row]; double v = val - rowMean - bias; colResidue.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selrow && selcol); double v = val - rowM[row] - colM[col] + allM; msr.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selcol); final double rowMean = rowM[row]; final double colMean = colM[col]; double v = ((!rowinverted) ? (val - rowMean) : (rowMean - val)) - colMean + allM; rowResidue.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selrow); final double rowMean = rowM[row]; double v = val - rowMean - bias; colResidue.put(v * v); return false; } });
@Override public boolean visit(double val, int row, int col, boolean selrow, boolean selcol) { assert (selcol); final double rowMean = rowM[row]; final double colMean = colM[col]; double v = ((!rowinverted) ? (val - rowMean) : (rowMean - val)) - colMean + allM; rowResidue.put(v * v); return false; } });
/** * Add values with weight 1.0 * * @param vals Values * @return this */ public Mean put(double[] vals) { for(double v : vals) { put(v); } return this; }
/** * Add values with weight 1.0 * * @param vals Values * @return this */ public Mean put(double[] vals, double[] weights) { assert (vals.length == weights.length); for(int i = 0, end = vals.length; i < end; i++) { put(vals[i], weights[i]); } return this; }
/** * Add values with weight 1.0 * * @param vals Values * @return this */ public Mean put(double[] vals, double[] weights) { assert (vals.length == weights.length); for(int i = 0, end = vals.length; i < end; i++) { put(vals[i], weights[i]); } return this; }
/** * Add values with weight 1.0 * * @param vals Values * @return this */ public Mean put(double[] vals, double[] weights) { assert (vals.length == weights.length); for(int i = 0, end = vals.length; i < end; i++) { put(vals[i], weights[i]); } return this; }
/** * Computes the average distance of the objects to the centroid along the * specified dimension. * * @param centroid the centroid * @param objectIDs the set of objects ids * @param database the database holding the objects * @param dimension the dimension for which the average distance is computed * @return the average distance of the objects to the centroid along the * specified dimension */ private double avgDistance(double[] centroid, DBIDs objectIDs, Relation<V> database, int dimension) { Mean avg = new Mean(); for(DBIDIter iter = objectIDs.iter(); iter.valid(); iter.advance()) { V o = database.get(iter); avg.put(Math.abs(centroid[dimension] - o.doubleValue(dimension))); } return avg.getMean(); }
/** * Note: this test tests an earlier bug with tiny arrays. Keep. */ @Test public void basic() { Mean m = new Mean(); m.put(0); m.put(new double[] {}); m.put(new double[] { 0 }); m.put(new double[] { 0, 0 }); m.put(new double[] { 0, 0, 0 }); assertEquals("Count wrong.", 7, m.getCount(), 0.); assertEquals("Mean wrong.", 0, m.getMean(), 0.); assertEquals("No toString", -1, m.toString().indexOf('@')); assertEquals("Static helper", 2, Mean.of(1, 2, 3), 0.); assertEquals("Static helper", 2, Mean.highPrecision(1, 2, 3), 0.); }
@Test public void testInfinity() { Mean m = new Mean(); m.put(Double.POSITIVE_INFINITY); m.put(0.); assertEquals(2, m.getCount(), 0); assertEquals("Sensitive to infinity", Double.POSITIVE_INFINITY, m.getMean(), 0); m = new Mean(); m.put(Double.NEGATIVE_INFINITY); m.put(0.); assertEquals(2, m.getCount(), 0); assertEquals("Sensitive to infinity", Double.NEGATIVE_INFINITY, m.getMean(), 0); }
/** * Computes the average distance of the objects to the centroid along the * specified dimension. * * @param centroid the centroid * @param objectIDs the set of objects ids * @param database the database holding the objects * @param dimension the dimension for which the average distance is computed * @return the average distance of the objects to the centroid along the * specified dimension */ private double avgDistance(Vector centroid, DBIDs objectIDs, Relation<V> database, int dimension) { Mean avg = new Mean(); for(DBIDIter iter = objectIDs.iter(); iter.valid(); iter.advance()) { V o = database.get(iter); avg.put(Math.abs(centroid.doubleValue(dimension) - o.doubleValue(dimension))); } return avg.getMean(); }
@Test public void combine() { Mean m1 = new Mean(), m2 = new Mean(); m1.put(new double[] { 1, 2, 3 }); m2.put(new double[] { 4, 5, 6, 7 }); Mean m3 = new Mean(m1); m3.put(m2); assertEquals("First mean", 2, m1.getMean(), 0.); assertEquals("Second mean", 5.5, m2.getMean(), 0.); assertEquals("Third mean", 4, m3.getMean(), 0.); m2.put(new double[] { 1, 2, 3 }, new double[] { 3, 2, 1 }); assertEquals("Fourth mean", 3.2, m2.getMean(), 1e-15); } }