def testcenterMatrix(self): 
     #Try centering a test set 
     iterator = CenterMatrixIterator(self.getIterator())
     testIterator = iter(self.testMatrixList) 
     
     for X in iterator: 
         Y = X.todense()
         X2 = next(testIterator)
         Y2 = iterator.centerMatrix(X2).todense()
         nptst.assert_array_almost_equal(Y, Y2)
 def testUnCenter(self): 
     iterator = CenterMatrixIterator(self.getIterator())
     testIterator = iter(self.testMatrixList) 
     
     for X in iterator:
         Y = iterator.uncenter(X).todense()
         Y2 = next(testIterator).todense()
         
         for i in range(Y.shape[0]): 
             if numpy.nonzero(Y[i, :])[0].shape[0] > 1: 
                 nptst.assert_array_almost_equal(Y[i, :], Y2[i, :])
 def testCenterMatrix2(self): 
     """
     Test centering with the Netflix iterator. 
     """
     
     dataset = NetflixDataset()
     #iterator = dataset.getTrainIteratorFunc()
     trainIterator = dataset.getTrainIteratorFunc()
     newIterator = CenterMatrixIterator(trainIterator)   
     X = newIterator.next()
     
     
     for i in range(200): 
         self.assertAlmostEquals(X[i, :].mean(), 0, 6)