---
title: Central Moment Discrepancy (CMD)
url: https://www.emergentmind.com/topics/central-moment-discrepancy-cmd
type: topic
---

# Central Moment Discrepancy (CMD)

Central Moment Discrepancy (CMD) is a theoretically grounded metric for quantifying and minimizing differences between probability distributions by explicitly aligning their central moments up to a prescribed order. Developed to address the challenge of domain-invariant representation learning in neural networks, CMD has proven effective in unsupervised domain adaptation and, by extension, in neural style transfer. The central principle is to exploit the statistical informativeness of higher-order centralized moments to better enforce distributional alignment, enabling robust transfer across domains and more faithful representation matching in learning systems [1702.08811, 2103.07208].

## 1. Formal Definition and Theoretical Foundations

Let $P$ and $Q$ be probability distributions on the compact cube $[a,b]^N$, and let $X \sim P$, $Y \sim Q$. For a truncation order $K \geq 2$, the $k$-th central moment vector of $X$ is defined coordinate-wise as
$$
c_k(P) = \Bigl(E[(X_j - E[X_j])^k]\Bigr)_{j=1}^N \in \mathbb{R}^N,
$$
where $E[X] = (E[X_1], ... , E[X_N])$.

The empirical Central Moment Discrepancy up to order $K$ between samples $X = \{x_i\}_{i=1}^n$ and $Y = \{y_j\}_{j=1}^m$ is
$$
\mathrm{CMD}_K(X, Y) = \frac{1}{|b - a|} \|\mu_X - \mu_Y\|_2 + \sum_{k=2}^{K} \frac{1}{|b-a|^k} \|c_k(X) - c_k(Y)\|_2,
$$
where
$$
\mu_X = \frac{1}{n}\sum_{i=1}^n x_i,\quad c_k(X) = \frac{1}{n} \sum_{i=1}^n (x_i - \mu_X)^k.
$$

In the context of general compactly supported distributions on $\mathbb{R}^m$ and weights $a_i \geq 0$, a more general "primal" form is stated as
$$
\mathrm{CMD}_K(P, Q) = \sum_{i=1}^K a_i \| c_i(P) - c_i(Q) \|_2,
$$
with $c_1(P) = E_{X\sim P}[X]$ and, for $i\geq 2$, $c_i(P) = E_{X\sim P}[ \eta^{(i)}(X - \mu_P) ]$, where $\eta^{(i)}(\cdot)$ denotes all monomials of total degree $i$ in the components [2103.07208].

CMD possesses key metric properties: it is nonnegative, symmetric, satisfies the triangle inequality, and the condition $\mathrm{CMD}(P, Q) = 0 \implies P = Q$ on compact supports. Furthermore, convergence with respect to CMD entails convergence in distribution, as agreement in all centralized moments on a compact set uniquely determines the distribution [1702.08811].

## 2. Algorithmic Implementation

CMD is designed for efficient mini-batch computation within neural network training pipelines. For domain adaptation, in each iteration with hidden activations $A_S \in \mathbb{R}^{B\times N}$ and $A_T \in \mathbb{R}^{B\times N}$ from source and target domains, respectively, the following pseudo-code computes $\mathrm{CMD}_K$:

```python
function CMD_K(A_S, A_T, K, a, b):
    mu_S = mean(A_S, axis=0)
    mu_T = mean(A_T, axis=0)
    d = ||mu_S - mu_T||_2 / (b-a)
    for k in 2..K:
        cS = mean((A_S - mu_S)**k, axis=0)  # elementwise power
        cT = mean((A_T - mu_T)**k, axis=0)
        d += ||cS - cT||_2 / (b-a)**k
    return d
```
The computed quantity is then scaled by a penalty $\lambda$ and added to the task-specific loss (e.g., cross-entropy). All operations are differentiable and incur linear complexity $O(B N K)$ per batch [1702.08811].

For neural style transfer on convolutional feature maps, CMD is computed between feature activations $F_o$ and $F_s$ from output and style images, channel-wise and up to order $K$, ensuring activations reside in a known range via, e.g., sigmoid nonlinearity [2103.07208].

## 3. Comparison with Other Distribution Matching Methods

CMD is specifically contrasted with Maximum Mean Discrepancy (MMD) and other moment-matching methods:

| Method          | Statistic / Moments Matched      | Computational Cost      | Kernel/Bandwidth Needed |
|-----------------|----------------------------------|------------------------|-------------------------|
| CMD             | All central moments up to $K$    | $O(BNK)$ (linear)      | None                    |
| MMD (Gaussian)  | Weighted moment sums/all orders  | $O(B^2)$ (quadratic)   | Yes ($\beta$)           |
| Gram matrix     | Non-central second moment        | $O(n_l C_l^2)$ per layer | None                 |
| AdaIN, MM       | Mean and covariance only         | $O(n_l C_l^2)$         | None                    |
| OT (Gaussian)   | Mean and covariance              | $O(C_l^3)$ (or cubic)  | None                    |

CMD explicitly matches each moment up to order $K$, avoiding kernel selection and expensive Gram matrix operations. MMD, by contrast, requires careful tuning of kernel bandwidth and involves quadratic complexity in sample size. Gram-based methods and AdaIN only match first and second moments, leaving higher-order characteristics unconstrained. CMD’s explicit moment-order matching provides more complete alignment in practice and theory [1702.08811, 2103.07208].

## 4. Empirical Performance and Applications

CMD has been empirically validated in unsupervised domain adaptation and neural style transfer. 

- **Office Dataset:** With VGG16 features and a 256 neuron adaptation layer, CMD ($K = 5$, $\lambda = 1$) achieves 79.9% accuracy, outperforming fine-tuned VGG16 (75.5%) and AdaBN (76.7%), exceeding all prior methods on 4/6 tasks and matching on the remaining two.
- **Amazon Reviews Dataset:** CMD achieves 79.8% mean classification accuracy ($K = 5$, $\lambda = 1$), compared to 78.1% for MMD and 75.2% for the source-only baseline, reaching the state of the art on 9/12 adaptation tasks [1702.08811].
- **Neural Style Transfer:** CMD-based losses, implemented via the dual or primal form, yielded stylizations rated preferable over methods such as AdaIN, Gram/MMD, MM, OST, and WCT in user studies (CMD-based transfer chosen in 21.7% of cases, highest among six methods). Ablation studies attribute improved texture and color reproduction to explicit matching of higher moments up to $K=5$ [2103.07208].

CMD is also noted for computational efficiency; with $K = 5$, overhead is minor compared to classical Gatys implementations, while OT and other methods incur higher costs per iteration.

## 5. Metric and Convergence Properties

CMD is a metric on the space of probability distributions supported on a compact interval. The condition $\mathrm{CMD}(P, Q) = 0$ implies $P = Q$, as all central moments agree and moment sequences determine the distribution on compact supports. CMD metrizes weak convergence: if $\mathrm{CMD}(P_n, P) \to 0$, then $P_n \xrightarrow{d} P$ holds. This metric property distinguishes CMD from non-characteristic kernels (such as the quadratic Gram in MMD), ensuring that empirical minimization of CMD yields convergent distributional alignment [1702.08811].

In the context of polynomial integral-probability metrics (IPMs), CMD corresponds to maximizing the difference of expectations over the class of polynomial test functions up to degree $K$, fully characterized by their central moments. As $K \to \infty$, CMD metrizes convergence on compact sets [2103.07208].

## 6. Practical Hyperparameter Selection and Sensitivity

CMD requires minimal hyperparameter tuning. Recommendations derived from empirical sensitivity analyses include:

- Set $K = 5$ to incorporate mean, variance, skewness, kurtosis, and a fifth-order shape descriptor, capturing essential distributional features.
- Default $\lambda = 1$ balances CMD and task loss.
- Reducing $K$ to $3$ yields $\sim98\%$ of peak performance in domain adaptation.
- CMD displays stable performance for $K \in \{3, 4, 5, 6, 7\}$ (accuracy fluctuates by less than 0.5%) and for $\lambda$ in $[0.3, 3]$ [1702.08811].
- Ensure all activations to be matched are bounded within a known range $[a, b]$—typically by using activation functions such as $\tanh$ or a sigmoid, to correctly normalize each term via $|b - a|^k$.

In neural style transfer, elementwise sigmoid ensures feature activations remain in $[0,1]$, simplifying the normalization for CMD and stabilizing computation [2103.07208].

## 7. Application-Specific Contexts and Limitations

CMD is broadly applicable in tasks requiring precise distribution alignment in feature space. In domain-adaptive neural networks, CMD functions as a robust regularizer by reducing discrepancies between hidden activations of source and target domains. In neural style transfer, CMD is preferred for more faithfully capturing complex style elements by matching higher-order statistics beyond means and variances. Empirical studies demonstrate that odd moments control brightness/contrast, even moments govern texture and color, and higher moments further enrich stylization. A plausible implication is that matching further moments (higher $K$) could support even more granular control over distributional alignment, though with diminishing returns beyond $K=5$ in typical tasks.

CMD is most naturally applied to distributions on compact sets; ensuring boundedness of input features or activations is critical to preserve theoretical properties and normalization. CMD does not require kernel tuning or expensive matrix computations, but for very high-dimensional settings, the computation of higher-order moments may become more costly, especially if full multivariate moments are included rather than marginal powers.

---

Central Moment Discrepancy constitutes a metric, theoretically justified approach for aligning finite sets of central moments in empirical learning systems, outperforming classical moment-matching methods in tasks including domain adaptation and neural style transfer, while maintaining practical tractability and minimal reliance on hyperparameter tuning [1702.08811, 2103.07208].

Source: https://www.emergentmind.com/topics/central-moment-discrepancy-cmd