def test_pivot_data(self): json_obj = {"file_list": [self.processed_run_path], "run_list": [1]} json_string = json.dumps(json_obj) df_to_pca = pivot_data( json_string, "discharge_capacity", "voltage", self.cycles_to_pca ) self.assertEqual(df_to_pca.shape, (len(self.cycles_to_pca), 1000))
def test_get_pca_embeddings(self): json_obj = {"file_list": [self.processed_run_path], "run_list": [1]} json_string = json.dumps(json_obj) df_to_pca = pivot_data(json_string, "discharge_capacity", "voltage", self.cycles_to_test) pca_embeddings = self.pc.get_pca_embeddings(df_to_pca) self.assertEqual(pca_embeddings.shape, (len(self.cycles_to_test), self.pc.n_components))
def test_get_reconstruction_errors(self): json_obj = {"file_list": [self.processed_run_path], "run_list": [1]} json_string = json.dumps(json_obj) df_to_pca = pivot_data(json_string, "discharge_capacity", "voltage", self.cycles_to_test) reconstruction_errors, outliers = self.pc.get_reconstruction_error_outliers( df_to_pca, threshold=1.5) self.assertAlmostEqual(reconstruction_errors[0], 0.002553278, places=8) self.assertTrue(outliers[0])
def test_get_pca_reconstruction(self): """ Method to inverse transform PCA embeddings to reconstruct data """ json_obj = {"file_list": [self.processed_run_path], "run_list": [1]} json_string = json.dumps(json_obj) df_to_pca = pivot_data(json_string, "discharge_capacity", "voltage", self.cycles_to_test) pca_embeddings = self.pc.get_pca_embeddings(df_to_pca) pca_reconstruction = self.pc.get_pca_reconstruction(pca_embeddings) self.assertEqual(pca_reconstruction.shape, (len(self.cycles_to_test), 1000))