A Study in Reproducibility: The Congruent Matching Cells Algorithm and cmcR Package

Scientific research is driven by our ability to use methods, procedures, and materials from previous studies and further research by adding to it. As the need for computationally-intensive methods to analyze large amounts of data grows, the criteria needed to achieve reproducibility, specifically computational reproducibility, have become more sophisticated. In general, prosaic descriptions of algorithms are not detailed or precise enough to ensure complete reproducibility of a method. Results may be sensitive to conditions not commonly specified in written-word descriptions such as implicit parameter settings or the programming language used. To achieve true computational reproducibility, it is necessary to provide all intermediate data and code used to produce published results. In this paper, we consider a class of algorithms developed to perform firearm evidence identification on cartridge case evidence known as the Congruent Matching Cells (CMC) methods. To date, these algorithms have been published as textual descriptions only. We introduce the first open-source implementation of the Congruent Matching Cells methods in the R package cmcR . We have structured the cmcR package as a set of sequential, modularized functions intended to ease the process of parameter experimentation. We use cmcR and a novel variance ratio statistic to explore the CMC methodology and demonstrate how to fill in the gaps when provided with computationally ambiguous descriptions of algorithms.


Introduction
Forensic examinations are intended to provide an objective assessment of the probative value of a piece of evidence.Typically, this assessment of probative value is performed by a forensic examiner who visually inspects the evidence to determine whether it matches evidence found on a suspect.The process by which an examiner arrives at their evidentiary conclusion is largely opaque and has been criticized (President's Council of Advisors on Sci.& Tech.2016) because its subjectivity does not allow for an estimation of error rates.In response, National Research Council (2009) pushed to augment subjective decisions made by forensic examiners with automatic algorithms that objectively assess evidence and can be explained during court testimony.In addition to the objectivity of these algorithms, there is an additional benefit: we expect that an algorithm with the same random seed run on the same data multiple times will produce the same answer; that is, that the results are repeatable.This is extremely beneficial because it allows the prosecution and defense to come to the same conclusion given objective evidence or data.

Repeatability and reproducibility
Repeatability in forensic labs is enforced primarily using standard operating procedures (SOPs), which specify the steps taken for any given evaluation, along with the concentrations of any chemicals used, the range of acceptable machine settings, and any calibration procedures required to be completed before the evidence is evaluated.When labs use computational procedures, this SOP is augmented with specific algorithms, which are themselves SOPs intended for use by man and machine.Algorithms are generally described on two levels: we need both the conceptual description (intended for the human using the algorithm) and the procedural definition (which provides the computer hardware with a precise set of instructions).For scientific and forensic repeatability and reproducibility, it is essential to have both pieces: the algorithm description is critical for establishing human understanding and justifying the method's use in court, but no less important is the computer code which provides the higher degree of precision necessary to ensure the results obtained are similar no matter who evaluates the evidence.As with SOPs in lab settings, the code parameters function like specific chemical concentrations; without those details, the SOP would be incomplete and the results produced would be too variable to be accepted in court.
The National Academy of Sciences, Engineering, and Medicine (2019) defines reproducibility as "obtaining consistent computational results using the same input data, computational steps, methods, code, and conditions of analysis."This form of reproducibility requires that the input data, code, method, and computational environment are all described and made available to the community.In many situations, this level of reproducibility is not provided -not just in forensics but in many other The R Journal Vol.14/4, December 2022 ISSN  To aid in comprehension of an algorithm, it is useful to supplement conceptual descriptions with pseudocode.However, a conceptual description and pseudocode alone do not contain sufficient detail (e.g., parameter settings) to ensure computational reproducibility.Implementing algorithms based on conceptual descriptions or pseudocode requires enumerating and testing possible parameter choices which, depending on their complexity, can be a lengthy and expensive process.In contrast, implementing fully reproducible algorithms requires only as much time as it takes to emulate the original development environment.Commonly identified reasons for unreproducible results include (1) ambiguity in how procedures were implemented, (2) missing or incomplete data, and (3) missing or incomplete computer code to replicate all statistical analyses (Leek and Jager 2017).In particular, for statistical algorithms which depend on input data, we find that full reproducibility depends on the provision of both original data and any manual pre-processing applied to said data, as this manual process is not reproducible by itself.In combination with the code, the algorithm description, and the numerical results presented in the paper, it should be possible to fully reproduce the results of a paper.
In this paper, we demonstrate the importance of higher levels of reproducibility by examining the Congruent Matching Cells (CMC) algorithm for cartridge case comparisons and developing an open-source, fully reproducible version for general use in the forensics community.

The Congruent Matching Cells algorithm
A cartridge case is the portion of firearm ammunition that encases a projectile (e.g., bullet, shots, or slug) along with the explosive used to propel the projectile through the firearm.When a firearm is discharged, the projectile is propelled down the barrel of the firearm, while the cartridge case is forced towards the back of the barrel.It strikes the back wall, known as the breech face, of the barrel with considerable force, thereby imprinting any markings on the breech face onto the cartridge case and creating the so-called breech face impressions.These markings are used in forensic examinations to determine whether two cartridge cases have been fired by the same firearm.During a forensic examination, two pieces of ballistic evidence are placed under a comparison microscope.Comparison microscopes allow for a side-by-side comparison of two objects within the same viewfinder, as seen in Figure 1.A pair of breech face images is aligned along the thin black line in the middle of the images.The degree to which these breech face markings can be aligned is used to determine whether the two cartridge cases came from the same source; i.e., were fired from the same firearm.These breech face impressions are considered analogous to a firearm's "fingerprint" left on a cartridge case (Thompson 2017).
The Congruent Matching Cells (CMC) pipeline is a collection of algorithms to process and compare cartridge case evidence (Song 2013).Since its introduction, the pipeline and its extensions (Tong, Song, and Chu 2015;Chen et al. 2017;Song et al. 2018) have shown promise in being able to differentiate between matching and non-matching cartridge cases.However, so far the CMC pipelines have only been introduced in the form of conceptual descriptions.Further, the cartridge case scans used to validate the pipelines are only available in their raw, unprocessed forms on the NIST Ballistics The R Journal Vol.14/4, December 2022 ISSN 2073-4859 Toolmark Research Database (Zheng, Soons, and Thompson 2016).While it is clear that the creators of the CMC pipeline have a working implementation, the wider forensic science community only has access to conceptual descriptions of the pipeline and summary statistics describing its performance.
In our hierarchy of reproducibility, this puts the CMC algorithm somewhere between the conceptual description and reproducible data stage: the steps are described but no code is available, and the raw data are available but manual pre-processing steps make this raw data insufficient to replicate the pipeline even with newly written code.
The development of the CMC algorithm seems to be representative of how many forensic algorithms are developed: after an algorithm is introduced, researchers build upon the foundation laid by the original algorithm in subsequent papers.These changes are often incremental in nature and reflect a growing understanding of the algorithm's behavior.While this cycle of scientific progress certainly is not unique to forensic algorithms, given the gravity of the application it is imperative that these incremental improvements not be unnecessarily delayed.As such, we believe that the forensic community at-large would benefit greatly by establishing an open-source foundation for their algorithms upon which additional improvements can be developed.Using open-source algorithms are cheaper to use than writing one's own code, enables the process of peer review by providing an accessible benchmark, and helps other research groups or companies stay on the leading edge of technology development (The Linux Foundation 2017).
Here, we describe the process of implementing the CMC pipeline for the comparison of marks on spent cartridge cases, using the descriptions from two published papers, Song et al. (2014) and Tong, Song, and Chu (2015).Our R package, cmcR, provides an open-source implementation of the CMC pipeline.We use cmcR to illustrate how ambiguities in the textual description of an algorithm can lead to highly divergent results.In particular, our implementation highlights an extreme sensitivity to processing and parameter decisions that has not been discussed previously.Additionally, we argue that our implementation can be used as a template for future implementations of forensic pattern-matching algorithms to not only ensure transparency and auditability, but also to facilitate incremental improvements in forensic algorithms.
In the remainder of this paper, we describe a general, reproducible, and open-source CMC pipeline which encompasses those discussed in Song (2013), Song et al. (2014), andTong, Song, andChu (2015).Song (2013) lays out the conceptual framework for the original CMC pipeline later implemented in Song et al. (2014) and Tong et al. (2014).An improvement of the pipeline presented in Tong, Song, and Chu (2015) and used in subsequent papers is referred to as the "High CMC" method (Chen et al. 2017).However, it should be noted that what the authors refer to as the original and High CMC decision rules are variations of one step of a larger CMC pipeline.
The cmcR package contains implementations designed for use with 3D topographical scans of the original decision rule described in Song (2013) and Song et al. (2014) and the High CMC decision rule described in Tong, Song, and Chu (2015).The source code to the full cmcR package is accessible at The R Journal Vol.14/4, December 2022 ISSN 2073-4859 https://github.com/CSAFE-ISU/cmcR.

The CMC pipeline
In this section, we examine the process of implementing the CMC pipeline for automatic comparisons of 3D cartridge case scans.At each step, we will discuss how we filled in the gaps of the original description during the creation of cmcR.
All of the CMC pipelines can be broken down into three broad stages: (1) pre-processing, (2) cellbased similarity feature extraction, and (3) application of a decision rule as illustrated in Figure 2. In the following sections we break each of these stages further into a set of modular steps.One advantage of modularizing these algorithms is that we can implement an algorithm as a set of sequential procedures.This allows us to test new variations against the old implementation in a coherent, unified framework.

Figure 2:
The stages of CMC pipelines.In the pre-processing stage, each scan is prepared for analysis, removing extraneous information and noise.Then, each scan is broken up into cells, which are numerically compared to cells in the other scan to determine an optimal alignment.Finally, each of the scores arising from the cells in the second stage are compared to a reference distribution to determine whether the scans originate from the same source or from different sources.
The primary difference between the two pipelines presented here, using the original and High CMC decision rules, lies in how the decision rules are utilized to separate matching vs. non-matching cartridge case pairs.In addition, there are also several small differences in the parameters used in the pre-processing and comparison procedures.

Initial data
Digital microscopy is capable of precision measurements of surface topology at high resolutions.Using a 3D microscope, we can obtain scans of breech face impressions at the micron level (1µm = 10 −3 mm = 10 −6 m).These 3D topological scans are used as input to automated comparison algorithms, such as the CMC pipeline originally proposed in Song (2013).We will use the same data set referenced in Song et al. (2014) and Tong, Song, and Chu (2015) to illustrate usage of the cmcR package.These 3D scans of cartridge cases are available from the NIST Ballistics Toolmark Research Database (Zheng, Soons, and Thompson 2016).The strings defined below refer to three cartridge case scans available on the NBTRD from Fadul et al. (2011) and will be used throughout the remainder of this paper.
Figure 3 shows the surface matrices of a known match (KM) pair of cartridge cases from a study by Fadul et al. (2011).In this study, a total of 40 cartridge cases were scanned with a lateral resolution of 6.25 microns (micrometers) per pixel.The surface matrices are approximately 1200 × 1200 pixels in size corresponding to an area of about 3.8 × 3.8 mm 2 .The observations in the corners of these surface matrices are artifacts of the staging area in which these scans were taken.The holes on the interior of the primer surfaces are caused by the firing pin striking the primer during the firing process.The region of the primer around this hole does not come into uniform contact with the breech face of the firearm.
Only certain regions of a cartridge case contain identifying breech face impression markings.Song (2013) defines "valid correlation regions" as regions where "the individual characteristics of the ballistics signature are found that can be used effectively for ballistics identification."Prior to applying the CMC comparison procedure, cartridge scans must undergo some pre-processing to isolate the valid correlation regions.

Pre-processing procedures
During the pre-processing stage, we apply sequential steps to prepare each cartridge case for analysis.The goal of this process is to remove the edges and center of the scan which did not come into contact with the breech face, as well as any artifacts of the scan and microscope staging which do not accurately represent the breech face surface.The various iterations of the CMC algorithm describe different variations of these steps.A summary of these steps is shown in Figure 4.
Translating the pre-processing steps in Figure 4 into an implementation requires the implementer to decide between potentially many implicit parameter choices.For example, Table 1 compares the pre-processing procedures as described in Song et al. (2014) to considerations that need to be made when implementing the procedures.Depending on one's interpretation of the description, there are many possible implementations that satisfy the described procedure -in contrast, there was only one implementation that led to the original results.While not explicitly mentioned in Song et al. (2014), Song et al. (2018) indicates that the "trimming" of the unwanted regions of the scan is performed manually.It is difficult to replicate manual steps as part of a reproducible pipeline; the best solution is for the authors to provide intermediate data after the manual steps have been completed.
The pre-processing procedures are implemented via modularized functions of the form preProcess_*.Modularizing the steps of the pre-processing procedures makes the overall process easier to understand and allows for experimentation.Figure 5 shows an overview of the pre-processing framework for the Fadul 1-1 breech face from reading the scan (left) to an analysis-ready region (right).For each scan in Figure 5, eleven height value percentiles: the Minimum (0th), 1st, 2.5th, 10th, 25th, Median The R Journal Vol.14/4, December 2022 ISSN 2073-4859   75th,90th,97.5th,99th,and Maximum (100th) are mapped to a purple-to-orange color gradient.This mapping is chosen to highlight the extreme values in each scan.We map the cartridge case surface height values to a divergent purple-white-orange color scale to emphasize deviations from the median height value (represented here as 0 micrometers).At each stage, the variability in height across the scan decreases as we emphasize the regions containing breech face impressions.
We demonstrate usage of the preProcess_* functions on the Fadul 1-1 scan.Each code chunk is followed up with an explanation of the functions used.

#
Step (1) fadul1.1 <-x3ptools::x3p_read("data/fadul1-1.x3p") We begin with a 3D scan.Typically, we downsample scans to about 25% of their size by only retaining every other row and column in the surface matrix.The breech faces in Fadul et al. (2011) were initially scanned at a resolution of 3.125 µm per pixel.Downsampling reduces the resolution to 6.25 µm per pixel.
Step (1) in Figure 5 shows an unprocessed breech face scan.
# Step (2) fadul1.1_cropped<-fadul1.1 %>% cmcR::preProcess_crop(region = "exterior") %>% cmcR::preProcess_crop(region = "interior") We then use a labeling algorithm to identify three major regions of the scan: the exterior of the cartridge case primer, the breech face impression region of interest, and the firing pin impression region in the center of the scan (Hesselink, Meijster, and Bron 2001;Barthelme 2019).We remove observations outside of the breech face impression region (i.e., replaced with NA).The resulting breech face scan, like the one shown in step (2) of Figure 5, is reproducible assuming the same parameters are used.The preProcess_crop function removes the exterior and firing pin impression region on the interior based on the region argument.
# Step (3) fadul1.1_deTrended<-fadul1.1_cropped%>% preProcess_removeTrend(statistic = "quantile", tau = .5,method = "fn") In step (3), we remove the southwest-to-northeast trend observable in steps (1) and ( 2 The R Journal Vol.14/4, December 2022 ISSN 2073-4859 Finally, we apply a band-pass Gaussian filter to the surface values to attenuate noise and unwanted large-scale structure.Step (4) of Figure 5 shows the effect of the preProcess_gaussFilter function.There is currently no determination or removal of outliers in the cmcR package's pre-processing procedures.Instead, we rely on the low-pass portion of the Gaussian filter to reduce the effects of any high-frequency noise.
Figure 6 displays the processed Fadul 1-1 and Fadul 1-2 scans; the second matrix is processed using the same parameters.Next, similarity features are extracted from a processed cartridge case pair in the cell-based comparison procedure.

"Correlation cell" comparison procedure
As described in Song (2013), breech face markings are not uniformly impressed upon a cartridge case during the firing process.As such, only certain sections of the cartridge case are used in a comparison.
In the CMC pipeline as proposed by Song (2013) two scans are compared by partitioning one breech face scan into a grid of so-called "correlation cells".These cells are compared individually to their best-matching counterpart on the other scan.If a large proportion of these correlation cells are highly similar to their counterparts on the other breech face scan, this is considered as evidence that the markings on the two cartridge cases were made by the same source.The number of highly similar cells is defined as the CMC count C (Song 2013) of the breech-face comparison.The CMC count is considered to be a more robust measure of similarity than the correlation calculated between two full scans.
Figure 7 illustrates the cell-based comparison procedure between two cartridge case scans.The scan on the left serves as the reference; it is divided into a grid of 8 × 8 cells.
Figure 8 shows the steps of the correlation cell comparison process in each of the papers as well as the cmcR implementation.Each cell is paired with an associated larger region in the other scan.The absolute location of each cell and region in their respective surface matrices remain constant.However, the scan on the right is rotated to determine the rotation at which the two scans are the most "similar," as quantified by the cross-correlation function (CCF).
For real-valued matrices A and B of dimension M × N and P × Q, respectively, the cross-correlation function, denoted (A ⋆ B) is defined as where 1 ≤ m ≤ M + P − 1 and 1 ≤ n ≤ N + Q − 1.By this definition, the [m, n]th element of the resulting M + P − 1 × N + Q − 1 CCF matrix quantifies the similarity between matrices A and B for a translation of matrix B by m pixels horizontally and n pixel vertically.The index at which the CCF attains a maximum represents the optimal translation needed to align B with A. The CCF as The R Journal Vol.14/4, December 2022 ISSN 2073-4859  The R Journal Vol.14/4, December 2022 ISSN 2073-4859 defined need not be bounded between −1 and 1.However, it is common to normalize the CCF for interpretability, and this is the convention adopted in the cmcR package.
Prior to calculating the CCF, the matrices A and B are standardized through subtraction of their respective means and division by their respective standard deviations.This is referred to as the Areal Cross-Correlation Function (ACCF) in some CMC papers (Ott, Thompson, and Song 2017).A direct calculation of the CCF for breech face scans based on the definition above is prohibitively slow.While computationally feasible alternatives exist, Song (2013) and other CMC papers do not specify the algorithm used to calculate the CCF.
Published descriptions of the CMC algorithm do not detail how the CCF is calculated.In image processing, it is common to use an implementation based on the Fast Fourier Transform (Brown 1992).This implementation leverages the Cross-Correlation Theorem, which states that for matrices A and B, the CCF can be expressed in terms of a frequency-domain pointwise product: where F and F −1 denote the discrete Fourier and inverse discrete Fourier transforms, respectively, and F (A) denotes the complex conjugate (Brigham 1988).Because the product on the right-hand side is calculated pointwise, we trade the moving sum computations from the definition of the CCF for two forward Fourier transformations, a pointwise product, and an inverse Fourier transformation.The Fast Fourier Transform (FFT) algorithm can be used to reduce the computational load considerably.Our implementation of this FFT-based CCF calculation is adapted from the cartridges3D package (Tai 2021).
No computational shortcut comes without some trade-offs, though, and this FFT-based CCF calculation is no different.The FFT does not tolerate missing values, and breech faces are not continuous surfaces -all of the white regions in Figure 7 correspond to missing values.While it is unclear how the CCF is implemented in the CMC papers, the cmcR package adopts the following conventions: • Only cells with a minimum proportion of non-missing pixels are assessed.This minimum threshold differs across CMC papers (15% in Chen et al. (2017) vs. 10% in Song et al. (2018), as shown in Figure 8), and is referenced but not specified in several other papers (Tong et al. 2014;Song et al. 2014;Chu, Tong, and Song 2013).The comparison_calcPropMissing function computes the proportion of a matrix that is missing (NA-valued).
• Missing values are replaced with the overall mean value when the FFT-based CCF is computed (using function comparison_replaceMissing).
• The optimal translation is determined using the FFT-based CCF (using comparison_fft_ccf).
• Based on the optimal translation determined from the FFT-based CCF, we compute the pairwise complete CCF directly, avoiding any distortion of the CCF computation based on compensation for missing values (using function comparison_cor).
All of the steps dealing with cell-based comparisons are implemented as functions of the form comparison_*.Similar to the preProcess_* functions, the comparison_* functions can be chained together through a sequence of pipes.Below, we use the comparison_allTogether function to perform the entire cell-based comparison procedure in one call.The comparison procedure is performed twice: once with Fadul 1-1 considered the "reference" scan divided into cells that are compared to the "target" scan Fadul 1-2 and again with the roles reversed.)) The comparison_allTogether function consists of the following steps wrapped into a single convenience function: The R Journal Vol.14/4, December 2022 ISSN 2073-4859 • comparison_alignedTargetCell: Extract a matrix from the target scan corresponding to the region of the target scan to which the reference cell aligns • cor: Calculate the pairwise-complete correlation between each cell pair The comparison_allTogether is called repeatedly while rotating the target scan by a set of rotation angles.When implementing the High CMC decision rule (Tong, Song, and Chu 2015), both combinations of reference and target scan are examined (e.g.A-B and B-A).
Table 2 shows several rows of the data frame output of the comparison_allTogether function for the comparison of Fadul 1-1 vs. Fadul 1-2 considering Fadul 1-1 as the reference scan.Although we used a grid of 8 × 8 cells, there were only 26 cell-region pairs that contained a sufficient proportion of non-missing values (15% in this example).The features derived from the correlation cell procedure (CCF max , ∆x, ∆y, θ) are then used to measure the similarity between scans.

Decision rule
For each cell on the reference scan, we calculate the translation (∆x, ∆y) and cross-correlation across rotations by a set of angles θ of the target scan.The task is to determine whether multiple cells come to a "consensus" on a particular translation and rotation.If such a consensus is reached, then there is evidence that a true aligning translation and rotation exists and the cartridge cases match.The CMC decision rules principally differ in how they identify consensus among the ∆x, ∆y, θ values.Here, we describe the two pipelines implemented in the cmcR package: using the original decision rule described in Song et al. (2014) and the High CMC decision rule proposed in Tong, Song, and Chu (2015).

The Original CMC decision rule
This section briefly describes the decision rule used in the first CMC paper (Song 2013).For a thorough explanation of the procedure, refer to the CMC Decision Rule Description vignette of the cmcR package.Let x i , y i , θ i denote the translation and rotation parameters which produce the highest CCF for the alignment of cell-region pair i, i = 1, ..., n where n is the total number of cell-region pairs containing a sufficient proportion of non-missing values.Song (2013) propose the median as a consensus (x ref , y ref , θ ref ) across the cell-region pairs.Then, the distance between each (x i , y i , θ i ) and The R Journal Vol.14/4, December 2022 ISSN 2073-4859 The number of matching cell-region pairs, the "CMC count," is used as a measure of similarity the two cartridge cases.Song et al. (2014) indicate that the thresholds T x , T y , T θ , T CCF need to be determined experimentally.Table 3 summarizes the thresholds used in various CMC papers.
Unlike the original CMC pipeline, the High CMC decision rule considers multiple rotations for each cell-region pair.

The High CMC decision rule
For the High CMC decision rule, two scans are compared in both directions -i.e., each scan takes on the role of the reference scan that is partitioned into a grid of cells.Tong, Song, and Chu (2015) claim that some matching cell-region pairs "may be mistakenly excluded from the CMC count" under the original decision rule because they attain the largest CCF at a rotation outside the range allowed by T θ "by chance."Tong, Song, and Chu (2015) introduce consensus values across all cell-region pairs for each rotation angle θ and calculate a θ-dependent CMC count as the sum of matches observed.Under the High CMC rule, a cell-region pair i is defined as a match conditional on a particular rotation θ if it satisfies the following three conditions: The θ-dependent CMC count, CMC θ , is defined as the sum of matching cell-region pairs.
Tong, Song, and Chu (2015) assert that for a truly matching cartridge case pair, the relationship between θ and CMC θ should exhibit a "prominent peak" near the true rotation value.That is, CMC θ should be largest when the scans are close to being correctly aligned.Further, non-matching pairs should exhibit a "relatively flat and random [. . .] pattern" across the CMC θ values.
To determine whether a "prominent peak" exists in the relationship between θ and CMC θ , Tong, Song, and Chu (2015) consider an interval of rotation angles with large associated CMC θ values.Let CMC max = max θ CMC θ be the maximum CMC θ count across all rotation angles.For τ > 0, define S(τ) = {θ : CMC θ > (CMC max − τ)} as the set of rotations with "large" CMC θ values.Tong, Song, The R Journal Vol.14/4, December 2022 ISSN 2073-4859 and Chu (2015) consider the "angular range" as R(τ) = | max θ S(τ) − min θ S(τ)|.If R(τ) is small, then there is evidence that many cells agree on a single rotation and that the scans match.To arrive at a CMC count similarity score, Tong, Song, and Chu (2015) suggest a value for τ of 1 and determine: If the angular range of the "high CMCs" is within the range T θ , identify the CMCs for each rotation angle in this range and combine them to give the number of CMCs for this comparison in place of the original CMC number.
If the angular range is larger than T θ , we say that the cartridge case pair "fails" the High CMC criteria and the original CMC number is used.The High CMC decision rule returns a CMC count at least as large as the original decision rule.

Implementation of decision rules
In this section, we implement the decision rules in cmcR for both the original and High CMC decision rules.For illustrative purposes, we consider a set of thresholds: T x = T y = 20, T θ = 6, and T CCF = 0.5.
Decision rules in cmcR are implemented as functions of the form decision_*.In particular, the decision_CMC function applies both the original and High CMC decision rules depending on if the parameter τ is set.The code below demonstrates the use of decision_CMC on the features kmComparisonFeatures, extracted from the comparison of scans Fadul 1-1 vs. Fadul 1-2.Convserely, kmComparisonFeatures_rev contains the features from a comparison of Fadul 1-2 vs. Fadul 1-1.For comparison, we also compute the CMCs under both decision rules for the comparison between the non-match pair Fadul 1-1 and Fadul 2-1 (not shown to avoid redundancy).
Similarly, CMCs and non-CMCs determined under the High CMC decision rule are shown in Figure 10.Treating Fadul 1-1 and Fadul 1-2 as the reference scan yields 20 and 18 CMCs, respectively.Combining the results as described above, the final High CMC count is 24.
In contrast, Figure 11 shows the CMC results for a comparison between Fadul 1-1 and a known non-match scan, Fadul 2-1, under the exact same processing conditions.Only two cells are classified as congruent matching cells under the original decision rule when Fadul 1-1 is the reference scan.No cells are classified as CMCs in the other direction.While not shown, this pair fails the High CMC criteria and thus was assigned 0 CMCs under the High CMC decision rule.

Ambiguity in algorithmic descriptions
During the implementation process we encountered ambiguous descriptions of the various CMC pipelines.We include the pre-processing and cell-based comparison procedures in the description of CMC methodology to emphasize how sensitive the final results are to decisions made in these first two steps.The pre-processing and cell-based comparison procedures are discussed only briefly, if at all, in Song et al. (2014), Tong et al. (2014), Tong, Song, and Chu (2015), or Chen et al. (2017).However, the results reported often indicate a sensitivity to these procedures.Ambiguities range from minor implicit parameter choices (e.g., the convergence criteria for the robust Gaussian regression filter (Brinkman The R Journal Vol.14/4, December 2022 ISSN 2073-4859  The R Journal Vol.14/4, December 2022 ISSN 2073-4859 and Bodschwinna 2003)) to procedures that are fundamental to feature calculation (e.g., how the cross-correlation is calculated).We bring up these ambiguities to demonstrate the difficulties that we faced when translating the conceptual description of the CMC pipeline into an actual pipeline.While many of these choices are unlikely to affect the results dramatically, we believe that any amount of variability that exists solely because of uncertainty in how the method was intended to be implemented is both unnecessary and dangerous in this application.
The only solution to such ambiguity is to enumerate, implement, and pare-down the possible choices that could have been made to arrive to published results.Unsurprisingly, this process takes a considerable amount of time and that would be better spent furthering the state of the field.During the creation of the cmcR package, the process of re-implementing the comparison and decision steps of the pipeline was fairly straightforward.Emulating the pre-processing procedures used, on the other hand, took months of trial and error.Even after this effort, we still have no assurances that our implementation would match the results of the original implementation if applied to other data sets.
In the next section, we describe the process of resolving these ambiguities in the CMC pipeline descriptions.In doing so, we abstract a set of principles by which pipelines and results can be rendered both computationally reproducible and more thoroughly understood.

CMC pattern matching pipeline
As described in the initial data section, the set of cartridge case scans from Fadul et al. (2011) is commonly used to compare the performance of various classification methods (Song et al. 2014;Tong, Song, and Chu 2015;Chen et al. 2017).This set consists of 40 cartridge cases and 780 total comparisons: 63 known match comparisons and 717 known non-match comparisons.Scans of each breech face impression were taken with a Nanofocus Confocal Light Microscope at 10 fold magnification for a nominal lateral resolution of 3.125 microns per pixel and published to the NBTRD (Zheng, Soons, and Thompson 2016).We also use the Weller et al. (2012) data set of 95 cartridge cases for comparison.For the Weller et al. (2012) dataset, we manually isolated the breech face impression regions using the FiX3P software (accessible here: https://github.com/talenfisher/fix3p).We compare results from the cmcR package to published results using processed scans available through the Iowa State University DataShare repository (Zemmels, Hofmann, and Vanderplas 2022).Our goal is to show that results obtained from cmcR are similar, at least qualitatively, to previously published results.However, justification for any differences will ultimately involve educated guesses due to the closed-source nature of the original implementations.
For each cartridge case pair, we calculate CMC counts under both the original and High CMC decision rules.In practice, we classify a cartridge case pair as "matching" if its CMC count surpasses some threshold; 6 CMCs being the generally accepted threshold in many papers (Tong, Song, and Chu 2015;Song et al. 2018;Song 2013).However, this threshold has been shown to not generalize well to all proposed methods and cartridge case data sets (Chen et al. 2017).We instead use an optimization criterion to select parameters.In doing so, we will demonstrate the sensitivity of the pipeline to parameter choice.Additionally, we introduce a set of principles designed to reduce the need for brute-force searches across parameter settings when re-implementing algorithms without accompanying code.Adherence to these principles yields not only computationally reproducible results, but also improves a reader's understanding of a proposed pipeline.

Processing condition sensitivity
Choosing threshold values T x , T y , T θ , T CCF for translation, rotation, and maximum cross-correlation is crucial in declaring a particular cell-region pair "congruent."However, many combinations of these thresholds yield perfect separation between the matching and non-matching CMC count distributions.Therefore, choosing parameters based on maximizing classification accuracy does not lead to an obvious, single set of parameters.We instead consider the ratio of between-and within-group variability to measure separation between match and non-match CMC counts.
Let C ij denote the CMC count assigned to the jth cartridge case pair, j = 1, ..., n i from the ith group, i = 1, 2 representing matches and non-matches, respectively.For each set of thresholds we calculate the Variance Ratio r as:

,
where C i. denotes the within-group CMC count average and C .. denotes the grand CMC count average.Greater separation between and less variability within the match and non-match CMC count The R Journal Vol.14/4, December 2022 ISSN 2073-4859 distributions yields larger r values.
For example, Figure 12 shows results for the original decision rule and the High CMC decision rule for parameters T x = 20 = T y pixels, T CCF = 0.5, and T θ = 6.Despite both decision rules resulting in separation between the matching and non-matching CMC count distributions, the High CMC decision rule yields greater separation as evidenced by the larger r value.
Figure 12: CMC count relative frequencies under the original decision rule and the High CMC decision rule for T ∆x = 20 = T ∆y pixels, T CCF = 0.5, and T θ 6 degrees.An AUC = 1 corresponds to perfect separation of the match and non-match CMC count distributions.We can see that, for this set of processing parameters, the High CMC decision rule yields higher CMC counts for known matches that the original decision rule while known non-matches have the same distribution under both methods.
To explore the pipeline's sensitivity, we consider five dimensions that have a demonstrable impact on CMC counts: • the decision rule (original or High CMC) used, • whether the global trend is removed during pre-processing, and • choice of congruency thresholds: translation T x , T y , rotation T θ , and cross-correlation T CCF .
Choosing a single parameter setting that results in perfect identification is not enough to generally understand the algorithm.Instead, we use the variance ratio r to identify promising ranges of parameters.Figure 13 shows the value of the variance ratio under different parameter settings.We see that the High CMC decision rule yields better separation than the original decision rule under any parameter setting.The largest variance ratio values are achieved for thresholds T x , T y ∈ [10, 20], T θ = 6, and T CCF ∈ [0.4,0.5].Interestingly, considering Table 3, only the parameters used in Song et al. (2018) fall into these ranges.
As shown in Figure 13, de-trending breech-scans in the pre-processing stage emerges as a critical step to achieve good algorithmic results.This step is not explicitly mentioned in the written-word descriptions of the algorithm in Song (2013), Tong et al. (2014), Tong, Song, andChu (2015), Chen et al. (2017), or Song et al. (2018), though it appears from their examples that it was used in the process.Figure 13 also illustrates how breaking a pipeline up into modularized steps eases experimentation.We will expand upon this idea in the next section.
We compare the best results from cmcR to results presented in previous papers.In particular, we have calculated variance ratio statistics shown in Figure 14 based on CMC counts reported in Song (2013), Tong et al. (2014), Tong, Song, and Chu (2015), Chen et al. (2017), andSong et al. (2018).The last row in each facet shows the variance ratio values obtained from cmcR.We see that the implementation provided in cmcR yields comparable results to previous CMC papers.

Conclusion
Reproducibility is an indispensable component of scientific validity (Goodman, Fanelli, and Ioannidis 2016).In this paper, we demonstrate at least three ways reproducibility can go awry: ambiguity in procedural implementation, missing or incomplete data, and missing or incomplete code.In forensics, many matching algorithms are commonly presented in the form of conceptual descriptions with accompanying results.There is sound reasoning to this; conceptual descriptions are more easily understood by humans compared to computer code.However, using the CMC pipelines as an example The R Journal Vol.14/4, December 2022 ISSN 2073-4859  The R Journal Vol.14/4, December 2022 ISSN 2073-4859 we have observed the gaps that can exist when translating a conceptual description of an algorithm to a genuine implementation.This is largely due to the fact that conceptual descriptions rarely detail implicit parameter choices required to run an algorithm.Consequently, there are multiple choices that are compatible with the description of an algorithm in a publication.This is dangerous in a forensics context because if many parameter settings are valid but only a narrow range lead to the same conclusion, it is entirely possible that witnesses for the prosecution and defense comef to different conclusions.In order to prevent such misunderstandings, it is not enough to have guidelines for parameter settings and/or a sensitivity study -it is also necessary to standardize the specific computer code.The parameter values are only useful within the context of a single software package or pipeline.
These principles of open, accessible, interoperable code are also critical for a fair (in the legal sense) justice system: the defense has access to the code to understand the evidence against them, lawyers and examiners can assess the utility of the analysis method, and judges can determine whether a method is admissible in court.Transparent and intuitive open-source algorithms, such as cmcR, should be considered the gold standard in allowing the forensic science community to validate a pipeline.
Our contribution to the CMC literature is the open-source implementation, which fills the gaps in the human-friendly descriptions in the original papers.In addition, because we have structured the cmcR implementation as a modular pipeline, it is easier to improve upon the CMC method and document the effects of specific changes to the algorithm compared to previous versions.The modularization creates an explicit framework to assess the utility and effectiveness of each piece of the algorithm, and allows us to independently manipulate each step while monitoring the downstream impact on the results.Additionally, it allows future collaborators to improve on pieces of the pipeline, adding new options and improving the method without having to re-invent the wheel.Indeed, re-implementing steps of the pipeline is at best a useful academic exercise and at worst a waste of time and resources that could be spent actually improving the pipeline.Even after many months of trial and error, although we have succeeded in obtaining qualitatively similar results on two data sets, it is difficult to know whether our implementation will behave the same as previous implementations on external data sets.Generalizability is an important assessment for any computational algorithm (Vanderplas et al. 2020).
Our application is far from unique: some journals have adopted policies encouraging or requiring that authors provide code and data sufficient to reproduce the statistical analyses, with the goal of building a "culture of reproducibility" in their respective fields (Peng 2009(Peng , 2011;;Stodden, Guo, and Ma 2013).Peer-review and scientific progress in the truest sense requires that all pre-processed data, code, and results be made openly available (Kwong 2017;Desai and Kroll 2017).Our experience with the CMC algorithm suggests that these standards should be adopted by the forensic science community, leveraging open-source ecosystems like R and software sharing platforms such as Github.We firmly believe that the forensic community should not go only halfway, trading a subjective, human black box for objective, proprietary algorithms that are similarly opaque and unauditable.Open, fully reproducible packages like cmcR allow research groups to make incremental changes, compare different approaches, and accelerate the pace of research and development.

Acknowledgement
This work was partially funded by the Center for Statistics and Applications in Forensic Evidence (CSAFE) through Cooperative Agreement 70NANB20H019 between NIST and Iowa State University, which includes activities carried out at Carnegie Mellon University, Duke University, University of California Irvine, University of Virginia, West Virginia University, University of Pennsylvania, Swarthmore College and University of Nebraska, Lincoln.
We greatly appreciate the constructive feedback from the two anonymous reviewers.Special thanks also to all the developers and open-source contributors of R, knitr (Xie 2015(Xie , 2014)), rticles (Allaire et al. 2021), and the tidyverse (Wickham et al. 2019), without whom this project would not have been possible.

Figure 1 :
Figure1: A cartridge case pair with visible breech face impressions under a microscope.A thin line can be seen separating the two views.The degree to which the markings coincide is used to conclude whether the pair comes from the same source.

Figure 3 :
Figure 3: Unprocessed surface matrices of the known-match Fadul 1-1 and Fadul 1-2 Fadul et al. 2011.The observations in the corners of these surface matrices are artifacts of the staging area in which these scans were taken.The holes on the interior of the primer surfaces are caused by the firing pin striking the primer during the firing process.The region of the primer around this hole does not come into uniform contact with the breech face of the firearm.

Figure 4 :
Figure 4: Overview of the set of pre-processing steps used in the CMC algorithms.Where a procedure step is not discussed or explicitly not applied in the paper, the path traverses empty space.

Figure 5 :
Figure 5: Illustration of the sequential application of pre-processing steps implemented in cmcR.We map the cartridge case surface height values to a divergent purple-white-orange color scale to emphasize deviations from the median height value (represented here as 0 micrometers).At each stage, the variability in height across the scan decreases as we emphasize the regions containing breech face impressions.

Figure 6 :
Figure 6: Fadul 1-1 and Fadul 1-2 after pre-processing.Similar striated markings are now easier to visually identify on both surfaces.It is now clearer that one of the scans needs to be rotated to align better with the other.

Figure 7 :
Figure7: Illustration of comparing a cell in the reference cartridge case scan (left) to a larger region in a questioned cartridge case scan (right).Every one of the cells in the reference cartridge case is similarly paired with a region in the questioned cartridge case.To determine the rotation at which the two cartridge cases align, the cell-region pairs are compared for various rotations of the questioned cartridge case.

Figure 8 :
Figure 8: Each CMC implementation uses a slightly different procedure to obtain a similarity score between two cartridge cases.Steps which are implemented with additional user-specified parameters are shaded purple; steps which are described but without sufficient detail are shaded grey.

Figure 9 :Figure
Figure 9: CMC results for the comparison between Fadul 1-1 and Fadul 1-2 using the original decision rule.The two plots in the top row show the 18 CMCs when Fadul 1-1 is treated as the "reference" cartridge case to which Fadul 1-2 (the "target") is compared.The second row shows the 17 CMCs when the roles are reversed.Red cells indicate where cells not identified as congruent achieve the maximum pairwise-complete correlation across all rotations of the target scan.

Figure
Figure Applying both decision rules to the comparison between the non-match pair Fadul 1-1 and Fadul 2-1 results in 2 CMCs under the original decision rule (shown above) and 0 CMCs under the High CMC decision rule (not shown).The seemingly random behavior of the red cells exemplifies the assumption that cells in a non-match comparison do not exhibit an observable pattern.Random chance should be the prevailing factor in classifying non-match cells as CMCs.

Figure 13 :
Figure 13: Variance ratio values are plotted for different parameter settings.High variance ratios are indicative of a a good separation between CMC counts for known matching pairs and known-non matching pairs.The High CMC decision rule generally performs better than the original decision rule.Removing the trend during pre-processing has a major impact on the effectiveness of the CMC pipeline.In this setting, translation thresholds T x , T y ∈ [15, 20], a rotation threshold T θ = 6, and a CCF threshold T CCF ∈ [0.4,0.5] lead to a separation of results.

Figure 14 :
Figure 14: Variance ratios based on results reported in various CMC papers.The High CMC decision rule tends to outperform the original decision rule.However, it should be emphasized that each paper uses very different processing and parameter settings meaning the results are difficult to compare.The values labeled "cmcR" show the largest variance ratio values for the original and High CMC decision rules based on a limited grid search.These results indicate that the CMC pipeline implementation provided in cmcR yields comparable results to previous CMC papers.

Table 1 :
Description of pre-processing procedures fromSong et al. 2014 vs.considerations that need to be made when implementing these procedures.Each of these considerations requires the implementer to decide between potentially many choices.

Description from Song et al. (2014) Implementation Considerations
"Trim off the inside firing pin surface and other areas outside the breech face mark, so that only breech face impression data remain for correlation."Removal of firing pin hole, primer exterior, global trend, and primer roll-off "Identify and remove dropouts or outliers."Definition of outliers, what "removal" The R Journal Vol.14/4, December 2022 ISSN 2073-4859 (50th),

Table 2 :
Example of output from correlation cell comparison procedure between Fadul 1-1 and Fadul 1-2 rotated by -24 degrees.Due to the large proportion of missing values that are replaced to compute the FFT-based correlation, the pairwise-complete correlation is most often greater than the FFT-based correlation.Divide the reference scan into cells • comparison_getTargetRegions: Extract regions associated with each reference cell from the target scan • comparison_calcPropMissing: Compute missing proportions and filter out cells with a propor- tion of missing values above the threshold.• comparison_standardizeHeights: Standardize height values • comparison_replaceMissing: Replace missing values • comparison_fft_ccf: Compute CCF and estimated translations using FFT • comparison_cellDivision:

Table 3 :
Different thresholds for translation, rotation, and CCF max are used across different papers.The range in CCF max is particularly notable.
ref , y ref , θ ref ) is compared to thresholds T x , T y , T θ , T CCF .A cell-region pair i is declared a "match" if all of the following conditions hold: