Why Alignment Is Needed
A component index is a label, not an identity. Separate NMF fits can represent similar patterns but list them in different orders; their component scales can also differ without changing the fitted reconstruction. Comparing “component 1” across runs without addressing these indeterminacies can therefore compare different patterns, or make the same pattern look different simply because its scale changed.
This tutorial focuses on matching components from separate fits of the same data representation. Let \(X\) be a nonnegative matrix with \(p\) features and \(n\) samples. In run \(r\), write its rank-\(K\) approximation as \(X \approx W^{(r)}H^{(r)}\), where \(W^{(r)}\) is \(p \times K\) and \(H^{(r)}\) is \(K \times n\). A column of \(W^{(r)}\) is a feature profile; the corresponding row of \(H^{(r)}\) contains that component’s scores across samples. This convention fixes the orientation used below.
Meaningful profile comparisons require the features to be in the same order and represented on compatible scales in both runs. If fits use different feature sets, transformations, or modality definitions, first establish a defensible common feature representation; a similarity score cannot resolve incompatible inputs. The earlier material on scale and permutation indeterminacy in NMF explains why rescaling and reordering can leave a factorization’s reconstruction unchanged.
Normalize Profiles Before Comparing Them
After normalization, compare two profiles with cosine similarity:
Here \(A\) and \(B\) name the two runs, and \(S\) is a \(K \times K\) similarity matrix when both runs have rank \(K\). For nonzero nonnegative profiles, cosine similarity lies between 0 and 1: larger values indicate more similar directions in feature space. It does not measure equality of the profiles’ original magnitudes, and a high value does not by itself establish that a component has a unique interpretation.
Unit-\(L_1\) normalization makes each profile’s entries sum to one and helps remove the arbitrary component scale. Cosine similarity then compares profile directions. These steps do not make profiles independent of choices such as feature preprocessing or block weighting; those choices must be held fixed or explicitly accounted for.
Worked Example: Correcting a Permutation and Scale Difference
Suppose run A has three profiles \(e_1=(1,0,0)^\mathsf{T}\), \(e_2=(0,1,0)^\mathsf{T}\), and \(e_3=(0,0,1)^\mathsf{T}\). Run B stores the same profiles in a different order and scale: \(4e_3, 2e_1, 5e_2\). The corresponding score rows in run B are assumed to have been scaled inversely, so each product of a profile and its score row is unchanged.
Normalize each run B profile by its \(L_1\) norm: \(4e_3/4=e_3\), \(2e_1/2=e_1\), and \(5e_2/5=e_2\). The resulting cosine similarities are 1 for identical unit vectors and 0 for different coordinate vectors. With rows indexed by run A and columns by run B in storage order, the similarity matrix is:
The one-to-one match is A1 to B2, A2 to B3, and A3 to B1. Its total similarity is \(1+1+1=3\), the largest possible total for three similarities each bounded by 1. The match identifies the corresponding patterns despite their different labels and original scales. If B’s profiles had been normalized without compensating their score rows, the reconstruction would have changed; that is why the rescaling step must preserve the profile-score product.
Choose a Global One-to-One Assignment
For equal-rank fits, a standard alignment is the permutation that maximizes the sum of matched similarities. If \(\pi\) maps each component index in run A to one component index in run B, the objective is:
where \(\mathcal{P}_K\) is the set of all permutations of \(1,\ldots,K\). This is a linear assignment problem and can be solved by the Hungarian algorithm. The algorithm finds the global optimum; it does not require listing every permutation. The match is one-to-one: no component in either run is assigned to two components in the other run.
Worked Example: Why the Global Match Can Beat Greedy Matching
Suppose cosine calculations for two hypothetical rank-2 runs give the following similarity matrix. Rows are components in run A and columns are components in run B.
A greedy procedure first takes the largest entry, 0.80, matching A1 to B1. It must then match A2 to B2, for a total of \(0.80+0.20=1.00\), or an average matched similarity of \(1.00/2=0.500\).
The other one-to-one assignment matches A1 to B2 and A2 to B1. Its total is \(0.70+0.75=1.45\), and its average matched similarity is \(1.45/2=0.725\). Thus the global optimum is the second assignment, even though it does not include the single largest entry. Greedy matching optimizes its first choice, not the sum over the complete assignment.
Worked Comparisons After Alignment
A matching is a bookkeeping decision that makes component labels comparable; it does not refit either model or make the runs’ factors identical. Once the match is applied, compare the quantities relevant to the question. For example, matched profile similarities describe agreement in feature shape, while correlations between matched score rows describe agreement in relative sample patterns. Absolute score differences require more care: they can depend on normalization and on whether the runs used comparable preprocessing.
Worked Example: How an Unaligned Score Comparison Misleads
Consider three samples and run A score rows \(h_1=(1,2,4)\), \(h_2=(4,2,1)\), and \(h_3=(1,4,2)\). Suppose run B stores the same three score patterns in the order \(h_3,h_1,h_2\), with profile similarities indicating the match A1–B2, A2–B3, and A3–B1.
If an analyst compares the first row in each run just because both are labelled “component 1,” they compare \(h_1=(1,2,4)\) with B’s first row \(h_3=(1,4,2)\). Their Pearson correlation is approximately \(0.143\). For example, both have mean \(7/3\), and their centered cross-product sum is \(2/3\), while each centered sum of squares is \(14/3\); therefore \(r=(2/3)/\sqrt{(14/3)(14/3)}=1/7\approx0.143\).
After applying the profile-based match, A1 is compared with B2, which is \((1,2,4)\). The matched score correlation is \(1.000\), because the two vectors are identical. This example shows how an arbitrary row order can obscure agreement in sample patterns. It does not show that correlation should replace profile-based matching: the profile similarity defines the stated alignment, and score comparisons are then made using that alignment.
Diagnostics, Alternatives, and Limits
Report more than the matched component labels. Useful diagnostics include the full or summarized similarity matrix, each matched similarity, and the gap between the chosen match and plausible alternatives. A low matched similarity signals weak correspondence under the selected metric. A small assignment margin—where a different full assignment has nearly the same total—signals ambiguity even if the optimum is mathematically well-defined. Neither a high average nor a single high match guarantees that every component is stable.
The chosen similarity measure should reflect the comparison of interest. Cosine similarity is suitable when profile direction or relative feature pattern matters. A distance between normalized profiles is another option, but it defines a different assignment objective and can produce a different match. Correlation centers profiles before comparing them; this may be useful when common offsets are nuisance variation, but centering can create negative values and may not reflect the intended comparison of nonnegative feature contributions. State the metric and normalization rather than treating “similarity” as unambiguous.
For unequal ranks, a rectangular assignment can match at most the smaller number of components. To leave some components unmatched explicitly, use dummy assignments with a stated penalty or threshold. The penalty encodes how much similarity is needed to justify a match; it should not be chosen silently. If one component in a run splits into two in another, or two components merge, a one-to-one permutation cannot represent that relationship. Inspect residual structure, rank choices, and the relevant profiles rather than forcing a misleading match.
Other approaches answer different questions. Independent nearest-neighbor matching allows several components to select the same partner, so it does not produce a one-to-one alignment. Greedy matching can be suboptimal, as the worked example shows. A consensus summary across many runs can describe recurring patterns, but it is not a substitute for stating how a particular pair of runs was aligned. A general rotation-based alignment is also not the same as permutation matching: it can mix component profiles and need not preserve the nonnegative component interpretation.
A common mistake is to conclude that the largest entry in each row gives the correct alignment. Two rows may choose the same column, violating one-to-one matching; resolving the conflict by hand or greedily can lower the total similarity. The correction is to define the similarity matrix and assignment objective first, then solve the global assignment and report its diagnostics. Alignment is useful for cross-run comparison, but it cannot eliminate uncertainty from weakly separated patterns, incompatible preprocessing, or genuinely different decompositions.
Confirm that the runs use the same feature coordinates, compatible preprocessing, and the ranks and matching scope you intend to compare.
Use a stated normalization and compensate the corresponding score rows so each fitted product is preserved.
Compute the stated profile similarity matrix and maximize its total over one-to-one assignments.
Inspect matched similarities, competing assignments, and unmatched or split/merged patterns before interpreting cross-run comparisons.
Check Your Understanding
Answer each question, then compare with the solutions below.
- Why must a profile rescaling be accompanied by an inverse adjustment to its score row?
- For a similarity matrix with entries \(S_{11}=0.88\), \(S_{12}=0.81\), \(S_{21}=0.79\), and \(S_{22}=0.30\), compare the greedy assignment with the global assignment using total similarity.
- What does a low matched cosine similarity indicate, and what does it not establish?
- Why can a one-to-one assignment be inadequate when one component in one run appears to split into two in another?
Solutions. (1) If \(w_k\) is divided by \(c\), its contribution to the product is preserved by multiplying the corresponding score row by \(c\): \((w_k/c)(c h_k)=w_kh_k\). Without the compensation, the reconstruction changes. (2) Greedy matching takes 0.88 and then 0.30, totaling \(1.18\). The alternative assignment totals \(0.81+0.79=1.60\), so the global assignment matches A1–B2 and A2–B1. (3) It indicates weak profile agreement under the chosen feature representation and cosine measure. It does not prove that the component is absent, biologically meaningless, or unstable under every possible metric. (4) A one-to-one assignment requires distinct partners and cannot pair one component with two; forcing such a match hides a possible split and should prompt inspection rather than a simple permutation claim.