DOI: 10.5281/zenodo.8186775
title: Supplemental Material for Predictive Reranking using Code Smells for Information Retrieval Fault Localization

description: <pre># Predictive Reranking using Code Smells for Information Retrieval Fault Localization This repository constitutes the supplementary material, data, and source code for the paper "Predictive Reranking using Code Smells for Information Retrieval Fault Localization", by Thomas Hirsch and Birgit Hofer, 2023. Source code and results are also made available on GitHub: https://github.com/AmadeusBugProject/PredictiveRerankingUsingCodeSmellsForIRFL </pre> <pre>## Preliminaries ### Python environment - python=3.8 - pandas - numpy - joblib - scikit-learn==1.0.2 - keras - tensorflow - nltk - sentence-transformers - matplotlib - seaborn Conda files are located in the root directory of the repository, [conda_from_history.yml](<em>conda_from_history.yml</em>). ### Datasets The [Bench4BL](<em>https://github.com/exatoa/Bench4BL</em>) dataset was used in our evaluation. All data necessary for our machine learning and localization experiments is included in this repository. However, if the data is to be re-imported and recalculated directly from Bench4BL: Bench4BL has to be downloaded and paths to the benchmark root set accordingly in [paths.py](<em>paths.py</em>). BugLocator, BRTracer, and BLIA have to be run on the Bench4BL dataset using the scripting provided by the benchmark. PMD has to be installed in version 6.45.0 and path to PMD set accordingly in [paths.py](<em>paths.py</em>). # Structure of this repository ## General utility functions - [constants.py](<em>constants.py</em>) Contains parameters for the NN model, and other parameters. - [paths.py](<em>paths.py</em>) Contains paths to external datasources and tools, e.g. Bench4BL and PMD. - [utils/bench4bl_utils.py](<em>utils/bench4bl_utils.py</em>) Helper functions for resolving paths to Bench4BL benchmark. - [utils/dataset_utils.py](<em>utils/dataset_utils.py</em>) Helper functions for loading datasets and performing dataset splits. - [utils/Logger.py](<em>utils/Logger.py</em>) Logging. - [utils/nn_classifier.py](<em>utils/nn_classifier.py</em>) NN classifier model. - [utils/scoring_utils.py](<em>utils/scoring_utils.py</em>) Metrics. - [utils/stats_utils.py](<em>utils/stats_utils.py</em>) Wrapper methods for statistical tests. ## Experiment ### Dataset setup and preparation The following scripts are responsible to create, import, and set up data that is used in our experiments. The produced data is already part of this repository, the execution of these scripts is therefore only necessary when data is to be re-imported from the Bench4BL repository. - [a00_pmd_bench4bl.py](<em>a00_pmd_bench4bl.py</em>) Runs PMD on all projects and versions contained in the Bench4BL dataset. The utilized ruleset is defined in [all_java_ruleset.xml](<em>all_java_ruleset.xml</em>). Results are stored in [pmd_results](<em>pmd_results</em>). - [a01_vectorize_pmd.py](<em>a01_vectorize_pmd.py</em>) Creates csv vectors from PMD outputs. - [a02_cloc_bench4bl.py](<em>a02_cloc_bench4bl.py</em>) Runs cloc on all projects and versions contained in the Bench4BL dataset. Only Java files are considered. Results are stored in [cloc_results](<em>cloc_results</em>). - [a02_pmd_usage_in_bench4bl_projects.py](<em>a02_pmd_usage_in_bench4bl_projects.py</em>) Searches for occurrence of PMD in the build files of all projects and versions contained in the Bench4BL dataset. Results are stored in [pmd_usage_in_bench4bl_projects](<em>pmd_usage_in_bench4bl_projects</em>). - [a03_import_bugs_from_bench4bl.py](<em>a03_import_bugs_from_bench4bl.py</em>) Imports textual bug reports and corresponding fixed files ground truth from Bench4BL. Results are stored in [bench4bl_summary](<em>bench4bl_summary</em>). - [a04_normalize_smells_by_loc.py](<em>a04_normalize_smells_by_loc.py</em>) Normalizes the smell vectors for each file with its LOC count. Results are stored in [pmd_results](<em>pmd_results</em>). - [a05_bench4bl_file_features.py](<em>a05_bench4bl_file_features.py</em>) Creates feature vectors for each bug report from PMD smells. Results are stored in [bug_smell_vectors](<em>bug_smell_vectors</em>). - [a05_bench4bl_ranking_results.py](<em>a05_bench4bl_ranking_results.py</em>) Imports the results of BugLocator, BRTracer, and BLIA from the Bench4BL benchmark. Results are stored in [bench4bl_localization_results](<em>bench4bl_localization_results</em>). - [a09_bench4bl_stackoverflow_mpnet.py](<em>a09_bench4bl_stackoverflow_mpnet.py</em>) Creates document embeddings for all textual bug reports using the [stackoverflow_mpnet-base](<em>https://huggingface.co/flax-sentence-embeddings/stackoverflow_mpnet-base</em>) model. Results are stored in [stackoverflow_mpnet_embeddings](<em>stackoverflow_mpnet_embeddings</em>). ### Preliminary experiments and dataset splitting The following scripts perform data set splitting, and the preliminary experiments used for feature selection as discussed in Section VI of the paper. - [b00_analyze_most_promising_smells.py](<em>b00_analyze_most_promising_smells.py</em>) Assumes a perfect smell oracle (by using the known smells of the ground truth files) and applies it to rerank the IRFL tools outputs on the Classification Training Set (the older half of versions in the dataset). Then evaluates the achievable localization performance increase for each smell group. Results are stored in [h_analyze_most_promising_smells](<em>h_analyze_most_promising_smells</em>). - [c00_make_dataset_splits_bootstrap.py](<em>c00_make_dataset_splits_bootstrap.py</em>) Performs dataset splitting. Splits are performed on a temporal ordering of versions of each contained software project. Data is greedily split into 50/25/25, resulting in a Classification training set (used for NN model training), a ranking training set (used to estimate weights for linear combination of smell distance and IRFL suspicousness scores), and a test set (used for evaluating the localization performance achievable by our pipeline). Bootstrapping is applied by resampling fractions of 0.8, 20 times, resulting in 20 sets of the three splits to be used in the following eperiments. Datasets are stored in [p_FINAL_Bench4BL/p_model_for_smell_classification_bootstrap](<em>p_FINAL_Bench4BL/p_model_for_smell_classification_bootstrap</em>) for the full Bench4BL dataset, for the single project experiments please refer to p_FINAL_CAMEL, p_FINAL_HBASE, and p_FINAL_ROO accordingly. - [c01_full_dataset_stats.py](<em>c01_full_dataset_stats.py</em>) Calculates various statistics on the created datasets. Results are stored in [px_summary_dataset](<em>px_summary_dataset</em>). - [d00_model_for_smell_classification_performance_all_groups_bootstrap.py](<em>d00_model_for_smell_classification_performance_all_groups_bootstrap.py</em>) Trains a NN model on the Classification data set and evaluates its classification performance on the Ranking training set. This is performed for all 20 bootstrap iterations, the resulting data is stored in [p_FINAL_Bench4BL/p_model_for_smell_classification_bootstrap](<em>p_FINAL_Bench4BL/p_model_for_smell_classification_bootstrap</em>) for the full Bench4BL dataset, for the single project experiments please refer to p_FINAL_CAMEL, p_FINAL_HBASE, and p_FINAL_ROO accordingly. - [d01_classification_performance_evaluation_for_feature_selection_preliminariy_all_smell_groups.py](<em>d01_classification_performance_evaluation_for_feature_selection_preliminariy_all_smell_groups.py</em>) Creates summary and bootstrap statistics from the previous step. Results are stored in [p_FINAL_Bench4BL/p_summary_classification](<em>p_FINAL_Bench4BL/p_summary_classification</em>) for the full Bench4BL dataset. ### Localization experiments The following scripts perform our actual localization experiments. These scripts are applied to bootstrapped dataset splits. Results are stored in [p_FINAL_Bench4BL](<em>p_FINAL_Bench4BL</em>) for the full Bench4BL dataset, for the single project experiments please refer to p_FINAL_CAMEL, p_FINAL_HBASE, and p_FINAL_ROO accordingly. For a detailed experiment setup we refer to our paper. - [e01_model_for_localization_bootstrap.py](<em>e01_model_for_localization_bootstrap.py</em>) Trains NN models for smell classification and performs predictions on the corresponding test sets. Results are stored in [p_FINAL_Bench4BL/p_model_for_smell_classification_bootstrap](<em>p_FINAL_Bench4BL/p_model_for_smell_classification_bootstrap</em>). - [e02_ranking_training_bootstrap.py](<em>e02_ranking_training_bootstrap.py</em>) Performs reranking of the Ranking training set based on predicted smells by the model created in the previous step. Score combination is performed by linear combination of IRFL tools suspicousness scores and smell distances calculated based on our predictions. Results are stored in [p_FINAL_Bench4BL/p_ranking_training_bootstrap](<em>p_FINAL_Bench4BL/p_ranking_training_bootstrap</em>). - [e03_get_best_weigths_per_project_bootstrap.py](<em>e03_get_best_weigths_per_project_bootstrap.py</em>) Evaluates the outputs of the previous steps in order to pick the best weights for each project and IRFL tool. Results are stored in [p_FINAL_Bench4BL/p_ranking_training_bootstrap](<em>p_FINAL_Bench4BL/p_ranking_training_bootstrap</em>). - [e04_ranking_test_project_wise_bootstrap.py](<em>e04_ranking_test_project_wise_bootstrap.py</em>) Uses predictions of the final NN model and the weights obtained from the previous step to perform rerankings on the Test set. Results are stored in [p_FINAL_Bench4BL/p_ranking_test_proejct_wise_bootstrap](<em>p_FINAL_Bench4BL/p_ranking_test_proejct_wise_bootstrap</em>). ### Result collection and evaluation The following scripts calculate final scores and statistics from the 20 bootstrap iterations of the previous block of scripts. - [f00_bootstrap_summary_compare_map_and_ttest.py](<em>f00_bootstrap_summary_compare_map_and_ttest.py</em>) Calculates localization performance using the MAP metric and performs statistical tests. Results are stored in [p_FINAL_Bench4BL/p_summary_bootstrap](<em>p_FINAL_Bench4BL/p_summary_bootstrap</em>). - [f01_boostrap_summary_compare_classification_performance.py](<em>f01_boostrap_summary_compare_classification_performance.py</em>) Calculates classifier performance of our final model. Results are stored in [p_FINAL_Bench4BL/p_summary_bootstrap](<em>p_FINAL_Bench4BL/p_summary_bootstrap</em>). - [f02_bootstrap_summary_model_classification_performance_eval_test_set_for_all_projects.py](<em>f02_bootstrap_summary_model_classification_performance_eval_test_set_for_all_projects.py</em>) Calculates classifier performance and project wise classifier performance of our final model. Results are stored in [p_FINAL_Bench4BL/p_summary_classification_test_set](<em>p_FINAL_Bench4BL/p_summary_classification_test_set</em>). ### Further analysis The following scripts collect statistics and results to create latex tables and additional analysis used in our paper. - [g00_project_wise_perf_stats.py](<em>g00_project_wise_perf_stats.py</em>) Creates overview latex table comparing the Bench4BL and single project trained pipelines. Results are stored in [px_summary_performance](<em>px_summary_performance</em>). - [g01_project_multiple_file_smell_distances.py](<em>g01_project_multiple_file_smell_distances.py</em>) Analyses smell distances within each bug's ground truth files. Results are stored in [px_summary_dataset](<em>px_summary_dataset</em>). - [g02_performance_correlation_analysis.py](<em>g02_performance_correlation_analysis.py</em>) Performs correlation analysis of our pipeline's MAP localization performance, classification performance, and smell distance measures from previous step. Results are stored in [p_FINAL_Bench4BL/p_summary_correlations](<em>p_FINAL_Bench4BL/p_summary_correlations</em>) for the full Bench4BL dataset. ## Results - [pmd_catalogue/all_smells.json](<em>pmd_catalogue/all_smells.json</em>) lists all PMD smells and associated groups that occur in the dataset. - [px_summary_dataset](<em>px_summary_dataset</em>) contains statistics and information about the utilized dataset. Results for preliminary experiments for feature selection: - [h_analyze_most_promising_smells](<em>h_analyze_most_promising_smells</em>) contains the results of our preliminary experiment into each smell group's information content towards localization. - [p_FINAL_Bench4BL/p_summary_classification](<em>p_FINAL_Bench4BL/p_summary_classification</em>) contains the results of our preliminary experiments into the classifiability of smell groups from textual bug reports. Results of our localization eperiments: - [p_FINAL_Bench4BL/p_summary_bootstrap](<em>p_FINAL_Bench4BL/p_summary_bootstrap</em>) contains the results of our localization experiments, project wise MAP performance summary can be found in [p_FINAL_Bench4BL/p_summary_bootstrap/project_scores_tool_wise_others.tex](<em>p_FINAL_Bench4BL/p_summary_bootstrap/project_scores_tool_wise_others.tex</em>). - [p_FINAL_Bench4BL/p_summary_classification_test_set](<em>p_FINAL_Bench4BL/p_summary_classification_test_set</em>) contains the results of our classification performance analysis of the predictions used in localization. A project wise classification performance summary can be found in [p_FINAL_Bench4BL/p_summary_classification_test_set/macro_average_classification_performances_per_projectother.tex](<em>p_FINAL_Bench4BL/p_summary_classification_test_set/macro_average_classification_performances_per_projectother.tex</em>) ## Licence All code and results are licensed under [AGPL v3](<em>https://www.gnu.org/licenses/agpl-3.0.html.en</em>), according to LICENSE file. Other licences may apply for some tools and datasets contained in this repo: [cloc-1.92.pl](<em>https://github.com/AlDanial/cloc</em>) under [GPL v2](<em>https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html</em>), and data originating from [Bench4BL](<em>https://github.com/exatoa/Bench4BL</em>) under [CCA 4.0](<em>https://creativecommons.org/licenses/by/4.0/</em>). </pre>