def test_NotFittedError_transform(self):
     """Checks that an error is returned when
     trying to use the transform function
     before the fit function"""
     X = np.random.uniform(0, 100, size=(3, 3))
     model = StandardFlexibleScaler(column_wise=True)
     with self.assertRaises(sklearn.exceptions.NotFittedError):
         model.transform(X)
 def test_shape_inconsistent_transform(self):
     """Checks that an error is returned when attempting
     to use the transform function with mismatched matrix sizes."""
     X = np.random.uniform(0, 100, size=(3, 3))
     X_test = np.random.uniform(0, 100, size=(4, 4))
     model = StandardFlexibleScaler(column_wise=True)
     model.fit(X)
     with self.assertRaises(ValueError):
         model.transform(X_test)
 def test_inverse_transform(self):
     """Checks the inverse transformation with
     respect to the reference matrix.
     """
     X = np.random.uniform(0, 100, size=(3, 3))
     model = StandardFlexibleScaler(column_wise=True)
     model.fit(X)
     Y = np.random.uniform(0, 100, size=(3, 3))
     Y_tr = model.transform(Y)
     Y = np.around(Y, decimals=4)
     Y_inv = np.around((model.inverse_transform(Y_tr)), decimals=4)
     self.assertTrue((np.isclose(Y, Y_inv, atol=1e-12)).all())
     X = np.random.uniform(0, 100, size=(3, 3))
     model = StandardFlexibleScaler(column_wise=False)
     model.fit(X)
     Y = np.random.uniform(0, 100, size=(3, 3))
     Y_tr = model.transform(Y)
     Y = np.around(Y, decimals=4)
     Y_inv = np.around((model.inverse_transform(Y_tr)), decimals=4)
     self.assertTrue((np.isclose(Y, Y_inv, atol=1e-12)).all())
 def test_transform(self):
     """Checks the transformation relative
     to the reference matrix.
     """
     X = np.random.uniform(0, 100, size=(3, 3))
     model = StandardFlexibleScaler(column_wise=True)
     model.fit(X)
     Y = np.random.uniform(0, 100, size=(3, 3))
     Y_tr = model.transform(Y)
     mean = X.mean(axis=0)
     var = ((X - mean)**2).mean(axis=0)
     scale = np.sqrt(var)
     Y_ex = (Y - mean) / scale
     self.assertTrue((np.isclose(Y_tr, Y_ex, atol=1e-12)).all())