def residual(self, max_row_variance=None): """computes the residual for this matrix, if max_row_variance is given, result is normalized by the row variance""" d_rows = util.row_means(self.values) d_cols = util.column_means(self.values) d_all = util.mean(d_rows) tmp = self.values + d_all - util.r_outer(d_rows, d_cols, operator.add) average = util.mean(np.abs(tmp)) if max_row_variance is not None: row_var = self.row_variance() if np.isnan(row_var) or row_var > max_row_variance: row_var = max_row_variance average = average / row_var return average
def mean(self): """returns the mean value""" return util.mean(self.values)
def test_mean_with_nans(self): """tests the mean() function""" array = np.array([2.0, 3.0, np.nan, 1.0]) result = util.mean(array) self.assertAlmostEqual(2.0, result)