/** * Compute the mean square residue. * * @param mat Data matrix * @return mean squared residue */ protected double computeMeanSquaredDeviation(final double[][] mat) { final Mean msr = new Mean(); visitAll( mat, CellVisitor.SELECTED, new CellVisitor() { @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; } }); residue = msr.getMean(); return residue; }
/** * Computes the <b>mean column residue</b> of the given <code>col</code>. * * @param col The column who's residue should be computed. * @return The row residue of the given <code>col</code>um. */ protected double computeColResidue(final double[][] mat, final int col) { final double bias = colM[col] - allM; final Mean colResidue = new Mean(); visitColumn( mat, col, CellVisitor.SELECTED, new CellVisitor() { @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; } }); return colResidue.getMean(); }
/** * Computes the <b>mean row residue</b> of the given <code>row</code>. * * @param mat Data matrix * @param row The row who's residue should be computed. * @param rowinverted Indicates if the row should be considered inverted. * @return The row residue of the given <code>row</code>. */ protected double computeRowResidue(final double[][] mat, int row, final boolean rowinverted) { final Mean rowResidue = new Mean(); visitRow( mat, row, CellVisitor.SELECTED, new CellVisitor() { @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; } }); return rowResidue.getMean(); }