Tutorials › Multi-Omics Data Integration › Local Scaling for Uneven Patient Densities

Similarity Network Fusion and Kernel Methods · Tutorial 325 of 597

Local Scaling for Uneven Patient Densities

Learn how to estimate patient-specific distance scales and use them to calculate, interpret, and check locally scaled affinities.

Advanced 12 min read

What You'll Learn

  • Define a patient-specific scale from the distance to the Kth nearest patient.
  • Derive a symmetric affinity by scaling each pairwise distance with both patients’ local scales.
  • Calculate affinities for pairs in dense and sparse regions.
  • Check how neighborhood size and boundary patients affect local scales.
  • Diagnose zero scales, extreme scales, ties, and unstable affinities.
  • Compare local scaling with a single global bandwidth.

Why Use Patient-Specific Scales?

A distance between two patients does not have the same meaning in every part of a cohort. In a dense region of the profile space, a short distance may be typical of many neighbors; in a sparse region, a longer distance may still indicate that two patients are relatively close. A single global bandwidth treats these distances alike, which can make affinities reflect sampling density as much as patient similarity.

Local scaling addresses this by estimating a distance scale separately for each patient. A pairwise distance is then judged relative to the scales of both patients. The result is a symmetric affinity: a large value indicates a pair that is close relative to its local distance scales, while a small value indicates a pair that is far relative to those scales. The distance itself is chosen and computed before this step, as in the earlier material on choosing distances for omics profiles.

Definition: For a cohort of \(n\geq 2\) patients with finite, symmetric, nonnegative pairwise distances \(d_{ij}=d_{ji}\), choose an integer \(K\) satisfying \(1\leq K\leq n-1\). Let \(\sigma_i\) be the distance from patient \(i\) to its \(K\)th nearest other patient. A locally scaled affinity for distinct patients \(i\) and \(j\) is $$ A_{ij}=\exp\left(-\frac{d_{ij}^{2}}{2\sigma_i\sigma_j}\right), $$ provided \(\sigma_i>0\) and \(\sigma_j>0\). This tutorial uses the factor of 2 in the denominator. The diagonal is not part of the pairwise definition; implementations commonly set \(A_{ii}=0\) when storing off-diagonal affinities.

How the Local Affinity Is Constructed

To obtain \(\sigma_i\), sort the \(n-1\) distances from patient \(i\) to all other patients from smallest to largest. The \(K\)th value in that ordering is the local scale. Thus \(K\) controls how many nearby patients determine the scale: a small \(K\) emphasizes the closest neighbors, whereas a larger \(K\) uses a wider neighborhood. Ties are permitted; if several distances are equal at the \(K\)th position, their shared value defines the scale.

The affinity uses the product \(\sigma_i\sigma_j\), not just one patient’s scale. This makes the result symmetric, because both \(d_{ij}=d_{ji}\) and \(\sigma_i\sigma_j=\sigma_j\sigma_i\). The exponent is dimensionless: if all distances and scales are multiplied by the same positive constant, the ratio \(d_{ij}^{2}/(\sigma_i\sigma_j)\) is unchanged. Therefore, changing distance units alone does not change the affinities.

$$ A_{ij}=A_{ji},\qquad 0<A_{ij}\leq 1 $$

For distinct patients with positive finite scales, the affinity is strictly positive. It equals 1 if \(d_{ij}=0\), and it decreases as the pair’s distance increases relative to its scales. It is not a probability, nor does it by itself establish a biological relationship or causal effect.

Derivation and Interpretation

The form of the affinity follows by adapting a Gaussian distance similarity to a pair-specific bandwidth. With one common bandwidth \(\tau>0\), a familiar distance affinity is \(\exp[-d_{ij}^{2}/(2\tau^{2})]\). For a pair of patients with different local scales, replace \(\tau^{2}\) by the symmetric pair scale \(\sigma_i\sigma_j\). This gives

$$ A_{ij}=\exp\left(-\frac{1}{2}r_{ij}^{2}\right), \qquad r_{ij}=\frac{d_{ij}}{\sqrt{\sigma_i\sigma_j}}. $$

Here \(r_{ij}\) is the distance normalized by the geometric mean of the two local scales. If both scales equal \(\tau\), then \(r_{ij}=d_{ij}/\tau\), and the global-bandwidth expression is recovered. If the normalized distance is the same for two different patient pairs, their affinities are also the same, even if their raw distances differ.

This construction gives a precise reason that local scaling can accommodate density differences. Holding \(d_{ij}\) fixed, increasing either positive local scale increases \(\sigma_i\sigma_j\), reduces the magnitude of the negative exponent, and increases \(A_{ij}\). A raw distance that is large may therefore still have appreciable affinity if it is typical relative to both patients’ neighborhoods. Conversely, a short raw distance can receive a modest affinity if it is large relative to particularly small local scales.

Worked Example: Computing Scales and Pairwise Affinities

Suppose a hypothetical cohort has four patients, and its pairwise distance matrix is as follows. Use \(K=1\), so each local scale is the distance to the nearest other patient.

Patient pairDistance
A–B1
A–C4
A–D7
B–C3
B–D6
C–D3

Each patient has three other patients, so \(K=1\) is allowed. The nearest-neighbor distances are \(\sigma_A=1\), \(\sigma_B=1\), \(\sigma_C=3\), and \(\sigma_D=3\). They are all positive, so the affinity formula is defined.

For patients A and B, \(d_{AB}=1\), giving $$ A_{AB}=\exp\left(-\frac{1^2}{2(1)(1)}\right) =\exp(-0.5)\approx 0.6065. $$ For B and C, \(d_{BC}=3\), giving $$ A_{BC}=\exp\left(-\frac{3^2}{2(1)(3)}\right) =\exp(-1.5)\approx 0.2231. $$ For C and D, \(d_{CD}=3\), giving $$ A_{CD}=\exp\left(-\frac{3^2}{2(3)(3)}\right) =\exp(-0.5)\approx 0.6065. $$

The two pairs at distance 3 do not have the same affinity: \(B\)–\(C\) has a smaller value because its distance is large relative to the product of its scales. The \(C\)–\(D\) calculation also illustrates that the affinity is symmetric; swapping the two patient labels does not alter the result.

Dense and Sparse Regions

In a dense region, nearest-neighbor distances tend to be short, producing small local scales. In a sparse region, those distances tend to be longer, producing larger scales. For pairs with comparable normalized distance, local scaling can assign comparable affinities despite different raw distances. This is an adjustment to local distance context, not a claim that the two regions have identical biology.

Worked Example: Comparing a Dense and a Sparse Region

Consider seven hypothetical patients positioned on a one-dimensional profile axis at \(0,1,2,10,14,18,\) and \(22\) distance units. Use absolute differences as distances and \(K=1\). The first three patients form a dense group; the remaining patients are more widely spaced.

The nearest-neighbor distances are 1 for each of the patients at 0, 1, and 2, and 4 for each patient at 10, 14, 18, and 22. For example, the patient at 2 is 1 unit from the patient at 1, and the patient at 10 is 4 units from the patient at 14. All local scales are positive.

For the dense-region pair at 0 and 1, the raw distance is 1 and both scales are 1: $$ A_{0,1}=\exp\left(-\frac{1^2}{2(1)(1)}\right) =\exp(-0.5)\approx 0.6065. $$ For the sparse-region pair at 10 and 14, the raw distance is 4 and both scales are 4: $$ A_{10,14}=\exp\left(-\frac{4^2}{2(4)(4)}\right) =\exp(-0.5)\approx 0.6065. $$

The raw distances differ by a factor of four, but the normalized distances match, so the affinities match. By contrast, the distance between the patients at 2 and 10 is 8, with scales 1 and 4: $$ A_{2,10}=\exp\left(-\frac{8^2}{2(1)(4)}\right) =\exp(-8)\approx 0.0003355. $$

The method thus reflects the contrast between within-region distances and the large gap between these groups. The calculation does not guarantee that local scaling will recover meaningful groups: it only shows how these specified distances and scales determine affinities.

Choosing K and Checking Sensitivity

The choice of \(K\) affects every local scale and therefore can alter affinities substantially. A small \(K\) can be sensitive to a single unusually close neighbor or to measurement noise. A larger \(K\) can produce more stable scales, but may span a gap between groups or blend regions with different densities. There is no universally correct \(K\); it should be examined in light of cohort size, distance behavior, and the intended analysis.

Worked Example: How K Changes a Cross-Region Affinity

Use five hypothetical one-dimensional profiles at \(0,1,2,8,\) and \(10\), with absolute difference as distance. Compare \(K=1\) and \(K=2\), both of which satisfy \(1\leq K\leq n-1=4\). Consider the pair at 2 and 8, whose distance is 6.

For \(K=1\), the scales at 2 and 8 are respectively 1 and 2, because their nearest patients are at 1 and 10. Thus $$ A_{2,8}=\exp\left(-\frac{6^2}{2(1)(2)}\right) =\exp(-9)\approx 0.0001234. $$ For \(K=2\), the scale at 2 is 2, since its second-nearest patient is at 0. The scale at 8 is 6, since its distances to the other patients, in increasing order, are \(2,6,7,8\). Therefore $$ A_{2,8}=\exp\left(-\frac{6^2}{2(2)(6)}\right) =\exp(-1.5)\approx 0.2231. $$

The affinity changes because the larger \(K\) makes the scale at 8 span the gap toward 2. This small hypothetical cohort illustrates why a value of \(K\) should not be treated as a harmless software setting: the neighborhood structure and the cohort’s boundary patients matter.

Assumptions, Diagnostics, and Limitations

The calculation requires a well-defined distance between each pair of patients, a valid \(K\) in the range \(1\leq K\leq n-1\), and positive local scales for all patients whose affinities are computed. The distance must be comparable across the cohort for the normalization to be meaningful. If the distance is dominated by batch effects, poor scaling, or irrelevant features, local scaling cannot repair that problem.

Check the sorted neighbor distances and the distribution of \(\sigma_i\). A scale that is zero makes the denominator undefined; a scale far larger than most others may signal an outlier, a boundary effect, a disconnected region, or a distance problem. Also examine ties and the number of patients sharing the \(K\)th distance. Ties do not invalidate the definition, but repeated profiles can produce zero scales. Such cases require an explicit decision, such as resolving duplicate profiles or using a documented positive lower bound based on measurement resolution. Adding a lower bound changes the affinities and should be reported; it is not merely a numerical detail.

Compare affinities across a few plausible \(K\) values. If small changes in \(K\) create large changes in important pairs, the local structure is not robust to neighborhood choice. Also compare the scales with known technical or clinical structure: patient-specific scales can adapt to density caused by unwanted artifacts just as readily as to meaningful variation.

A global bandwidth is simpler and preserves one common distance scale, but can understate similarity in sparse regions or overstate it in dense ones. Local scaling adapts to neighborhood density, at the cost of an additional \(K\) choice and potentially less direct comparison of raw distance magnitude across regions. Neither approach is universally superior. The locally scaled affinity matrix is generally dense; converting similarities into a sparse affinity graph is a separate decision and is not implied by this formula.

Common pitfall: “The pair at distance 4 must be less similar than the pair at distance 1, because 4 is larger.” That reasoning ignores the local scales. Under local scaling, compare \(d_{ij}/\sqrt{\sigma_i\sigma_j}\), not raw distance alone. In the dense-and-sparse example, distances 1 and 4 both yield affinity about 0.6065 because their normalized distances are equal.

Practical Calculation Sequence

1
Verify the distance inputs.
Check that pairwise distances are finite, symmetric, and nonnegative, and that the chosen distance is appropriate for the patient profiles.
2
Choose a valid neighborhood size.
For \(n\geq2\), use an integer \(K\) with \(1\leq K\leq n-1\). Sort each patient’s distances to the other patients and record the \(K\)th value.
3
Check that scales are positive.
If a scale is zero, the stated affinity formula is undefined for pairs involving that patient. Resolve the issue explicitly before calculating those affinities.
4
Compute and assess affinities.
For each distinct pair, substitute its distance and both scales into the exponential formula. Inspect sensitivity to \(K\) before interpreting the resulting similarities.
Key takeaway: Local scaling replaces a single distance bandwidth with one scale per patient. The affinity depends on the pair’s distance relative to both local scales, so it can make distances from dense and sparse regions comparable while remaining sensitive to the neighborhood size and the quality of the distance inputs.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A cohort has 9 patients. Which integer values of \(K\) are valid for defining a \(K\)th-nearest-other-patient scale?
  2. For a pair, \(d_{ij}=2\), \(\sigma_i=1\), and \(\sigma_j=4\). Calculate the locally scaled affinity to three significant figures.
  3. Why is a zero local scale a problem for the stated affinity formula? Name one response that should be documented.
  4. If two pairs have the same normalized distance \(d_{ij}/\sqrt{\sigma_i\sigma_j}\), what can be said about their affinities?

Solutions. (1) \(K\) can be any integer from 1 through 8 inclusive, because there are 8 other patients. (2) \(A_{ij}=\exp[-2^2/(2(1)(4))]=\exp(-0.5)\approx0.607\). (3) The product of scales appears in the denominator, so a zero scale makes that denominator zero. One documented response is to resolve duplicate profiles or apply a positive lower bound justified by measurement resolution, noting that this changes the affinities. (4) Their affinities are equal: each is \(\exp(-r^2/2)\) for the same normalized distance \(r\).

Clinical Biostats