def test_smacc_min_endmembers(self): '''Tests that smacc runs with min_endmember argument.''' # Without scaling numeric errors accumulate. scaled_data = self.data / 10000 S, F, R = spy.smacc(scaled_data, 10) data_shape = scaled_data.shape H = scaled_data.reshape(data_shape[0] * data_shape[1], data_shape[2]) assert (np.allclose(np.matmul(F, S) + R, H)) assert (np.min(F) == 0.0) assert (len(S.shape) == 2 and S.shape[0] == 10 and S.shape[1] == 220)
def test_smacc_runs(self): '''Tests that smacc runs without additional arguments.''' # Without scaling numeric errors accumulate. scaled_data = self.data / 10000 S, F, R = spy.smacc(scaled_data) data_shape = scaled_data.shape H = scaled_data.reshape(data_shape[0] * data_shape[1], data_shape[2]) assert_allclose(np.matmul(F, S) + R, H) assert(np.min(F) == 0.0) assert(len(S.shape) == 2 and S.shape[0] == 9 and S.shape[1] == 220)
def test_smacc_max_residual_norm(self): '''Tests that smacc runs with max_residual_norm argument.''' # Without scaling numeric errors accumulate. scaled_data = self.data / 10000 S, F, R = spy.smacc(scaled_data, 9, 0.8) data_shape = scaled_data.shape H = scaled_data.reshape(data_shape[0] * data_shape[1], data_shape[2]) assert (np.allclose(np.matmul(F, S) + R, H)) assert (np.min(F) == 0.0) residual_norms = np.einsum('ij,ij->i', R, R) assert (np.max(residual_norms) <= 0.8)
def test_smacc_minimal(self): '''Tests smacc correctness on minimal example.''' H = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 1.0]]) S, F, R = spy.smacc(H) assert (np.allclose(np.matmul(F, S) + R, H)) assert (np.min(F) == 0.0) expected_S = np.array([ # First two longer ones. [1., 1., 0.], [0., 1., 1.], # First of the two shorted ones. Other can be expressed other 3. [1., 0., 0.], ]) assert (np.array_equal(S, expected_S))