Esempio n. 1
0
 def test_r_outer(self):
     """tests the r_outer function"""
     result = util.r_outer([5.5, 6.5], [4.5, 7.5], operator.add)
     self.assertAlmostEqual(10.0, result[0][0])
     self.assertAlmostEqual(13.0, result[0][1])
     self.assertAlmostEqual(11.0, result[1][0])
     self.assertAlmostEqual(14.0, result[1][1])
Esempio n. 2
0
 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
Esempio n. 3
0
 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