def all_features_li_2019_classifier_ffnn_rul_prediction(): training_set = read_dfs(LEARNING_SET, ALL_FEATURES) # Two-Stage: lei et al 2019 training_set, first_prediction_times = cut_fpts(training_set) training_set = procentual_rul(training_set, first_prediction_times) # Visualize FPTs plot_fpts(first_prediction_times, training_set, 'fourier_entropy') # Concatenate trainings data concatenated_training_set = pd.concat( training_set, ignore_index=True, keys=['Bearing' + str(x) for x in range(0, len(training_set))]) labels = concatenated_training_set.pop('RUL') # Train FFNN trainings_history, ffnn = fit_ffnn(X=concatenated_training_set, y=labels, dropout=True, epochs=50) # Visualize training history and later validation history plot_trainings_history(trainings_history) # Visualize predicted RUL in comparison to real RUL of learning set plot_rul_comparisons(training_set, prediction_model=ffnn) # TESTING ESTIMATIONS # testing_set = read_dfs(FULL_TEST_SET, ALL_FEATURES) testing_set, fpts = cut_fpts(testing_set) testing_set = procentual_rul(testing_set, fpts) plot_rul_comparisons(testing_set, prediction_model=ffnn)
def isomap_features_no_classifier_ffnn_rul_prediction(training_data, comparison_set): # Read Training data isomap_training_data = training_data # Remove labels isomap_training_data = concat_dfs(isomap_training_data) labels = isomap_training_data.pop('RUL') model_training_data, isomap = isomap_embedded_data_frame( isomap_training_data, verbose=False) ffnn, training_history = fit_ffnn(model_training_data, labels, epochs=100) plot_trainings_history(training_history) # Visualize predicted RUL in comparison to real RUL # comparison_set = read_raw_dfs(FULL_TEST_SET) # Remove label label_data = pop_labels(comparison_set) # Apply autoencoder comparison_set = [ pd.DataFrame(isomap.transform(X=df)) for df in comparison_set ] plot_rul_comparisons(comparison_set, label_data=label_data, prediction_model=ffnn)
def ahmad_health_indicator_ahmad_classifier_ffnn_rul_prediction(): training_set = read_feature_dfs(LEARNING_SET) training_labels = pop_labels(training_set) training_set = construct_ahmad_health_indicator(training_set) training_set = [ pd.merge(training_set[i], training_labels[i], left_index=True, right_index=True) for i in range(len(training_labels)) ] cut_dfs, fpts = cut_fpts(training_set, fpt_method=ahmad_et_al_2019, signal_key='ahmad_health_indicator') plot_fpts(fpts, df_list=training_set, classification_indicator='ahmad_health_indicator') training_set = concat_dfs(training_set) training_labels = training_set.pop('RUL') ffnn, trainin_history = fit_ffnn(training_set, training_labels, dropout=True, epochs=30, hidden_layers=3, hidden_units=128) comparison_set = read_feature_dfs(FULL_TEST_SET) comparison_set, first_prediction_times = cut_fpts(comparison_set) # Remove label label_data = pop_labels(comparison_set) plot_rul_comparisons(comparison_set, label_data=label_data, prediction_model=ffnn)
def all_features_pca_combination_no_classifier_ffnn_rul_prediction(): # Read Training data feature_list = ALL_FEATURES training_data = read_feature_dfs(data_set_sub_set=LEARNING_SET, features=feature_list) learning_set = concat_dfs(training_data) training_labes = learning_set.pop('RUL') # Remove labels model_training_data, pca = pca_embedded_data_frame(learning_set, verbose=False) model_training_data = pd.DataFrame(model_training_data) ffnn, training_history = fit_ffnn(model_training_data, training_labes, epochs=60) # TODO dropout=True plot_trainings_history(training_history) # Visualize predicted RUL in comparison to real RUL of training set # Remove label training_label_data = pop_labels(training_data) # Apply PCA transformed_training_set = [] for df in tqdm(training_data, desc="Transforming validation set.", position=0, leave=True): transformed_training_set += [pd.DataFrame(pca.transform(X=df))] plot_rul_comparisons(transformed_training_set, label_data=training_label_data, prediction_model=ffnn) # Visualize predicted RUL in comparison to real RUL of validation set comparison_set = read_feature_dfs(data_set_sub_set=FULL_TEST_SET, features=feature_list) # Remove label label_data = pop_labels(comparison_set) # Apply PCA transformed_comparison_set = [] for df in tqdm(comparison_set, desc="Transforming validation set.", position=0, leave=True): transformed_comparison_set += [pd.DataFrame(pca.transform(X=df))] plot_rul_comparisons(transformed_comparison_set, label_data=label_data, prediction_model=ffnn)
def tba_features_ahmad_et_al_2019_ffnn(): feature_list = BASIC_STATISTICAL_FEATURES fpt_method = ahmad_et_al_2019 signal_key = "root_mean_square" learning_set = read_feature_dfs(data_set_sub_set=LEARNING_SET, features=feature_list) # Calculate FPTs and cut dataframes cut_learning_set, first_prediction_times = cut_fpts(learning_set, fpt_method=fpt_method, signal_key=signal_key) plot_fpts(first_prediction_times=first_prediction_times, df_list=learning_set, classification_indicator="root_mean_square") cut_learning_set = concat_dfs(cut_learning_set) training_labes = cut_learning_set.pop('RUL') ffnn, trainings_history = fit_ffnn(X=cut_learning_set, y=training_labes, epochs=100) # Plot trainings history plot_trainings_history(trainings_history=trainings_history, error_type='RMSE') # Read test set testing_set = read_feature_dfs(data_set_sub_set=FULL_TEST_SET, features=feature_list) cut_testing_set, _ = cut_fpts(testing_set, fpt_method=fpt_method, signal_key=signal_key) testing_labels = pop_labels(cut_testing_set) plot_rul_comparisons(cut_testing_set, testing_labels, ffnn)
def all_features_and_autoencoder_li_2019_classifier_ffnn_rul_prediction(): # Input features: statistical features learning_feature_df_list = read_feature_dfs(LEARNING_SET, FEATURES_CSV_NAME) # Two-Stage: lei et al 2019 cut_dfs, first_prediction_times = cut_fpts(learning_feature_df_list) # Visualize FPTs # plot_fpts(first_prediction_times, learning_feature_df_list, 'root_mean_square') # Concatenate trainings data all_bearings = concat_dfs(cut_dfs) labels = all_bearings.pop('RUL') all_bearings, pca = pca_embedded_data_frame(all_bearings) # RUL prediction: FFNN trainings_history, ffnn = fit_ffnn(X=all_bearings, y=labels, dropout=True, epochs=150) # Visualize training history and later validation history plot_trainings_history(trainings_history) # Visualize predicted RUL in comparison to real RUL comparison_set = read_feature_dfs(FULL_TEST_SET, FEATURES_CSV_NAME) comparison_set, first_prediction_times = cut_fpts(comparison_set) # Remove label label_data = pop_labels(comparison_set) # Apply PCA comparison_set = [pd.DataFrame(pca.transform(df)) for df in comparison_set] plot_rul_comparisons(comparison_set, label_data=label_data, prediction_model=ffnn)
def pca_features_no_classifier_ffnn_rul_prediction(training_data, comparison_set): hi = __name__ # Read Training data # Remove labels pca_training_data = concat_dfs(training_data) labels = pca_training_data.pop('RUL') model_training_data, pca = pca_embedded_data_frame(pca_training_data, n_components=300, verbose=False) model_training_data = pd.DataFrame(model_training_data) ffnn, training_history = fit_ffnn(model_training_data, labels, epochs=60, dropout=True) plot_trainings_history(training_history) # Visualize predicted RUL in comparison to real RUL of training set # Remove label training_label_data = pop_labels(training_data) # Apply PCA transformed_training_set = [] for df in tqdm(training_data, desc="Transforming training set.", position=0, leave=True): transformed_training_set += [pd.DataFrame(pca.transform(X=df))] plot_rul_comparisons(transformed_training_set, label_data=training_label_data, prediction_model=ffnn) # Visualize predicted RUL in comparison to real RUL of validation set # Remove label label_data = pop_labels(comparison_set) # Apply PCA transformed_comparison_set = [] for df in tqdm(comparison_set, desc="Transforming validation set.", position=0, leave=True): transformed_comparison_set += [pd.DataFrame(pca.transform(X=df))] plot_rul_comparisons(transformed_comparison_set, label_data=label_data, prediction_model=ffnn)
def spectra_features_no_classifier_cnn_rul_prediction(train: bool = True): model_path: str = Path('keras_models').joinpath('spectra_none_cnn') n_rows: int = 129 n_cols: int = 21 spectra_shape: tuple = (n_rows, n_cols) input_shape: tuple = (n_rows, n_cols, 1) if train: # Read in training data # print("Read in training data") read_spectra_dfs = read_feature_dfs(LEARNING_SET, SPECTRA_CSV_NAME) spectra_dfs = pd.concat( read_spectra_dfs, ignore_index=True, keys=['Bearing' + str(x) for x in range(0, len(read_spectra_dfs))]) labels = spectra_dfs.pop('RUL') # Reformat flattened spectra spectra_dfs = spectra_dfs.to_numpy() spectra_dfs = np.array( [df.reshape(spectra_shape) for df in spectra_dfs]) # Train and save CNN # print("Train and save CNN") trainings_history, cnn = fit_cnn(spectra_dfs, labels, input_shape=input_shape, epochs=20) # Visualize training history plot_trainings_history(trainings_history) cnn.save(model_path) else: # Load pre-trained CNN model cnn = keras.models.load_model(model_path) # Visualize predicted RUL in comparison to real RUL of learning set # print("Visualize predicted RUL in comparison to real RUL of learning set") comparison_set = read_feature_dfs(FULL_TEST_SET, SPECTRA_CSV_NAME) label_data = pop_labels(comparison_set) reshaped_comparison_set = reformat_flattened_data(comparison_set, n_rows=n_rows, n_cols=n_cols) plot_rul_comparisons(reshaped_comparison_set, label_data, cnn)
def entropy_features_no_classifier_ffnn(): feature_list = ENTROPY_FEATURES learning_set = read_feature_dfs(data_set_sub_set=LEARNING_SET, features=feature_list) learning_set = concat_dfs(learning_set) training_labes = learning_set.pop('RUL') ffnn, trainings_history = fit_ffnn(X=learning_set, y=training_labes, epochs=100) plot_trainings_history(trainings_history=trainings_history, error_type='RMSE') testing_set = read_feature_dfs(data_set_sub_set=FULL_TEST_SET, features=feature_list) testing_labels = pop_labels(testing_set) plot_rul_comparisons(testing_set, testing_labels, ffnn)
def tba_features_li_et_al_2019_svr(): feature_list = [] use_hs_classifier = True fpt_method = li_et_al_2019 signal_key = "kurtosis" learning_set = read_feature_dfs(data_set_sub_set=LEARNING_SET, features=feature_list) if use_hs_classifier: # Calculate FPTs and cut dataframes cut_learning_set, first_prediction_times = cut_fpts( learning_set, fpt_method=fpt_method, signal_key=signal_key) plot_fpts(first_prediction_times=first_prediction_times, df_list=learning_set, classification_indicator="root_mean_square") cut_learning_set = concat_dfs(cut_learning_set) training_labes = cut_learning_set.pop('RUL') svr, trainings_history = fit_svr(X=cut_learning_set, y=training_labes) else: learning_set = concat_dfs(learning_set) training_labes = learning_set.pop('RUL') svr, trainings_history = fit_svr(X=learning_set, y=training_labes) # Plot trainings history plot_trainings_history(trainings_history=trainings_history, error_type='RMSE') # Read test set testing_set = read_feature_dfs(data_set_sub_set=FULL_TEST_SET, features=feature_list) if use_hs_classifier: testing_set, _ = cut_fpts(testing_set, fpt_method=fpt_method, signal_key=signal_key) testing_labels = pop_labels(testing_set) plot_rul_comparisons(testing_set, testing_labels, svr)
def statistical_features_li_2019_classifier_ffnn_rul_prediction(): # Input features: statistical features learning_feature_df_list = read_dfs(LEARNING_SET, FEATURES_CSV_NAME, features=BASIC_STATISTICAL_FEATURES) # Two-Stage: lei et al 2019 cut_dfs, first_prediction_times = cut_fpts(learning_feature_df_list) # Visualize FPTs # plot_fpts(first_prediction_times, learning_feature_df_list, 'root_mean_square') # Concatenate trainings data all_bearings = concat_dfs(cut_dfs) labels = all_bearings.pop('RUL') # RUL prediction: FFNN trainings_history, ffnn = fit_ffnn(X=all_bearings, y=labels, dropout=True, epochs=100, hidden_layers=3, hidden_units=1024) # Visualize training history and later validation history plot_trainings_history(trainings_history) # Visualize predicted RUL in comparison to real RUL on trainings set label_data = pop_labels(cut_dfs) plot_rul_comparisons(cut_dfs, label_data=label_data, prediction_model=ffnn) # Visualize predicted RUL in comparison to real RUL on test set comparison_set = read_dfs(FULL_TEST_SET, FEATURES_CSV_NAME, features=BASIC_STATISTICAL_FEATURES) comparison_set, first_prediction_times = cut_fpts(comparison_set) # Remove label label_data = pop_labels(comparison_set) plot_rul_comparisons(comparison_set, label_data=label_data, prediction_model=ffnn)
def visualize_rul(self, df_dict: Dict[str, pd.DataFrame], label_data: Dict[str, pd.Series], experiment_name: str, use_svr: bool = False, use_gpr: bool = False, use_poly_reg: bool = False): plot_rul_comparisons(df_dict, label_data, self, experiment_name=experiment_name, model_name=self.name, use_svr=use_svr, use_gpr=use_gpr, use_poly_reg=use_poly_reg)