Tutorials › Multivariate Statistics (Graduate) › Hard and Soft Thresholding of Covariance Entries

High-Dimensional Covariance Estimation · Tutorial 788 of 975

Hard and Soft Thresholding of Covariance Entries

Learn how hard and soft thresholding act on covariance entries, what their bias–variance trade-offs look like, and how to calculate each estimator.

Advanced 10 min read

What You'll Learn

  • Define hard and soft thresholding for off-diagonal sample covariance entries
  • Derive both rules from scalar penalized least-squares objectives
  • Calculate the two thresholded estimators for a symmetric covariance matrix
  • Express Gaussian-noise bias and variance using truncated normal moments
  • Compare the estimators at a zero entry and at a large signal
  • Identify why entrywise thresholding does not automatically yield a valid covariance matrix

Why Threshold Covariance Entries?

When the number of variables is large relative to the sample size, a sample covariance matrix can contain many noisy off-diagonal estimates. If the underlying covariance structure is sparse, many population covariances are zero or small enough to be treated as negligible. Entrywise thresholding makes that sparsity explicit: it removes some off-diagonal estimates and, depending on the rule, shrinks others toward zero.

Let \(X_1,\ldots,X_n\) be independent and identically distributed random vectors in \(\mathbb{R}^p\), with finite second moments and covariance matrix \(\Sigma=(\sigma_{jk})\). Write \(\bar X=n^{-1}\sum_{i=1}^n X_i\), and use the sample covariance matrix

$$ S=\frac{1}{n-1}\sum_{i=1}^n (X_i-\bar X)(X_i-\bar X)^\mathsf{T}. $$

The rules below act on each off-diagonal entry \(S_{jk}\), \(j\ne k\). They leave the diagonal entries unchanged. This convention preserves the estimated marginal variances and, when the same rule is used on both sides of the diagonal, preserves symmetry.

Definition: For a threshold \(\lambda\ge 0\), the hard-thresholding function and soft-thresholding function are \(H_\lambda(x)=x\,\mathbf{1}\{|x|>\lambda\}\) and \(T_\lambda(x)=\operatorname{sign}(x)(|x|-\lambda)_+\), respectively, where \((a)_+=\max(a,0)\). The corresponding thresholded covariance estimators have entries \(\hat\sigma_{jj}=S_{jj}\) and, for \(j\ne k\), \(\hat\sigma_{jk}=H_\lambda(S_{jk})\) or \(\hat\sigma_{jk}=T_\lambda(S_{jk})\).

At \(|x|=\lambda\), hard thresholding sets the entry to zero under the strict inequality in its definition. Soft thresholding also sets it to zero. For \(|x|>\lambda\), hard thresholding retains the observed value exactly, whereas soft thresholding reduces its magnitude by \(\lambda\).

Two Scalar Optimization Derivations

Both rules can be derived by treating one observed entry \(s\) as a noisy estimate of a target value \(z\). The squared-error term \(\tfrac12(z-s)^2\) favors staying close to the observation. Different penalties produce the two thresholding rules.

Result: A minimizer of \(\tfrac12(z-s)^2+\tfrac12\lambda^2\mathbf{1}\{z\ne0\}\) is \(H_\lambda(s)\), choosing zero at a tie. The unique minimizer of \(\tfrac12(z-s)^2+\lambda|z|\) is \(T_\lambda(s)\).

Hard thresholding derivation. If \(z=0\), the objective is \(s^2/2\). Among all nonzero \(z\), the squared-error term is minimized at \(z=s\), giving objective \(\lambda^2/2\) when \(s\ne0\). Thus the best nonzero choice is preferable exactly when \(s^2>\lambda^2\), or \(|s|>\lambda\). When \(|s|=\lambda\), zero and \(s\) tie, and the stated convention selects zero. If \(s=0\), zero is also the minimizer. These cases give \(H_\lambda(s)\).

Soft thresholding derivation. For \(z>0\), differentiating the objective gives \(z-s+\lambda\); a stationary point in that region is \(z=s-\lambda\), which is valid when \(s>\lambda\). For \(z<0\), the derivative is \(z-s-\lambda\); the stationary point \(z=s+\lambda\) is valid when \(s<-\lambda\). If \(-\lambda\le s\le\lambda\), the subgradient at \(z=0\) contains zero: it is \(-s+\lambda[-1,1]\). The objective is strictly convex because of its quadratic term, so these candidates give its unique minimizer. Together they are exactly \(T_\lambda(s)\). \(\square\)

Worked Example: Applying Both Rules to a Covariance Matrix

Suppose the sample covariance matrix is

$$ S= \begin{pmatrix} 1.00&0.32&-0.18&0.07\\ 0.32&1.50&0.24&-0.41\\ -0.18&0.24&0.90&0.12\\ 0.07&-0.41&0.12&1.20 \end{pmatrix}, \qquad \lambda=0.20. $$

The diagonal entries remain \(1.00,1.50,0.90,1.20\). For hard thresholding, an off-diagonal entry survives only if its absolute value is strictly greater than \(0.20\). Thus \(0.32,0.24,-0.41\) and their symmetric counterparts survive; \(-0.18,0.07,0.12\) and their counterparts become zero. Therefore

$$ \hat\Sigma_H= \begin{pmatrix} 1.00&0.32&0&0\\ 0.32&1.50&0.24&-0.41\\ 0&0.24&0.90&0\\ 0&-0.41&0&1.20 \end{pmatrix}. $$

For soft thresholding, subtract \(0.20\) from each surviving magnitude and keep its sign. For example, \(T_{0.20}(0.32)=0.12\), \(T_{0.20}(0.24)=0.04\), and \(T_{0.20}(-0.41)=-0.21\); values of magnitude at most \(0.20\) become zero. Hence

$$ \hat\Sigma_S= \begin{pmatrix} 1.00&0.12&0&0\\ 0.12&1.50&0.04&-0.21\\ 0&0.04&0.90&0\\ 0&-0.21&0&1.20 \end{pmatrix}. $$

The two estimates have the same zero pattern here, but not the same retained values. Hard thresholding preserves each retained sample covariance; soft thresholding shrinks it.

Bias and Variance Under Gaussian Entry Noise

To compare repeated-sample behavior, consider a scalar model for one off-diagonal entry: \(Y=\theta+\varepsilon\), where \(\theta\) is the population covariance entry and \(\varepsilon\sim N(0,\tau^2)\). This is a marginal noise model for an entry; it does not assert that all sample covariance entries are mutually independent. Write \(\phi\) and \(\Phi\) for the standard normal density and distribution function, and define \(a=(\lambda-\theta)/\tau\), \(b=(-\lambda-\theta)/\tau\), assuming \(\tau>0\).

Result: In this Gaussian model, the mean of the hard-thresholded estimate is \(m_H=E[H_\lambda(Y)]=\theta\{1-\Phi(a)+\Phi(b)\}+\tau\{\phi(a)-\phi(b)\}\). Its second moment is \(q_H=(\theta^2+\tau^2)\{1-\Phi(a)+\Phi(b)\}+\tau\{(\theta+\lambda)\phi(a)+(\lambda-\theta)\phi(b)\}\). Consequently, its bias is \(m_H-\theta\) and its variance is \(q_H-m_H^2\).

To verify these expressions, note that \(H_\lambda(Y)=Y\) on \(Y>\lambda\) and on \(Y<-\lambda\), and is zero otherwise. With \(Z=(Y-\theta)/\tau\), the two retained regions are \(Z>a\) and \(Z<b\). The standard normal tail identities \(E[Z\mathbf{1}\{Z>a\}]=\phi(a)\) and \(E[Z^2\mathbf{1}\{Z>a\}]=1-\Phi(a)+a\phi(a)\), with corresponding lower-tail identities, follow by integrating the normal density and using \(\phi'(z)=-z\phi(z)\). Applying them to \(Y=\theta+\tau Z\) gives the displayed first and second moments. Subtracting the square of the mean from the second moment gives the variance. \(\square\)

For soft thresholding, the mean can be written in the same tail notation:

$$ m_S=E[T_\lambda(Y)] =\theta\{1-\Phi(a)+\Phi(b)\} +\tau\{\phi(a)-\phi(b)\} -\lambda\{1-\Phi(a)-\Phi(b)\}. $$

Indeed, on \(Y>\lambda\) the estimate is \(Y-\lambda\), and on \(Y<-\lambda\) it is \(Y+\lambda\); elsewhere it is zero. The final term is the expected signed subtraction on those two tails. Its variance is \(E[T_\lambda(Y)^2]-m_S^2\), where

$$ E[T_\lambda(Y)^2] =\int_{\lambda}^{\infty}(y-\lambda)^2 f_Y(y)\,dy +\int_{-\infty}^{-\lambda}(y+\lambda)^2 f_Y(y)\,dy, \qquad f_Y(y)=\frac{1}{\tau}\phi\!\left(\frac{y-\theta}{\tau}\right). $$

Small and Large Entries: What Changes?

At a truly zero entry, symmetry gives zero expected estimate for both rules, so both have zero bias at that exact parameter value. They do not have zero variance: repeated noise can push an observed entry beyond the threshold. Soft thresholding has a useful pointwise comparison at this null value. For every observation \(y\), \(|T_\lambda(y)|\le |H_\lambda(y)|\), so its squared estimate is no larger than the hard-thresholded squared estimate. Both estimates have mean zero when \(\theta=0\); therefore this pointwise inequality also proves that soft thresholding has no greater variance than hard thresholding at \(\theta=0\).

Result: If \(\theta=0\), then \(\operatorname{Var}(T_\lambda(Y))\le\operatorname{Var}(H_\lambda(Y))\). This follows from symmetry, which gives zero means, and the pointwise inequality \(T_\lambda(y)^2\le H_\lambda(y)^2\) for every \(y\).

For small but nonzero \(\theta\), the estimates need not remain unbiased. Thresholding can set a real covariance to zero, creating bias toward zero; when a small entry is retained, soft thresholding additionally pulls it toward zero. The reduced variability can be useful when the sample noise is substantial, but the cost is potential bias. There is no general ordering of hard and soft variances at every nonzero \(\theta\): the exact comparison depends on \(\theta,\tau,\lambda\).

For a large positive signal relative to the noise and threshold, hard thresholding is almost always in its retain region and then equals \(Y\). Its bias approaches zero and its variance approaches \(\tau^2\). Soft thresholding is also almost always retained, but then equals \(Y-\lambda\); its bias approaches \(-\lambda\) and its variance approaches \(\tau^2\). For a large negative signal, the corresponding soft-threshold bias approaches \(+\lambda\). Thus hard thresholding avoids shrinkage bias on retained large entries, while soft thresholding continues to shrink them.

Worked Example: Variance at a Zero Entry

Let \(\theta=0\), \(\tau=0.10\), and \(\lambda=0.20\), so \(Y=0.10Z\) for \(Z\sim N(0,1)\) and the standardized cutoff is \(c=2\). Both estimators have mean zero. For hard thresholding,

$$ \operatorname{Var}(H_\lambda(Y)) =0.10^2 E[Z^2\mathbf{1}\{|Z|>2\}] =0.01\cdot 2\{2\phi(2)+1-\Phi(2)\}. $$

Using \(\phi(2)\approx0.05399097\) and \(1-\Phi(2)\approx0.02275013\), the bracketed expression is \(2\{0.10798194+0.02275013\}=0.26146414\), so the variance is approximately \(0.00261464\).

For soft thresholding,

$$ \operatorname{Var}(T_\lambda(Y)) =0.01\cdot 2\int_2^\infty (z-2)^2\phi(z)\,dz =0.02\{(1+2^2)[1-\Phi(2)]-2\phi(2)\}. $$

The integral identity follows by expanding \((z-2)^2\) and using the normal tail moments above. Using the displayed rounded inputs, the expression in braces is \(5(0.02275013)-0.10798194=0.11375065-0.10798194=0.00576871\). Thus the soft-threshold variance is approximately \(0.000115374\). In this zero-entry example, soft thresholding has much lower variance; both estimates nevertheless have zero bias at \(\theta=0\).

Worked Example: A Retained Large Entry

Suppose an off-diagonal sample covariance is \(Y=0.58\), the threshold is \(\lambda=0.20\), and the population entry used for comparison is \(\theta=0.60\). Since \(0.58>0.20\), hard thresholding gives \(H_{0.20}(Y)=0.58\). Its realized error relative to \(\theta\) is \(0.58-0.60=-0.02\).

Soft thresholding gives \(T_{0.20}(Y)=0.58-0.20=0.38\), with realized error \(0.38-0.60=-0.22\). These are errors for this particular observed value, not expected biases. Across repeated observations, the Gaussian calculation describes the expected bias; for a signal far above the threshold, hard thresholding's bias approaches zero while soft thresholding's approaches \(-0.20\).

Practical Interpretation and a Common Pitfall

The choice between the rules is a choice about what to do with retained entries. Hard thresholding gives an exact zero pattern while leaving retained estimates unchanged. Soft thresholding gives the same zeroing behavior below the threshold, but applies continuous shrinkage to every retained entry. Near zero, either rule can remove genuine weak covariance; at large magnitudes, soft thresholding can retain a persistent bias. These trade-offs explain why the threshold is part of the estimator, not merely a cosmetic display setting.

  • Pitfall: calling the retained soft-thresholded entry unbiased because it is nonzero. For example, \(0.58\) becomes \(0.38\) at threshold \(0.20\). Conditional on being retained, its value has been shifted toward zero. Moreover, conditioning on retention changes the distribution of the observation, so the conditional bias is not simply the unconditional Gaussian bias formula.
  • Correction: distinguish the rule's output for one observed entry from its expectation across repeated samples. Use \(E[\hat\sigma_{jk}]-\sigma_{jk}\) for bias and \(\operatorname{Var}(\hat\sigma_{jk})\) for variance; neither is determined by a single thresholded matrix.

Finally, symmetry is preserved by applying the same threshold to \(S_{jk}\) and \(S_{kj}\), but positive semidefiniteness is not guaranteed. An entrywise thresholded matrix therefore need not itself be a valid covariance matrix. Thresholding is an entrywise sparsification operation, not a general guarantee of every matrix constraint.

Check Your Understanding

Work through these questions using the definitions and derivations above.

  1. For \(s=-0.37\) and \(\lambda=0.15\), calculate the hard- and soft-thresholded values.
  2. Why does hard thresholding choose zero at \(|s|=\lambda\) under the convention used here?
  3. In the Gaussian entry-noise model, what are the bias and variance of either thresholded estimate when \(\theta=0\)?
  4. For a large positive \(\theta\), what do the hard- and soft-thresholding biases approach, with \(\lambda\) fixed?
  5. Why does symmetry of a thresholded covariance matrix not by itself imply positive semidefiniteness?
Clinical Biostats