# Consistent order estimation for nonparametric Hidden Markov Models

Luc Lehéricy

<figure><img src="image_1.png" /></figure>

To cite this version:

Luc Lehéricy. Consistent order estimation for nonparametric Hidden Markov Models. 2017. hal-01321039v3

HAL Id: hal-01321039

https://hal.science/hal-01321039v3

Preprint submitted on 6 Apr 2017

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>

Distributed under a Creative Commons Attribution - ShareAlike 4.0 International License
# Consistent order estimation for nonparametric
# Hidden Markov Models

LUC LEHÉRICY

Laboratoire de Mathématiques d'Orsay, Univ. Paris-Sud, CNRS, Université Paris-Saclay,
91405 Orsay, France. E-mail: luc.lehericy@math.u-psud.fr

We consider the problem of estimating the number of hidden states (the *order*) of a nonparametric hidden Markov model (HMM). We propose two different methods and prove their almost sure consistency without any prior assumption, be it on the order or on the emission distributions. This is the first time a consistency result is proved in such a general setting without using restrictive assumptions such as a *priori* upper bounds on the order or parametric restrictions on the emission distributions. Our main method relies on the minimization of a penalized least squares criterion. In addition to the consistency of the order estimation, we also prove that this method yields rate minimax adaptive estimators of the parameters of the HMM - up to a logarithmic factor. Our second method relies on estimating the rank of a matrix obtained from the distribution of two consecutive observations. Finally, numerical experiments are used to compare both methods and study their ability to select the right order in several situations.

MSC 2010 subject classifications: Primary 62F07; secondary 62M05, 62M15, 62G05.

Keywords: hidden Markov model, least squares method, model selection, nonparametric density estimation, order estimation, spectral method.

# 1. Introduction

## 1.1. Context and motivation

Hidden Markov models (HMM in short) are powerful tools to study time-evolving processes on heterogeneous populations. Nonparametric HMMs—that is, hidden Markov models where the parameters are not restricted to a finite-dimensional space—have proved useful in a wide range of applications, see for instance Couvreur and Couvreur (2000) for voice activity detection, Lambert, Whiting and Metcalfe (2003) for climate state identification, Lefèvre (2003) for automatic speech recognition, Shang and Chan (2009) for facial expression recognition, Volant et al. (2014) for methylation comparison of proteins, Yau et al. (2011) for copy number variants identification in DNA analysis.

In practice, the hidden states often have an interpretation in the modelling of the phenomenon. It is thus important to be able to infer the right order in addition to the parameters when dealing with hidden Markov models. However, this task is notoriously difficult: Gassiat and Keribin (2000) show that the likelihood ratio statistic is unbounded even in the simple case where one wants to test if a HMM has 1 or 2 hidden states. As far
as we know, no consistency result has been proved about order selection for nonparametric HMMs. Even for parametric HMMs, no estimator has been proved to be consistent in a general setting without assuming that an *a priori* upper bound on the order is known beforehand.

Not only is the order estimation useful in order to interpret the model, it is also necessary to ensure stability. This is because over estimating the order causes a loss of identifiability: there are several ways to add one state to a HMM without changing anything to its distribution. The spectral estimators (Anandkumar, Hsu and Kakade (2012); de Castro, Gassiat and Le Corff) are especially sensitive to this problem, as shown by Lehéricy (2015) and Figure 6: as soon as the HMM becomes close to a HMM with fewer hidden states, the estimators give absurd results. Thus, estimating the right order is crucial for such methods to be effective.

Formally, a hidden Markov model is a markovian process $(X_t, Y_t)_{t \ge 1}$ taking value in $\mathcal{X} \times \mathcal{Y}$. $(X_t)_{t \ge 1}$ is a Markov chain and the observations $Y_t$ depend only on the associated $X_t$ (i.e. the $(Y_t)_{t \ge 1}$ are independent conditionally on $(X_t)_{t \ge 1}$). The states $(X_t)_{t \ge 1}$ are assumed to be hidden, so that one has only access to the observations $(Y_t)_{t \ge 1}$. When the number of hidden states $|\mathcal{X}|$ (which we call the *order* of the HMM) is finite, the model is completely defined by its order, the initial distribution and the transition matrix of the hidden Markov chain, and the possible distributions of an observation $Y_t$ conditionally to the values of its hidden state $X_t$, which we call the *emission distributions*. The goal of the estimation procedures is to recover these parameters by using only the observations $(Y_t)_{t \ge 1}$.

Up to now, most theoretical results on hidden Markov models dealt with the parametric frame, that is with a finite number of parameters. However, it is not always possible to restrict the model to such a convenient finite-dimensional space. Theoretical results in the nonparametric framework were only developed recently and do not address the order estimation problem. de Castro, Gassiat and Lacour (2016) propose an adaptive quasi-rate minimax least squares method. de Castro, Gassiat and Le Corff and Robin, Bonhomme and Jochmans (2014) study spectral methods. The latter is also proved to reach the minimax convergence rate but is not adaptive: it requires the regularity of the emission distributions to be known. All these methods require the order of the HMM to be known.

Our work is novel on three points. First, it deals with the nonparametric setting: we need no parametric or regularity assumption on the emission densities. Note that all our results also apply to parametric settings or even to finite observation spaces, since these are just special cases of nonparametric estimation. Secondly, we do not require any *a priori* upper bound on the order, an assumption that is often made in earlier works, both frequentist and bayesian. Finally, our least squares method yields estimators of all model parameters at the same time, without requiring any prior information. Oracle inequalities show that these estimators are rate minimax adaptive up to a logarithmic factor.
## 1.2. Related works

The first step to obtain theoretical results was to understand when hidden Markov models are identifiable. This challenging issue was only solved a few years ago, see Gassiat, Cleynen and Robin (2015) (following Allman, Matias and Rhodes (2009) and Hsu, Kakade and Zhang (2012)) and with weaker assumptions Alexandrovich and Holzmann (2014). Both proved that under generic assumptions, the parameters of the HMM can be recovered from the distribution of a finite number of consecutive observations, thus paving the way for guarantees on parameter estimation.

HMM inference is generally decomposed in two parts. The first one is the estimation of the order, and the second one is the estimation of the parameters once the order is known.

From a theoretical point of view, the order estimation problem remains widely open in the HMM framework. One can distinguish two kinds of results. The first kind does not need an *a priori* upper bound on the order, but is only applicable to restrictive cases. For instance, using tools from coding theory, Gassiat and Boucheron (2003) introduced a penalized maximum likelihood order estimator for which they prove strong consistency without *a priori* upper bound on the order of the HMM. Nevertheless, their result is restricted to a finite observation space and they have to use heavy penalties that grow as a power of the order. For the special case of Gaussian or Poisson emission distributions, Chambaz, Garivier and Gassiat (2009) showed that the penalized maximum likelihood estimator is strongly consistent without any *a priori* upper bound on the order. The second kind of results is more general but requires an *a priori* upper bound of the order just to get weak consistency of order estimators, for penalized likelihood criterion (Gassiat (2002)) as well as Bayesian approaches (Gassiat and Rousseau (2014); van Havre et al. (2016)).

On a practical side, several order estimation methods using penalized likelihood criterion have been studied numerically, see for instance Volant et al. (2014) when emission distributions are a mixture of parametric densities or Celeux and Durand (2008) for parametric HMMs. The latter also introduced cross-validation procedures that aimed for circumventing the lack of independance of the observations. In the case of nonparametric HMMs, Langrock et al. (2015) studied a method using P-splines with a custom penalization.

Then comes the question of estimating the parameters of the HMM once its order is known. In the parametric setting, the asymptotic behaviour of the maximum likelihood estimator is rather well understood (see for instance Bickel et al. (1998) or Douc et al. (2004) using techniques from Le Gland and Mevel (2000)), but so far the question of its nonasymptotic behaviour remains open. Hsu, Kakade and Zhang (2012) and Anandkumar, Hsu and Kakade (2012) proposed a spectral method for parametric HMMs based on joint diagonalization of a set of matrices and controlled its nonasymptotic error. Robin, Bonhomme and Jochmans (2014) and de Castro, Gassiat and Le Corff extended this method to the nonparametric setting, and de Castro, Gassiat and Lacour (2016) used the latter to obtain an estimator of the transition matrix of the hidden chain for a quasi-rate minimax adaptive least squares estimator of the emission densities. Our least
squares estimation method is a generalization of their procedure that is able to deal with all parameters at once and does not require auxiliary estimators.

## 1.3. Contribution

The aim of our paper is twofold. Firstly, we introduce two estimators of the order for nonparametric HMMs and show that both converge almost surely to the right order under minimal assumptions. Secondly, we numerically assess their ability to select the right order and compare their efficiency.

Our first and main method is the penalized least squares estimator. This method is based on estimating the projection of the emission distributions onto a family of nested parametric subspaces. Our results hold for any Hilbert space, including parametric sets of emission densities and finite observation spaces. Then, for each subspace and for each possible value $K$ of the order, we look for the HMM with $K$ hidden states and with emission distributions in the chosen subspace that matches the observations “best”-where “best” means minimizing the empirical equivalent of an $L^2$ distance. This step provides an empirical distance between the observations and the model, which is then penalized in order to counterbalance the overfitting phenomenon that occurs when considering large models. Our first main result is that for a suitable choice of the penalty, choosing the model (i.e. the order and the subspace) which minimizes this penalized distance leads to a strongly consistent estimator of the order, see Corollary 5.

In addition, this method also provides estimators of the other parameters of the HMM for free, by taking the parameters of the HMM corresponding to the selected model. We prove an oracle inequality on the $L^2$ risk of these estimators, which shows that they achieve the minimax adaptive rate of convergence, up to a logarithmic term, see Theorem 10 and Corollary 11.

Our second estimator comes from spectral methods. Just like for our least squares procedure, we consider a nested family of parametric subspaces of a Hilbert space. Let us choose one of them, and denote by $(\varphi_a)_a$ an orthonormal basis of this subspace. Then, consider the matrix $N$ defined by

$$N(a, b) := \mathbb{E}[\varphi_a(Y_1)\varphi_b(Y_2)].$$

This matrix contains the coordinates of the density of $(Y_1, Y_2)$ in the orthonormal basis $(\varphi_a \otimes \varphi_b)_{a,b}$. It is proved in Section 4 that the rank of $N$ is exactly equal to the order of the HMM as soon as the subspace is large enough. Therefore, finding its rank means finding the number of hidden states. However, in practice, one only has access to an empirical version of this matrix. The difficulty comes from the fact that this noisy version will almost surely have full rank. Thus, the key point is to recover the order of the true matrix given its empirical (full rank) counterpart. We achieve this by thresholding the spectrum of the empirical matrix. Notice that other methods exist to estimate the rank of a matrix based on a noisy observation, see for instance Kleibergen and Paap (2006) and references therein. Unfortunately, most can not be applied directly to our setting since
they require an invertibility condition on the covariance matrix of the matrix entries. The CRT statistics from Robin and Smith (2000) is a notable exception, however their test of rank also requires the tuning of an unknown parameter in order to be weakly consistent.

Then, we run an implementation of these two methods and compare their efficiency on simulated data. The difficulty at this stage comes from the fact that both method involve an unknown tuning parameter. This is a common issue that appears in every model selection method in one form or another, and many heuristics have been proposed to circumvent this difficulty.

For the least squares estimator, we compare two methods which have been both proved to be theoretically valid in simple cases and empirically validated in a large variety of situations: the slope heuristics (see for instance Baudry, Maugis and Michel (2012) and references therein) and the dimension jump heuristics (introduced and proved to lead to an optimal penalization in the gaussian model selection framework by Birgé and Massart (2007)). Both behave well with our estimator and lead to a satisfying calibration of the penalty.

For the spectral estimator, we introduce a custom heuristics based on the fact that the smallest singular values of the empirical version of the matrix $N$ decrease in a simple manner. It is thus possible to calibrate an entirely data-driven threshold to distinguish “significant” singular values—that is, the ones corresponding to non-zero singular values of the real $N$-from noise.

The numerical validation shows that our least squares method performs well in almost any situation. It is able to select the right order accurately with notably fewer observations than the spectral estimator, and is easier to calibrate. On the other hand, the spectral method is very fast, which allows to take more observations into account. This allows to obtain satisfying estimators in a short amount of time.

Regarding the inference of the other parameters, our least squares estimator offers several advantages when compared to previous methods. First, it does not need a preliminary estimation of the transition matrix or of the order, unlike de Castro, Gassiat and Lacour (2016) who used the transition matrix given by spectral estimators. Nevertheless, our method still reaches the adaptive minimax convergence rate for the estimation of the emission densities, up to a logarithmic factor. This is especially useful to avoid the cases where their auxiliary estimator fails. For instance, the spectral method that de Castro, Gassiat and Lacour (2016) used is unreliable when the order is over estimated or where the states are almost linearly dependent, see for instance Lehéricy (2015) or Figure 6. Then, our least squares method is robust to an overestimation of the order, both theoretically and numerically, thanks to the iterative initialization procedure that we introduce. This initialization method consists in using estimators from smaller models as initial point for the minimization algorithm in order to avoid getting stuck in suboptimal local extrema. We believe it can be of practical interest since it produces robust estimators and can also be used in other settings, for instance as initialization for expectation maximization algorithm for maximum likelihood estimators.
## 1.4. Outline of the paper

Our paper is organized as follows.

Section 2 is devoted to the notations, the model and the assumptions.

Our main procedure, the penalized least squares method, is introduced in Section 3. We first state an identifiability proposition which we use to prove strong consistency of the estimator of the order. This is done in two steps. Firstly, we control the probability to underestimate the order. This is done thanks to Proposition 1, and gives an exponential bound on the probability of error, see Theorem 3. Secondly, we control the probability to overestimate the order, see Theorem 4. For this, we introduce a general condition on the penalty, which we use to prove polynomial decrease rate, and illustrate how to easily satisfy this condition. Finally, we state oracle inequalities on the estimators of the density of L consecutive observations and on the parameters of the hidden Markov model under a generic assumption, see Theorem 10 and Corollary 11, which shows that they reach the minimax convergence rate up to a logarithmic factor.

In Section 4, we introduce the spectral algorithm and propose a strongly consistent estimator of the order. This is done by thresholding the spectrum of the empirical version of the matrix $N$, which describes the projection of the distribution of two observations on an orthonormal basis, see Theorem 13.

In Section 5, we propose practical algorithms to apply both methods and compare them. Firstly, we set the parameters on which we will test both procedures. Secondly, we compare their results and discuss their performance. Lastly, we introduce and discuss the heuristics we used to practically implement both methods.

Our main technical result, Lemma 16, can be found at the beginning of Section 6. It is used extensively for both the consistency of the estimator of the order and the oracle inequalities on the HMM parameters. The rest of this section is dedicated to the proofs of the results.

Appendix A of our supplementary material contains the spectral algorithm from de Castro, Gassiat and Le Corff and de Castro, Gassiat and Lacour (2016) that we use in our simulations. Appendix B gathers the proofs of Section 3.4, which deals with the oracle inequalities for the least squares method. Finally, Appendix C contains the proof of Lemma 16, and Appendix D contains miscellaneous lemmas and proofs.

## 2. Definitions and assumptions

We will use the following notations throughout the paper.

* $\mathbb{N}^* = \{1, 2, \dots\}$ is the set of positive integers.

* For $k \in \mathbb{N}^*$, $[k]$ is the set $\{1, \dots, k\}$.

* If $f_1$ and $f_2$ are two functions, we denote by $f_1 \otimes f_2$ their tensor product, defined by $f_1 \otimes f_2(x_1, x_2) = f_1(x_1)f_2(x_2)$.

* $\text{Span}(a)$ is the linear space spanned by the family $a$.
* If $E_1$ and $E_2$ are two linear spaces, we denote by $E_1 \otimes E_2$ their tensor product, that is the linear space spanned by the tensor products of their elements: $E_1 \otimes E_2 = \text{Span}(f_1 \otimes f_2 | f_1 \in E_1, f_2 \in E_2)$.

* $\Delta_K = \{\pi \in [0, 1]^K | \sum_{k=1}^K \pi_k = 1\}$ is the simplex in dimension $K$. It will be seen as the set of probability measures on a finite set of size $K$.

* $Q_K \subset \mathbb{R}^{K \times K}$ is the set of irreducible transition matrices of size $K$.

* $\text{Id}_K$ is the identity matrix of size $K$.

* $\mathbf{L}^2(A, \nu)$ is the Hilbert space of square integrable functions on $A$ with respect to the measure $\nu$.

* The notation $C \equiv C(a, b, \dots)$ for a constant $C$ will mean that the value of $C$ depends on the specified parameters $a, b, \dots$. For several constants depending on the same parameters, we will write $(C, D) \equiv (C, D)(a, b, \dots)$.

In the following, $L$ is a positive integer which will denote the number of consecutive observations used for the estimation procedure.

## 2.1. Hidden Markov models

Let $(X_j)_{j \ge 1}$ be a Markov chain with finite state space $\mathcal{X}$ of size $K^*$ with transition matrix $\mathbf{Q}^*$ and initial distribution $\pi^*$. Without loss of generality, we can set $\mathcal{X} = [K^*]$.

Let $(Y_j)_{j \ge 1}$ be random variables on a measured space $(\mathcal{Y}, \mu)$ with $\mu$-finite such that conditionally on $(X_j)_{j \ge 1}$ the $Y_j$'s are independent with a distribution depending only on $X_j$. Let $\nu_k^*$ be the distribution of $Y_j$ conditionally to $\{X_j = k\}$. Assume that $\nu_k^*$ has density $f_k^* \in \mathbf{L}^2(\mathcal{Y}, \mu)$ with respect to $\mu$. We call $(\nu_k^*)_{k \in \mathcal{X}}$ the emission distributions and $\mathbf{f}^* = (f_1^*, \dots, f_{K^*}^*)$ the emission densities.

Then $(X_j, Y_j)_{j \ge 1}$ is a hidden Markov model with parameters $(\pi^*, \mathbf{Q}^*, \mathbf{f}^*, K^*)$. The hidden chain $(X_j)_{j \ge 1}$ is assumed to be unknown, so that the estimator only has access to the observations $(Y_j)_{j \ge 1}$.

For $K \in \mathbb{N}^*$, $\pi \in \mathbb{R}^K$, $\mathbf{Q} \in \mathbb{R}^{K \times K}$ and $\mathbf{f} \in (\mathbf{L}^2(\mathcal{Y}, \mu))^K$, let

$$g^{\pi, \mathbf{Q}, \mathbf{f}, K} = \sum_{k_1, \dots, k_L = 1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \otimes_{i=1}^{L} f_{k_i}.$$

When $\pi$ is a probability distribution on $[K]$, $\mathbf{Q}$ a $K \times K$ transition matrix and $\mathbf{f}$ a $K$-uple of probability densities, $g^{\pi, \mathbf{Q}, \mathbf{f}, K}$ is the density of the first $L$ observations of a HMM with parameters $(\pi, \mathbf{Q}, \mathbf{f}, K)$.

For the sake of readability, we will drop the dependence in $K$ in the following and write $g^{\pi, \mathbf{Q}, \mathbf{f}}$ instead of $g^{\pi, \mathbf{Q}, \mathbf{f}, K}$. Moreover, if $\mathbf{Q}$ is irreducible with stationary distribution $\pi$, we simply write $g^{\mathbf{Q}, \mathbf{f}}$, and we write the true density $g^* := g^{\pi^*, \mathbf{Q}^*, \mathbf{f}^*}$.

## 2.2. Assumptions

Let $\mathcal{F}$ be a subset of $\mathbf{L}^2(\mathcal{Y}, \mu)$ and $(\mathfrak{P}_M)_{M \in \mathcal{M} \subset \mathbb{N}}$ be a sequence of nested subspaces of $\mathbf{L}^2(\mathcal{Y}, \mu)$ such that $\mathfrak{P}_M$ has dimension $M$ for all $M \in \mathcal{M}$ and their union is dense
in $L^2(Y, \mu)$. $(\mathfrak{P}_M)_{M \in \mathcal{M}}$ will be the subspaces on which the projections of the emission densities will be estimated.

We will need the following assumptions.

[HX] $(X_k)_{k \ge 1}$ is a stationary ergodic Markov chain with parameters $(\pi^*, \mathbf{Q}^*)$;

[HidA] $\mathbf{Q}^*$ is invertible, $L \ge 3$ and the family $\mathbf{f}^*$ is linearly independent;

[HidB] $\mathbf{Q}^*$ is invertible, $L \ge (2K^*+1)((K^*)^2 - 2K^*+2)+1$ and the emission densities $(f_k^*)_{k \in \mathcal{X}}$ are all distinct;

[HF] $\mathbf{f}^* \in \mathcal{F}^{K^*}$, $\mathcal{F}$ is closed under projection on $\mathfrak{P}_M$ for all $M$ and

$$ \forall f \in \mathcal{F}, \quad \begin{cases} \|f\|_{\infty} \le C_{\mathcal{F},\infty} \\ \|f\|_{2} \le C_{\mathcal{F},2} \end{cases} $$

with $C_{\mathcal{F},\infty}$ and $C_{\mathcal{F},2}$ larger than 1.

The ergodicity assumption in [HX] is completely standard in order to obtain convergence results. In this case, the initial distribution is forgotten exponentially fast, so that the HMM will essentially behave like a stationary process. In order to simplify the proofs, we assume the Markov chain to be stationary. One can check that our results are essentially the same when the initial distribution is not the stationary one.

[HidA] appears in spectral methods, with the hypothesis that $\pi^* > 0$ elementwise, see for instance Hsu, Kakade and Zhang (2012). [HidA] and [HidB] also appear in identifiability issues, possibly combined with the stationarity hypothesis, see Alexandrovich and Holzmann (2014) and Gassiat, Cleynen and Robin (2015). Note that the condition on $L$ in [HidB] only involves the real order $K^*$.

Even though [HidB] appears less restrictive than [HidA] about the emission densities, it is delicate to use here. The problem lies in the condition on the number of consecutive observations $L$. For [HidB], one has to take $L$ larger than an increasing function of the order, so it requires to have an *a priori* upper bound on the order to choose $L$. This is less interesting than [HidA], which can work without prior bound since it only requires $L = 3$ for any value of the order.

# 3. Least squares estimation

In this section, we introduce our penalized least squares estimator and study its asymptotic properties.

## 3.1. Approximation spaces and estimators

We want to estimate the density of $L$ consecutive observations $g^*$ by minimizing the quadratic loss $t \mapsto \|t - g^*\|_2^2 - \|g^*\|_2^2$. We thus take the corresponding empirical loss

$$ \gamma_n(t) = \|t\|_2^2 - \frac{2}{n} \sum_{s=1}^{n} t(Z_s) $$
where $Z_s = (Y_s, \dots, Y_{s+L-1})$ for an observation sequence $(Y_t)_{1 \le t \le n+L-1}$ of length $n+L-1$ coming from a single HMM $(X_t, Y_t)_{t \ge 1}$.

Define for all $K \in \mathbb{N}^*$, $M \in \mathcal{M}$:

$$S_{K,M} := \{g^{\mathbf{Q},\mathbf{f}}, \mathbf{Q} \in \mathcal{Q}_K, \mathbf{f} \in (\mathcal{F} \cap \mathfrak{P}_M)^K\}$$

$$S_K := \{g^{\mathbf{Q},\mathbf{f}}, \mathbf{Q} \in \mathcal{Q}_K, \mathbf{f} \in \mathcal{F}^K\}$$

where $\mathcal{F}$ and $(\mathfrak{P}_M)_{M \in \mathcal{M}}$ are defined in Section 2.2. In the following, we will always implicitly consider $M \in \mathcal{M}$.

For all $K$ and $M$, we define the corresponding estimators

$$\hat{g}_{K,M} = g^{\hat{\mathbf{Q}}_{K,M}, \hat{\mathbf{f}}_{K,M}} \in \arg \min_{t \in S_{K,M}} \gamma_n(t)$$

where we dropped the dependency in $n$ for ease of notation. Then, we select the parameters using the penalized empirical loss:

$$(\hat{K}_{1,s.}, \hat{M}) \in \arg \min_{K \le n, M \le n} \{\gamma_n(\hat{g}_{K,M}) + \text{pen}(n, M, K)\}$$

which leads to the estimators

$$\hat{g} := \hat{g}_{\hat{K}_{1,s.}, \hat{M}}$$

$$\hat{\mathbf{Q}} := \hat{\mathbf{Q}}_{\hat{K}_{1,s.}, \hat{M}}$$

$$\hat{\mathbf{f}} := \hat{\mathbf{f}}_{\hat{K}_{1,s.}, \hat{M}}$$

## 3.2. Underestimation of the order

Note that the distribution of the HMM remains unchanged under permutation of the hidden states. We will therefore use a pseudo-distance $d_{\text{perm}}$ that is invariant by permutation on the set of parameters.

We define it as follows. Let $K \ge 1$, $\pi_1, \pi_2 \in \Delta_K$, $\mathbf{Q}_1$ and $\mathbf{Q}_2$ transition matrices of size $K$, $\mathbf{f}_1, \mathbf{f}_2 \in (\mathbf{L}^2(\mathcal{Y}, \mu))^K$. Let $\mathcal{S}(\mathcal{X})$ be the set of permutations of $\mathcal{X}$. For all $\tau \in \mathcal{S}(\mathcal{X})$, define the swapped parameters $\tau\pi_1$, $\tau\mathbf{Q}_1$ and $\tau\mathbf{f}_1$ by

$$(\tau\pi_1)(k) := \pi_1(\tau(k))$$

$$(\tau\mathbf{Q}_1)(k, l) := \mathbf{Q}_1(\tau(k), \tau(l))$$

$$(\tau\mathbf{f}_1)_k := f_{1,\tau(k)}$$

and finally

$$d_{\text{perm}}((\pi_1, \mathbf{Q}_1, \mathbf{f}_1), (\pi_2, \mathbf{Q}_2, \mathbf{f}_2)) := \inf_{\tau \in \mathcal{S}(\mathcal{X})} \left( \|\tau\pi_1 - \pi_2\|_2^2 + \|\tau\mathbf{Q}_1 - \mathbf{Q}_2\|_F^2 + \sum_{k=1}^K \|(\tau\mathbf{f}_1)_k - f_{2,k}\|_2^2 \right)^{1/2}.$$
The following properties will be of use to prove the consistency of the order estimator, but we think it can also be of independent interest to better understand the identifiability of the model. The first one is a generalization of previous identifiability results from Alexandrovich and Holzmann (2014); Gassiat, Cleynen and Robin (2015); de Castro, Gassiat and Lacour (2016).

**Proposition 1.** Let $K \ge 1$, $\pi \in \Delta_K$ such that $\pi_k > 0$ for all $k \in \mathcal{X}$, $\mathbf{Q}$ transition matrix of size $K$ and $\mathbf{f} \in (\mathbf{L}^2(\mathcal{Y}, \mu))^K$ such that $[\text{HidA}]$ or $[\text{HidB}]$ hold for the order $K$. Then, for all $K' \ge 1$, for all $\pi' \in \Delta_{K'}$, for all transition matrix $\mathbf{Q}'$ of size $K'$ and all $\mathbf{f}' \in (\mathbf{L}^2(\mathcal{Y}, \mu))^{K'}$, the following holds:

$$ (g^{\pi, \mathbf{Q}, \mathbf{f}} = g^{\pi', \mathbf{Q}', \mathbf{f}'}, \text{ and } K' \le K) \qquad \Rightarrow (K = K' \text{ and } d_{\text{perm}}((\pi, \mathbf{Q}, \mathbf{f}), (\pi', \mathbf{Q}', \mathbf{f}')) = 0). $$

**Comment.** This property does not require two assumptions that appear in Alexandrovich and Holzmann (2014) and Gassiat, Cleynen and Robin (2015): that $\mathbf{f}$ is a family of probability densities and that the Markov chain is stationary.

In particular, the fact that $\mathbf{f}$ may not be a family of probability densities is crucial in the proof of Corollary 2, which is necessary to prove the strong consistency of the estimator of the order.

**Proof.** Assume $[\text{HidA}]$. The spectral algorithm from de Castro, Gassiat and Le Corff applied on the linear space spanned by both sets of densities allows to retrieve the order from two consecutive observations and the parameters from three consecutive observations. Their proof works when the emission densities are not probability densities and when the chain is not stationary.

Assume $[\text{HidB}]$. A careful reading of the proofs of Alexandrovich and Holzmann (2014) shows that their result can be extended to general observation spaces and do not require the measures to be probabilities. $\square$

The second property is the following corollary, which states that the $\mathbf{L}^2$ distance between the actual model and the models where the order is underestimated is positive. It is worth noting that we do not need $\mathcal{F}$ to be compact.

**Corollary 2.** Assume $[\text{HX}]$, $([\text{HidA}]$ or $[\text{HidB}])$ and $[\text{HF}]$ hold. Then, for all $K < K^*$:

$$ d_K := \inf_{t \in S_K} \|t - g^*\|_2 > 0 $$

**Proof.** Proof in Section 6.2.1. $\square$

<figure><img src="image_3.png" /></figure>

Our first theorem shows that the probability to underestimate the order decreases exponentially with the number of observations. This comes from Corollary 2: since the empirical criterion converges to the $\mathbf{L}^2$ distance (plus some constant that does not depend
on the model), the penalized error will eventually become larger for orders under $K^*$ than for orders over $K^*$, which means that we won't underestimate the real order. The exponential decrease rate brings to mind the one studied in Gassiat and Boucheron (2003): in both cases, the exponents involve the distance between the actual model and models with underestimated orders, as can be seen in our proof.

**Theorem 3.** Assume [HX], ([HidA] or [HidB]) and [HF] hold. There exists positive constants $\rho \equiv \rho(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ and $\beta \equiv \beta(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, (d_K)_{K<K^*}, L)$ such that the following holds.

Assume that

$$ \forall n, \forall M, \forall K, \quad \text{pen}(n, M, K) \geq \rho(MK + K^2 - 1) \frac{\log(n)}{n}, $$

and

$$ \forall M, \forall K, \quad \text{pen}(n, M, K) \xrightarrow{n \to \infty} 0 $$

then there exists $n_0$ such that for all $n \geq n_0$,

$$ \mathbb{P}(\hat{K}_{l.s.} < K^*) \leq e^{-\beta n}. $$

**Proof.** Proof in Section 6.3. □

<figure><img src="image_4.png" /></figure>

### 3.3. Overestimation of the order and consistency

Our second theorem controls the probability to overestimate the order. It consists in overpenalizing large models so that the estimated order remains small.

We will need the following technical condition on the penalty:

**Condition ([Hpen](α, ρ)).** The penalty function pen satisfies

$$ \exists n_1, \forall n \geq n_1, \forall M \leq n, \forall K \leq n \text{ s.t. } K > K^*, $$

$$ \text{pen}(n, M, K) - \text{pen}(n, M, K^*) \geq \rho(MK + K^2 - 1) \frac{\log(n)}{n} + \alpha \frac{\log(n)}{n}, $$

We can now state the theorem and its corollary proving the strong consistency of our estimator of the order. Note that it does not require any identifiability assumption.

**Theorem 4.** Assume [HX] and [HF] hold. There exists positive constants $(\rho, \beta) \equiv (\rho, \beta)(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ such that the following holds.

Assume [Hpen](α, ρ) holds for some $\alpha \geq 0$, then there exists $n_0$ such that for all $n \geq n_0$,

$$ \mathbb{P}(\hat{K}_{l.s.} > K^*) \leq n^{-\beta\alpha}. $$

**Proof.** Proof in Section 6.3. □

<figure><img src="image_5.png" /></figure>
**Corollary 5.** Assume [HX], [HF] and ([HidA] or [HidB]) hold. There exists positive constants $(\rho, \beta) \equiv (\rho, \beta)(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ such that the following holds.

Assume that the penalty function satisfies

$$ \begin{cases} \forall n, \forall M \le n, \forall K \le n, & \text{pen}(n, M, K) \ge \rho(MK + K^2 - 1) \frac{\log(n)}{n} \\ \forall M, \forall K, & \text{pen}(n, M, K) \underset{n \to +\infty}{\longrightarrow} 0 \end{cases} $$

and [Hpen]$(\alpha/\beta, \rho)$ holds for some $\alpha > 1$, then

$$ \mathbb{P}(\hat{K}_{l.s.} \neq K^*) = O(n^{-\alpha}). $$

In particular, $\hat{K}_{l.s.} \to K^*$ almost surely.

Let us comment on the condition [Hpen] when using a penalty of the form $\text{pen}(n, M, K) = C(MK + K^2 - 1) \log(n)/n$ where $C$ may depend on $n$.

* If one has an a priori bound on the order, i.e. if $K^* \le K_0$ for some known $K_0$, then direct computations show that for all $\alpha, \rho$, there exists $C \ge 0$ depending on $K_0$ (for instance, $C = 2\rho(1 + K_0^2 \vee \frac{\alpha}{\rho})$ works) such that [Hpen]$(\alpha, \rho)$ holds for all $K^* \le K_0$ (instead of $K \le n$). This means that if one has an a priori bound $K_0$ on the order, then by taking a constant $C$ large enough and $\hat{K}_{l.s.} \le K_0$, the estimator $\hat{K}_{l.s.} > K^*$ is almost surely consistent.

* If one does not have an a priori bound on $K^*$, taking a constant $C$ does not allow to get [Hpen]$(\alpha, \rho)$ for all possible $K^*$, which means we can't apply Corollary 5. However, by taking $C$ as a sequence indexed by $n$ that tends to infinity, we get that for all $K^*$ and $\alpha, \rho$, [Hpen]$(\alpha, \rho)$ holds. This implies consistency with polynomial decrease of the probability of error, at the cost of overpenalizing.

Overpenalizing is actually necessary if one wants to satisfy [Hpen] for all $K^*$. This is stated in the following proposition:

**Proposition 6.** Let $\rho > 0$ and pen be a positive penalty such that for all $K^*$, [Hpen]$(0, \rho)$ holds, then there exists a sequence $(u_n)_{n \ge 1} \to \infty$ such that for all $n \ge 1$, $M \le n$ and $K \le n$, $\text{pen}(n, M, K) \ge u_n(MK + K^2 - 1) \log(n)/n$.

**Proof.** Proof in Appendix D.1. □

<figure><img src="image_6.png" /></figure>

## 3.4. Oracle inequalities

Our first result for this section is an oracle inequality on the density of $L$ consecutive observations for the least squares estimator.

**Theorem 7.** Assume [HX] and [HF] hold. Then there exists positive constants $(n_0, \rho, A) \equiv (n_0, \rho, A)(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ such that if the penalty satisfies

$$ \forall n, \forall M \le n, \forall K \le n, \quad \text{pen}(n, M, K) \ge \rho(MK + K^2 - 1) \frac{\log(n)}{n} $$
then for all $n \ge n_0$, for all $x > 0$, it holds with probability larger than $1 - e^{-x}$ that

$$ \|\hat{g} - g^*\|_2^2 \le 4 \inf_{K \le n, M \le n} \{\|g_{K,M}^* - g^*\|_2^2 + \text{pen}(n, M, K)\} + 4A \frac{x}{n}. $$

**Proof.** Proof in Section B.1.

<figure><img src="image_7.png" /></figure>

**Comment.** The constant 4 before the infimum can be replaced by any constant $\kappa > 1$, at the cost of changing the constants $n_0$, $\rho$ and $A$.

We would like to deduce an oracle inequality on the parameters of the HMM from this result. Using Cauchy-Schwarz inequality, it is easy to upper bound the error on the density $g^*$ by the error on the parameters: for all probability distributions $\pi_1$ and $\pi_2$ on $[K]$, for all transition matrices $\mathbf{Q}_1$ and $\mathbf{Q}_2$ of size $K$ and for all $\mathbf{f}_1, \mathbf{f}_2 \in \mathcal{F}^K$,

$$ \|g^{\pi_1, \mathbf{Q}_1, \mathbf{f}_1} - g^{\pi_2, \mathbf{Q}_2, \mathbf{f}_2}\|_2 \le C_{\mathcal{F},2}^L \sqrt{LK} d_{\text{perm}}((\pi_1, \mathbf{Q}_1, \mathbf{f}_1), (\pi_2, \mathbf{Q}_2, \mathbf{f}_2)) \quad (1) $$

as soon as [HF] holds. The proof of this equation is detailed in Section B.2.

Thus, all we need to deduce an oracle inequality on the parameters is to lower bound the error on $g^*$ by the error on the parameters. Let $\mathcal{C} \subset \mathbb{R}^{K^*} \times \mathbb{R}^{K^* \times K^*} \times \mathbb{R}^{K^* \times K^*}$ be the set of parameters $(p, q, A)$ such that

$$ \left\{ \begin{array}{ll} \forall i \in \mathcal{X}, & \sum_{j \in \mathcal{X}} q(i, j) = 0 \\ \forall j \in \mathcal{X}, & \sum_{i \in \mathcal{X}} A(i, j) = 0 \end{array} \right. \qquad (2) $$

Note that $\mathcal{C}$ can be identified with the set

$$ \begin{aligned} \mathcal{C}_{\text{red}} &:= \{((p_i)_{i \ge 2}, (q(i,j))_{i,j \ge 2}, (A(i,j))_{i \ge 2,j}) \mid (p, q, A) \in \mathcal{C}\} \\ &= \mathbb{R}^{K^*-1} \times \mathbb{R}^{K^* \times (K^*-1)} \times \mathbb{R}^{K^* \times (K^*-1)} \end{aligned} $$

These assumptions are natural since they are necessary (but not sufficient) to ensure that if $(p, q, A) \in \mathcal{C}$ and $\pi$ is a probability distribution, $\mathbf{Q}$ a transition matrix and $\mathbf{f}$ a vector of probability densities, then $\pi + p$ is also a probability distribution, $\mathbf{Q} + q$ a transition matrix and $\mathbf{f} + A\mathbf{f}$ a vector of probability densities.

The first step in order to get a lower bound along the same lines as equation (1) is to control the behaviour of the difference near the true parameters, which comes down to proving that the quadratic form $M$ derived from the second-order expansion of

$$ \mathfrak{N} : (p, q, A) \in \mathbb{R}^{K^*} \times \mathbb{R}^{K^* \times K^*} \times \mathbb{R}^{K^* \times K^*} \mapsto \|g^{\pi+p, \mathbf{Q}+q, \mathbf{f}+A\mathbf{f}} - g^{\pi, \mathbf{Q}, \mathbf{f}}\|_2^2 $$

is positive definite on $\mathcal{C}$ for $(\pi, \mathbf{Q}, \mathbf{f}) = (\pi^*, \mathbf{Q}^*, \mathbf{f}^*)$. One can write the coefficients of the matrix of this quadratic form as polynomials in the coefficients of $\pi, \mathbf{Q}$ and of the Gram matrix $G(\mathbf{f}) := (\langle f_i, f_j \rangle)_{i,j \in \mathcal{X}}$. However, this matrix may not be invertible: one has to consider its restriction to the space $\mathcal{C}$, which is equivalent to considering the quadratic form $M_{\mathcal{C}}$ defined on $\mathcal{C}_{\text{red}}$ by the second-order expansion of $x \in \mathcal{C}_{\text{red}} \mapsto \mathfrak{N}(I_{\mathcal{C}}(x))$ where
$I_{\mathcal{C}}$ is the natural linear injection from $\mathcal{C}_{\text{red}}$ to $\mathcal{C}$ (note that $I_{\mathcal{C}}$ is bijective and bicontinous under [HF]). Since the quadratic form $M_{\mathcal{C}}$ is always nonnegative, we only need its determinant to be non zero in order for the quadratic form $M$ to be positive definite on $\mathcal{C}$.

Thus, let $H$ be determinant of the matrix of this quadratic form. $H$ is also a polynomial in the coefficients of $\pi$, $Q$ and $G(f)$. The following lemma shows that there exists some parameters $\pi, Q$ and $f$ satisfying the conditions for which $H$ is not zero.

**Lemma 8.** There exists some parameters $(\pi, Q, f)$ satisfying the conditions [HX] and [HidA] such that $H(\pi, Q, G(f)) \neq 0$.

*Proof.* Proof in Section B.3. □

What should be retained from this lemma is that $H$ is a polynomial which is not identically zero on the set of parameters satisfying the identifiability conditions. This means that one can generically assume it to be different from zero, which corresponds to the assumption

[Hdet] $H(\pi^*, Q^*, G(f^*)) \neq 0$.

Since we assumed $\pi^*$ to be the stationary distribution of $Q^*$, its coefficients-and by extension $H$-can be expressed as a rational function of the coefficients of $Q^*$. Taking $H_1$ as the numerator of the rational function deduced from $H$, one gets another polynomial in the coefficients of $Q^*$ and $G(f^*)$ which is also non-zero. Thus, the following assumption-which we will need to lower bound the error on the density $g^*$ by the error on the parameters-is generically satisfied.

[HdetStat] $H_1(Q^*, G(f^*)) \neq 0$.

Note that [Hdet] and [HdetStat] are equivalent under the assumption [HX].

**Theorem 9.** Assume [HidA] and [Hdet] hold. Then there exists a positive constant $c(\pi^*, Q^*, f^*)$ such that for all $\pi \in \Delta_{K^*}$, for all transition matrix $Q$ of size $K^*$ and for all $h \in \mathcal{F}^{K^*}$ such that $\int h_i d\mu = 1$ for all $i \in [K^*]$,

$$ \|g^{\pi, Q, h} - g^{\pi^*, Q^*, f^*}\|_2^2 \geq c(\pi^*, Q^*, f^*) d_{\text{perm}}((\pi, Q, h), (\pi^*, Q^*, f^*))^2. $$

*Proof.* Proof in Section B.4. □

The following theorem is a direct consequence of the above results. It provides an oracle inequality on the parameters conditionally to the fact that the order has been correctly estimated.

**Theorem 10.** Assume [HX], [HidA], [HF] and [Hdet] hold. Also assume that for all $f \in \mathcal{F}$, $\int f d\mu = 1$.
Then there exists positive constants ($n_0, \rho, A$) $\equiv (n_0, \rho, A)(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ such that if the penalty satisfies

$$ \forall n, \forall M \le n, \forall K \le n, \quad \text{pen}(n, M, K) \ge \rho(MK + K^2 - 1) \frac{\log(n)}{n} $$

then for all $n \ge n_0$, for all $x > 0$, conditionally to $\{\hat{K}_{l.s.} = K^*\}$, with probability larger than $1 - e^{-x}$:

$$ d_{\text{perm}}((\hat{\pi}, \hat{\mathbf{Q}}, \hat{\mathbf{f}}), (\pi^*, \mathbf{Q}^*, \mathbf{f}^*)) \le \frac{4C_{\mathcal{F},2}^L \sqrt{LK^*}}{c(\mathbf{Q}^*, \mathbf{f}^*)} \times \left[ \inf_{M \le n} \left\{ \sum_{k=1}^{K^*} \|f_{M,k}^* - f_k^*\|_2^2 + \text{pen}(n, M, K^*) \right\} + A \frac{x}{n} \right], $$

where $f_{M,k}^*$ is the projection of $f_k^*$ on $\mathfrak{P}_M$.

It is now possible to get the convergence rate of the estimators of the parameters. In order to take the event where $\hat{K}_{l.s.} \ne K^*$ into account, we agree that the distance between the parameters of two HMMs with different orders is bounded by some constant $C_{\text{err}}$. Note that $C_{\text{err}}$ could even be taken as a power of $n$ without changing anything to our result.

**Corollary 11.** Assume [HX], [HidA], [HF] and [Hdet] hold. Also assume that for all $f \in \mathcal{F}$, $\int f d\mu = 1$, and that the penalty satisfies

$$ \forall n, \forall M \le n, \forall K \le n, \quad \text{pen}(n, M, K) = (MK + K^2 - 1) \frac{\log(n)^2}{n} $$

Then there exists a positive constant $A \equiv A(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ such that for all $\beta > 1$, there exists a positive constant $n_0 \equiv n_0(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L, \beta)$ such that for all $n \ge n_0$ and for all $C_{\text{err}} > 0$,

$$ \mathbb{E} \left[ \mathbb{1}_{\hat{K} \neq K^*} C_{\text{err}} + \mathbb{1}_{\hat{K} = K^*} d_{\text{perm}}((\hat{\pi}, \hat{\mathbf{Q}}, \hat{\mathbf{f}}), (\pi^*, \mathbf{Q}^*, \mathbf{f}^*)) \right] \le \frac{4C_{\mathcal{F},2}^L \sqrt{LK^*}}{c(\mathbf{Q}^*, \mathbf{f}^*)} \times \inf_{M \le n} \left\{ \sum_{k=1}^{K^*} \|f_{M,k}^* - f_k^*\|_2^2 + \text{pen}(n, M, K^*) \right\} + \frac{A}{c(\mathbf{Q}^*, \mathbf{f}^*) n} + \frac{C_{\text{err}}}{n^\beta}, $$

and $\mathbb{P}(\hat{K}_{l.s.} \ne K^*) = O(n^{-\beta})$.

Let us discuss what this corollary implies. The approximation error $\sum_{k=1}^{K^*} \|f_{M,k}^* - f_k^*\|_2^2$ can be bounded in a standard way by $O(M^{-2s/D})$ where $s > 0$ is the regularity of the emission densities, see for instance DeVore and Lorentz (1993). One can obtain a trade-off between approximation error and penalty by choosing $M \approx (n/\log(n)^2)^{D/(2s+D)}$, which leads to the optimal rate of convergence $(n/\log(n)^2)^{-2s/(2s+D)}$, up to a logarithmic factor. This shows that our estimators are adaptive, quasi-rate minimax and converge almost surely to the right number of states, all at the same time.
## 4. Spectral estimation

In this section, we introduce our spectral order estimator. We will assume [HX] and [HidA] hold.

The idea of this method is to use the matrix containing the coordinates of the density of two consecutive observations in an orthonormal basis. Take $M \in \mathcal{M}$ and let $\Phi_M = (\varphi_1^{(M)}, \dots, \varphi_M^{(M)})$ be an orthonormal basis of $\mathfrak{P}_M$. For ease of notation, we will drop the dependency in $M$ and write $\varphi_a$ instead of $\varphi_a^{(M)}$. Let us introduce the matrix $\mathbf{N}_M$ and its empirical estimator, defined by

$$ \forall a, b \in [M], \quad \mathbf{N}_M(a, b) := \mathbb{E}[\varphi_a(Y_1)\varphi_b(Y_2)], $$

$$ \forall a, b \in [M], \quad \hat{\mathbf{N}}_M(a, b) := \frac{1}{n} \sum_{s=1}^{n} \varphi_a(Y_s)\varphi_b(Y_{s+1}). $$

$\mathbf{N}_M$ contains the coordinates of the density of $(Y_1, Y_2)$ with respect to $\mu^{\otimes 2}$ on the basis $\Phi_M$. It holds that

$$ \mathbf{N}_M = \mathbf{O}_M \mathrm{Diag}(\pi^*) \mathbf{Q}^* \mathbf{O}_M^\top, \qquad (3) $$

with $\mathbf{O}_M$ the coordinates of the emission densities on the orthonormal basis:

$$ \forall m \in [M], \forall k \in \mathcal{X}, \quad \mathbf{O}_M(m, k) := \mathbb{E}[\varphi_m(Y_1)|X_1 = k] = \int \varphi_m f_k^* d\mu. $$

When the emission densities are linearly independent, $\mathbf{O}_M$ has full rank for $M$ large enough.

The key remark for our method is that $\mathbf{N}_M$ contains explicit information about the order of the HMM, as stated in the following lemma:

**Lemma 12.** There exists $M_0 \equiv M_0(\mathbf{Q}^*, \Phi_M, \mathbf{f}^*)$ such that for all $M \ge M_0$, $\mathbf{N}_M$ has rank $K^*$.

In the following, we will assume $M \ge M_0$ for $M_0$ given by this lemma.

In practice, one only has access to the matrix $\mathbf{N}_M$, which can be seen as a noisy version of $\mathbf{N}_M$. In particular, there is no reason for it to have only $K^*$ nonzero singular values. On the contrary, the spectrum becomes noisy, and when some singular values of $\mathbf{N}_M$ are too small, they can be masked by this noise. As seen in equation (3), this can occur when $\mathbf{Q}^*$ or $\mathbf{O}_M$ are close to not having full rank, which means for $\mathbf{O}_M$ that the emission densities are almost linearly dependent.

Denote by $\sigma_1(A) \ge \sigma_2(A) \ge \dots$ the singular values of the matrix $A$. We can now state the theorem proving the consistency of the spectral order estimator:

**Theorem 13.** Let $\hat{K}_{sp.}(C) = \#\{i | \sigma_i(\hat{\mathbf{N}}_M) > C\sqrt{\log(n)/n}\}$.

There exists $C_0 \equiv C_0(\mathbf{Q}^*, \Phi_M)$ and $n_0 \equiv n_0(\mathbf{Q}^*, \Phi_M, \mathbf{O}_M^*)$ such that for all $C \ge C_0$ and $n \ge n_0 C^2(1 + \log(C))$,

$$ \mathbb{P}(\hat{K}_{sp.}(C) \neq K^*) \le n^{-2} $$

so that $\hat{K}_{sp.}(C) \to K^*$ almost surely.
**Comment.** It is possible to take $M \to \infty$, $n_0$ constant and $C_0$ depending on $M$ in an explicit way as long as $M$ grows slowly enough, that is $\eta_2(\Phi_M) \le \text{cst} \cdot \sqrt{n/\log(n)}$ and $C_0 = \text{cst} \cdot \eta_2(\Phi_M)$ where $\eta_2(\Phi_M)$ is defined in Lemma 14.

**Proof.** The following result from appendix E of de Castro, Gassiat and Le Corff allows to control the difference between the spectra of $\mathbf{N}_M$ and $\hat{\mathbf{N}}_M$.

**Lemma 14.** There exists some constant $C_*$ depending only on $\mathbf{Q}^*$ such that for any positive $u$, $M$ and $n$,

$$ \mathbb{P}\left[\|\mathbf{N}_M - \hat{\mathbf{N}}_M\|_F \ge \frac{\eta_2(\Phi_M)C_*}{\sqrt{n}}(1+u)\right] \le e^{-u^2} $$

where

$$ \eta_2^2(\Phi_M) = \sup_{y,y' \in \mathcal{Y}^2} \sum_{a,b=1}^{M} (\varphi_a(y_1)\varphi_b(y_2) - \varphi_a(y'_1)\varphi_b(y'_2))^2. $$

In particular, taking $u = \sqrt{2\log(n)}$ and assuming $u > 1$ and $n \ge 2$, one has with probability $1 - n^{-2}$ that

$$ \sigma_1(\mathbf{N}_M - \hat{\mathbf{N}}_M) \le C \sqrt{\frac{\log(n)}{n}} $$

for all $C \ge C_0 := 2\sqrt{2}\eta_2(\Phi_M)C_*$, using that for any matrix $A$, one has $\sigma_1(A) \le \|A\|_F$.

Let $C \ge C_0$. We will need Weyl's inequality (a proof may be found in Stewart and Sun (1990) for instance):

**Lemma 15 (Weyl's inequality).** Let $A, B$ be $p \times q$ matrices with $p \ge q$, then for all $i = 1, \dots, q$,

$$ |\sigma_i(A + B) - \sigma_i(A)| \le \sigma_1(B). $$

Using this inequality, one gets that with probability at least $1 - n^{-2}$, for all $1 \le i \le K^*$, $\sigma_i(\hat{\mathbf{N}}_M) > \sigma_{K^*}(\mathbf{N}_M) - C\sqrt{\log(n)/n}$ and for all $i > K^*$, $\sigma_i(\hat{\mathbf{N}}_M) < C\sqrt{\log(n)/n}$.

In particular, if $2C\sqrt{\log(n)/n} < \sigma_{K^*}(\mathbf{N}_M)$, then with probability at least $1 - n^{-2}$, the order is exactly the number of singular values of $\hat{\mathbf{N}}_M$ which are larger than $C\sqrt{\log(n)/n}$. Finally, observe that under the condition $n \ge n_0C^2(1 + \log(C))$,

$$ \begin{aligned} C \sqrt{\frac{\log(n)}{n}} &\le \sqrt{\frac{2 \log(C) + \log(1 + \log(C))}{n_0(1 + \log(C))}} \\ &\le \sqrt{\frac{3}{n_0}} \sqrt{\frac{\log(C)}{1 + \log(C)}}, \end{aligned} $$

since one can assume without loss of generality that $C_0 \ge 1$. By taking $n_0 = 12/\sigma_{K^*}(\mathbf{N}_M)^2$, this concludes the proof. $\square$
# 5. Numerical experiments

In this section, we show the results of our estimators on simulated data. The simulation parameters are introduced in Section 5.1. We show the numerical results and discuss their ability to select the right order in practice in Section 5.2, and we present the data-driven methods and heuristics we used for the numerical implementation in Section 5.3.

## 5.1. Simulation parameters

We will consider $\mathcal{Y} = [0, 1]$ with $\mu$ being the Lebesgue measure. We will use a trigonometric basis on $L^2([0, 1])$ to generate the approximation spaces $(\mathfrak{P}_M)_M$. More precisely, define

$$ \varphi_0(t) = 1 \\ \varphi_a(t) = \sqrt{2} \cos(\pi a t) $$

for all $t \in [0, 1]$ and $a \in \mathbb{N}^*$. We take $\mathfrak{P}_M = \text{Span}(\{\varphi_a | 0 \le a < M\})$ the spaces induced by the trigonometric basis.

**Comment.** Taking the same vectors in all bases is not mandatory to ensure theoretical consistency, but in practice it allows us to take an additional initial point for the minimization step and improves the stability of the algorithm (see Step 1 below).

We will assume $f^*$ to be linearly independent, so that one only needs $L = 3$ observations to recover the parameters of the HMM.

In order to assess the performances of the different procedures, we generate $n$ observations of a HMM of order 3 for several values of $n$, using the following parameters:

* Emission distributions: Beta distributions with two possible sets of parameters: $[(1.5; 5), (7; 2) \text{ and } (6; 6)]$ or $[(2; 5), (4; 2) \text{ and } (4; 4)]$;

* Markov chain parameters:

$$ \begin{aligned} Q^* &= \begin{pmatrix} 0.8 & 0.1 & 0.1 \\ 0.2 & 0.7 & 0.1 \\ 0.07 & 0.13 & 0.8 \end{pmatrix}, \\ \pi^* &= \begin{pmatrix} \frac{47}{120} & \frac{11}{40} & \frac{1}{3} \end{pmatrix} \\ &\approx (0.3917 \quad 0.2750 \quad 0.3333). \end{aligned} $$

Finally, we take $M_{\text{max}} = 50$ and $K_{\text{max}} = 5$ the maximum values of $M$ and $K$ for which we will compute the estimators.

The simulation codes are available in MATLAB at https://www.normalesup.org/~llehericy/HMM_order_simfiles/.
<table><thead><tr><th>n</th><th>P(Κ̂<sub>1.s.</sub> = K*)</th><th>P(Κ̂<sub>sp.</sub> = K*)</th></tr></thead><tbody><tr><td>999</td><td>0.2</td><td>0</td></tr><tr><td>3 000</td><td>1</td><td>0</td></tr><tr><td>9 999</td><td>1</td><td>1</td></tr><tr><td>19 998</td><td>1</td><td>1</td></tr></tbody></table>

(a) Beta parameters (1.5; 5), (7; 2) and (6; 6).

<table><thead><tr><th>n</th><th>P(Κ̂<sub>1.s.</sub> = K*)</th><th>P(Κ̂<sub>sp.</sub> = K*)</th></tr></thead><tbody><tr><td>7 500</td><td>0.3</td><td>0</td></tr><tr><td>19 998</td><td>0.9</td><td>0</td></tr><tr><td>30 000</td><td>1</td><td>0</td></tr><tr><td>49 998</td><td>1</td><td>0.1</td></tr></tbody></table>

(b) Beta parameters (2; 5), (4; 2) and (4; 4)

Figure 1: Probability to select the right order for the two methods ($\hat{K}_{1.s.}$ for the least squares method and $\hat{K}_{sp.}$ for the spectral method). 10 simulations have been done for each $n$. Parameters for spectral selection are $M = 40$, $M_{reg} = 35$ and $\tau = 1.5$ (see Section 5.3.2 for the definition of these parameters).

## 5.2. Numerical results

Figure 1 summarizes the results of both procedures. Both select the right order as soon as the number of observations is sufficient.

The spectral method is easily put in practice and runs extremely fast. It doesn't need a time-consuming contrast minimization step or an initial point. However, the thresholding of the singular values is a delicate issue, and if the order is incorrect, then the theoretical results about the spectral estimators of the parameters don't hold and this method may behave poorly.

The performances of the least squares method are much better (see Figure 1 for comparing the order estimators and de Castro, Gassiat and Lacour (2016) for comparing the emission densities estimators). In addition, the model selection step is easy to handle and gives an estimator of the order that we proved to be consistent, estimators of the HMM parameters that we proved to be quasi-rate minimax and a way to check whether the model fits the data well (see Section 5.3.1), all at the same time. However, the minimization of the (non-convex) empirical contrast is a time-consuming step, especially for large samples and large models.

Choosing the right method is thus a question of computational power and amount of available data. For small datasets where one wants to get accurate results, the least squares method is best. Conversely, on large datasets and large models, the spectral method is a good choice in order to obtain many estimators in a reasonable amount of time.

## 5.3. Practical implementation

### 5.3.1. Least squares method

The first issue that one encounters when trying to minimize the least squares criterion $\gamma_n$ is that it is not convex. Several algorithms have been proposed to overcome this difficulty. We chose to use CMA-ES (for Covariance Matrix Adaptation Estimation Strategy, see Hansen (2006)) in order to find a minimizer. This estimator is easy to use and works well
in many situations, but–like all approximate minimization algorithms–it requires a good initial point since it might otherwise remain stuck in local minima.

One part of our method consists in using previous estimates as initial points for further steps to counter this phenomenon, since it is likely that this way the estimators stay near the real minimizer. Our practical algorithm is the following:

1. Minimize $\gamma_n$ on each model, for $M \le M_{max}$ and $K \le K_{max}$. We take several initial points for model $(K, M)$ according to the following cases:

* $K = 1$. Use a HMM with a single state and a uniform emission distribution.

* $K > 1$. Take the estimator from model $(K - 1, M)$. For each hidden state of the corresponding HMM, use the model where this state is duplicated. More precisely, the Markov chain $\tilde{X}$ where state $I$ is duplicated is obtained by replacing the state $I$ from chain $X$ with two states $I_1$ and $I_2$ such that for each state $S \ne I_1, I_2$,

$$ 
\begin{aligned}
\mathbb{P}(\tilde{X}_{t+1} = I_1 | \tilde{X}_t = S) &= \frac{1}{2} \mathbb{P}(X_{t+1} = I | X_t = S) \\
&= \mathbb{P}(\tilde{X}_{t+1} = I_2 | \tilde{X}_t = S) \\
\mathbb{P}(\tilde{X}_{t+1} = S | \tilde{X}_t = I_1) &= \mathbb{P}(X_{t+1} = S | X_t = I) \\
&= \mathbb{P}(\tilde{X}_{t+1} = S | \tilde{X}_t = I_2)
\end{aligned}
$$

and

$$ 
\begin{aligned}
\mathbb{P}(\tilde{X}_{t+1} = I_2 | \tilde{X}_t = I_1) &= \frac{1}{2} \mathbb{P}(X_{t+1} = I | X_t = I) \\
&= \mathbb{P}(\tilde{X}_{t+1} = I_1 | \tilde{X}_t = I_2)
\end{aligned}
$$

* $M > 1$. Use estimator from model $(K, M-1)$ with the $M$-th coordinate of each emission density set to zero. This is only interesting if all $\mathfrak{P}_M$ are spanned by the first $M$ vectors of a given orthonormal basis, like for trigonometric spaces.

Then, after minimization from each one of these initial points, take the estimator that minimizes $\gamma_n$.

2. Tune the parameter $\rho$ of the penalty with the slope heuristics or the dimension jump method (see below) and select $\tilde{M}$ and $\tilde{K}$.

3. Return the estimator for $M = \tilde{M}$ and $K = \tilde{K}$.

This iterative initialization procedure relies on the heuristics that when the order is underestimated, then several states are "merged" together. Duplicating a merged state will allow to separate them effectively while still taking advantage of the computations done up to now. It is meant to avoid having to recalculate all states at the same time (which could get us stuck in sub-optimal local minima) when the best solution is likely to be a small modification of the previous estimator. In addition, when the order is overestimated, it allows to make sure the empirical criterion is indeed decreasing with
the dimension of the model by giving an estimator that performs at least as well as those from smaller models. This makes our method robust to an overestimation of the order.

The last practical issue is a very common one in the model selection setting: the constant $\rho$ of the penalty is unknown and has to be estimated before one can select the right model. Several data-driven estimators have been proposed to circumvent this difficulty, for instance dimension jump heuristics, slope heuristics, bootstrap or cross validation. We focus on the first two, which have several advantages in our setting. First, they are easy to use, are proved to be theoretically valid in many settings and work well in a wide range of applications (see for instance Baudry, Maugis and Michel (2012) and references therein). Secondly, they take advantage of the structure of our problem and both give a qualitative way to check whether the choice of penalty is valid or not, and by extension whether the model is misspecified or not.

**Dimension jump heuristics** In this paragraph, we study the selected parameters

$$ \rho \mapsto (\hat{M}(\rho), \hat{K}(\rho)) \in \arg \min \{\gamma_n(\hat{g}_{K,M}) + \rho \text{pen}_{\text{shape}}(n, M, K)\} $$

and the selected complexity

$$ \rho \mapsto \text{Comp}(\rho) = \hat{M}(\rho)\hat{K}(\rho) + \hat{K}(\rho)[\hat{K}(\rho) - 1] $$

with $\text{pen}_{\text{shape}}(n, M, K) = (MK + K^2 - 1) \log(n)/n$.

Assume that there exists $\kappa$ such that $\kappa \text{pen}_{\text{shape}}$ is a minimal penalty, that is a penalty such that as $n$ tends to infinity, for all $\rho > \kappa$, the size of the model chosen for penalty $\rho \text{pen}_{\text{shape}}$ remains small in some sense and for all $\rho < \kappa$, the size of the model becomes huge. Then, for $n$ large enough, this will appear on the graph of the selected model complexity as a “dimension jump”: around some constant $\rho_{\text{jump}}$, the complexity will abruptly drop from large models to small models. This is clearly the case in Figure 2. Figure 3 shows the behaviour of $\hat{M}$ and $\hat{K}$ with $\rho$. A dimension jump also occurs with these functions. It is most visible for $\hat{M}$.

Finally, once the dimension jump location $\rho_{\text{jump}}$ has been estimated, we take $\hat{\rho} = 2\rho_{\text{jump}}$ to select the final parameters.

It is worth noting that this jump method also gives a qualitative way to check whether the choice of parameters is sensible: if no clear jump can be identified, then either one didn't consider enough models to make the jump clear, or the penalty isn't the right one, or the model cannot approximate the data distribution well.

**Slope heuristics** This heuristics relies on the fact that when $\text{pen}_{\text{shape}}$ is a minimal penalty, then the empirical contrast function is expected to behave like $\rho_{\text{min}}\text{pen}_{\text{shape}}$ for large models and for some constant $\rho_{\min}$. This gives both a way to calibrate the constant of the penalty and to check if the chosen penalty has the right shape (see Baudry, Maugis and Michel (2012)). The final penalty is then taken as $2\hat{\rho}_{\min}\text{pen}_{\text{shape}}$.

Figure 4 shows the graph of the empirical contrast depending on $\text{pen}_{\text{shape}}$. The slope heuristics works well in this situation, suggesting that our penalty has the right shape.
<figure><img src="image_8.png" /><figcaption>Figure 2: Graph of $\rho \mapsto \text{Comp}(\rho)$ for 10 sets of $n$ consecutive observations. Here, the parameters of the Beta distribution are (2; 5), (4; 2) and (4; 4).</figcaption></figure>

<figure><img src="image_9.png" /><figcaption>Figure 3: Graph of $\rho \mapsto \hat{M}(\rho)$ and $\rho \mapsto \hat{K}(\rho)$ for 10 sets of $n$ consecutive observations. Here, the parameters of the Beta distribution are (2; 5), (4; 2) and (4; 4).</figcaption></figure>

### 5.3.2. Spectral method

The idea of the spectral order estimation is to recover the rank of the matrix $N_M$. However, this is not always possible: if one singular value of $N_M$ is smaller than the noise (which is the case when $O_M$ is close from not being invertible, i.e. when the emission densities are close from being linearly dependent, and when there are only few observations), then this method will not be able to “see” the corresponding hidden state.

Figure 5—and in particular Figure 5a—illustrates this problem: the third singular value is smaller than several noisy singular values, which means it won't be possible to recover
<figure><img src="image_10.png" /><figcaption>Figure 4: Empirical constrast and calibrated penalty for $n = 49, 998$. Here, the parameters of the Beta distribution are (2; 5), (4; 2) and (4; 4).</figcaption></figure>

it. Even if one knows the right order, the fact that the singular value is smaller than the noise can make it impossible for spectral methods to recover the true parameters. Figure 6 shows the result when trying to estimate the densities in the situation of Figure 5a: when the singular value is drowned by the noise, the output of the spectral estimator is aberrant. Notice that it is not a fatality: in the same situation, the least squares method manages to give sensible estimators of the emission densities. This is an intrinsic limitation of the spectral method.

Therefore, what we need is a way to threshold the parameters in order to distinguish noise from significant singular values. The estimator $\hat{K}_{\text{sp.}}(C)$ is one way to achieve this, but the calibration of $C$ is a tricky problem, since the right choice of $C$ depends on the parameters of the HMM. We will use a different method, which relies on the same idea: identifying the noisy singular values which stand out from the others and saying they correspond to nonzero singular values of $N_M$. Our heuristics relies on the fact that when one sorts the singular values in decreasing order, then the smallest ones approximately follow an affine relation with respect to their index. This tendency is shown in Figure 7.

We proceed as follows. Let $M$ and $M_{\text{reg}}$ be two positive integers such that $M_{\text{reg}} \le M \le M_{\text{max}}$. We estimate the affine dependance of the singular values of $\hat{N}_M$ with respect to their index with a linear regression using its $M_{\text{reg}}$ smallest singular values. Then, we set a thresholding parameter $\tau > 1$. We say a singular value is *significant* if it is above $\tau$ times the value that the regression predicts for it. Lastly, we take $\hat{K}_{\text{sp.}}$ as the number of consecutive significant singular values starting from the largest one. This heuristics seems to work as soon as $\tau$ is large enough, e.g. $\tau = 1.5$.
<figure><img src="image_11.png" /><figcaption>(a) $n = 19,998$, Beta parameters (2; 5), (4; 2) (b) $n = 49,998$, Beta parameters (2; 5), (4; 2) and (4; 4).</figcaption></figure>

<figure><img src="image_12.png" /><figcaption>(c) $n = 3,000$, Beta parameters (1.5; 5), (7; 2) (d) $n = 19,998$, Beta parameters (1.5; 5), (7; 2) and (6; 6).</figcaption></figure>

Figure 5: Spectrum of the empirical matrix $\hat{\mathbf{N}}_M$ and the theoretical matrix $\mathbf{N}_M$ for $M = 40$ and 10 simulations. The first singular values are too large to appear here.

# 6. Proofs

## 6.1. Main technical result

The following lemma is the main technical result of this paper. It is the key for both the strong consistency and the oracle inequalities. It allows to control the difference between the empirical criterion $\gamma_n$ and the theoretical $\mathbf{L}^2$ loss for all models at the same time.

Define $\nu: t \mapsto \frac{1}{n} \sum_{s=1}^{n} t(Z_s) - \int t g^*$, so that

$$ \forall t \in \mathbf{L}^2(\mathcal{Y}^L, \mu^{\otimes L}), \quad \gamma_n(t) + \|g^*\|_2^2 = \|t - g^*\|_2^2 - 2\nu(t) \quad (4) $$
<figure><img src="image_13.png" /><figcaption>Figure 6: Estimators of the emission densities for $n = 19,998$ and Beta parameters (2; 5), (4; 2) and (4; 4). We took $K = \hat{K}_{1.s.} = 3$ and $M = \hat{M} = 13$. The bad behaviour of the spectral algorithm when the emission densities are poorly separated is clearly visible on the third emission distribution.</figcaption></figure>

<figure><img src="image_14.png" /><figcaption>Figure 7: Spectrum of $N_M$ for $M = 40$ and $n = 49,998$ for Beta parameters (2; 5), (4; 2) and (4; 4). The regression (green line) has been performed on the 35 smallest singular values. The two largest singular values are too large to appear here.</figcaption></figure>
Let

$$ 
\begin{aligned}
s = (s_{K,M})_{K,M} \in \mathbf{S} &:= \prod_{K \in \mathbb{N}^*, M \in \mathcal{M}} \left( \bigcup_{K} S_K \right) \\
&\mapsto (Z_{K,M}(s))_{K,M} \\
&:= \left( \sup_{t \in S_{K,M}} \left[ \frac{|\nu(t - s_{K,M})|}{\|t - s_{K,M}\|_2^2 + x_{K,M}^2} \right] \right)_{K,M} \quad (5)
\end{aligned}
$$

**Comment.** It is not necessary to assume that $s_{K,M} \in S_{K,M}$. In particular, one can take $s_{K,M} = g^*$ for all $K, M$. In that case, we will simply write $Z_{K,M}(g^*)$.

**Lemma 16.** Assume [HX] and [HF] hold. Then there exists a sequence $(x_{K,M})_{K,M} \equiv (x_{K,M})_{K,M}(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ and positive constants $(n_0, \rho, A) \equiv (n_0, \rho, A)(C_{\mathcal{F},2}, C_{\mathcal{F},\infty}, \mathbf{Q}^*, L)$ such that if the penalty $\widetilde{pen}$ satisfies

$$ \forall n, \forall M \le n, \forall K \le n \quad \widetilde{pen}(n, M, K) \ge \rho(MK + K^2 - 1) \frac{\log(n)}{n} $$

then for all $s \in \mathbf{S}$, $n \ge n_0$ and $x > 0$, one has with probability larger than $1 - e^{-x}$:

$$ \left\{ \begin{array}{l} \sup_{K' \le n, M' \le n} Z_{K',M'}(s) \le \frac{1}{4} \\ \\ \sup_{K' \le n, M' \le n} \left( 2Z_{K',M'}(s) x_{K',M'}^2 - \widetilde{pen}(n, M', K') \right) \le A \frac{x}{n} \end{array} \right. $$

**Comment.** One can replace the constant $1/4$ in the first upper bound by any $\epsilon > 0$, at the cost of changing the constants $n_0$, $\rho$ and $A$.

The structure of the proof follows the usual method to control empirical processes, see for instance Massart (2007), Chapter 6, adapted to the HMM structure by de Castro, Gassiat and Lacour (2016). The novelty and main difficulty of the proof comes from the generalization to both nonparametric densities and an unknown number of states: we had to introduce a much finer control of the constants and of the bracketing entropy of the models in order to take the dependency in the order of the HMM into account.

The details of the proof can be found in appendix C.

## 6.2. Identifiability proofs

### 6.2.1. Proof of Corollary 2

Denote by $\text{Proj}_A$ the orthogonal projection on a linear space $A$.

Since the union of $(\mathfrak{P}_M)_{M \in \mathcal{M}}$ is dense in $\mathcal{F}$, we can take $M$ such that [HidA] or [HidB] holds for $\mathbf{f}_M^* = (f_{M,k}^*)_{k \in \mathcal{X}} := (\text{Proj}_{\mathfrak{P}_M} \mathbf{f}_k^*)_{k \in \mathcal{X}}$.

We will need the following lemma.
**Lemma 17.**

$$ \forall \pi \in \mathbb{R}^K, \forall \mathbf{Q} \in \mathbb{R}^{K \times K}, \forall \mathbf{f} \in \mathcal{F}^K, \forall M, \quad \mathrm{Proj}_{\mathfrak{P}_M^{\otimes L}}(g^{\pi, \mathbf{Q}, \mathbf{f}}) = g^{\pi, \mathbf{Q}, \mathrm{Proj}_{\mathfrak{P}_M}(\mathbf{f})} $$

*Proof.* By linearity of the projection operator, it is enough to prove that for all $(t_1, \dots, t_L) \in (\mathbf{L}^2(\mathcal{Y}, \mu))^L$,

$$ \mathrm{Proj}_{\mathfrak{P}_M^{\otimes L}}(t_1 \otimes \dots \otimes t_L) = \mathrm{Proj}_{\mathfrak{P}_M}(t_1) \otimes \dots \otimes \mathrm{Proj}_{\mathfrak{P}_M}(t_L) $$

which is easy to check.

<figure><img src="image_15.png" /></figure>

We will make a proof by contradiction. Assume that $\inf_{t \in S_K} \|t - g^*\|_2 = 0$ for some $K < K^*$. Then there exists a sequence $(g_n)_{n \ge 1} = (g^{\pi_n, \mathbf{Q}_n, \mathbf{f}_n})_{n \ge 1}$ such that $g_n \to g^*$ in $\mathbf{L}^2(\mathcal{Y}^L, \mu^{\otimes L})$, with $\pi_n \in \Delta_K$, $\mathbf{Q}_n$ a transition matrix of size $K$ and $\mathbf{f}_n \in \mathcal{F}^K$.

The orthogonal projection on $\mathfrak{P}_M^{\otimes L}$ is continuous, so by using Lemma 17, one gets that

$$ g^{\pi_n, \mathbf{Q}_n, \mathrm{Proj}_{\mathfrak{P}_M}(\mathbf{f}_n)} \to g^{\pi^*, \mathbf{Q}^*, \mathbf{f}_M^*} $$

Then, using the compacity of $\Delta_K$ and of the set of transition matrices of size $K$ and the relative compacity of $(\mathcal{F} \cap \mathfrak{P}_M)^K$ (which is a bounded subset of a finite dimension linear space), one gets (up to extraction of a subsequence) that there exists $\pi_\infty \in \Delta_K$, $\mathbf{Q}_\infty$ a transition matrix of size $K$ and $\mathbf{f}_\infty \in (\mathfrak{P}_M)^K$ such that $\pi_n \to \pi_\infty$, $\mathbf{Q}_n \to \mathbf{Q}_\infty$ and $\mathrm{Proj}_{\mathfrak{P}_M}(\mathbf{f}_n) \to \mathbf{f}_\infty$.

Finally, using the continuity of the function $(\pi, \mathbf{Q}, \mathbf{f}) \mapsto g^{\pi, \mathbf{Q}, \mathbf{f}}$ and the unicity of the limit, one gets

$$ g^{\pi_\infty, \mathbf{Q}_\infty, \mathbf{f}_\infty} = g^{\pi^*, \mathbf{Q}^*, \mathbf{f}_M^*} $$

Then Proposition 1 contradicts the assumption $K < K^*$, which is enough to conclude.

## 6.3. Consistency proofs

The definition of $\hat{K}_{1,s.}$ is equivalent to the following one:

$$ \hat{K}_{1,s.} \in \arg \min_{K \le n} \{ \gamma_n(\hat{g}_{K, \hat{M}_K}) + \mathrm{pen}(n, \hat{M}_K, K) \} $$

where

$$ \hat{M}_K \in \arg \min_{M \le n} \{ \gamma_n(\hat{g}_{K,M}) + \mathrm{pen}(n, M, K) \} $$

Choosing $K$ rather than $K^*$ means that $K$ is better than $K^*$, i.e.

$$ \{\hat{K}_{1,s.} = K\} \subset \left\{ 0 \ge \inf_{M \le n} \{\gamma_n(\hat{g}_{K,M}) + \mathrm{pen}(n, M, K)\} - \inf_{M \le n} \{\gamma_n(\hat{g}_{K^*,M}) + \mathrm{pen}(n, M, K^*)\} \right\}. $$
Let

$$
\begin{align*}
D_{n,K} &:= \inf_{M \le n} \{ \gamma_n(\hat{g}_{K,M}) + \text{pen}(n, M, K) \} \\
&\quad - \inf_{M \le n} \{ \gamma_n(\hat{g}_{K^*,M}) + \text{pen}(n, M, K^*) \} \\
&= \gamma_n(\hat{g}_{K,\hat{M}_K}) + \text{pen}(n, \hat{M}_K, K) \\
&\quad - \inf_{M \le n} \{ \inf_{t \in S_{K^*,M}} \gamma_n(t) + \text{pen}(n, M, K^*) \}.
\end{align*}
$$

Then

$$
\{ \hat{K}_{1,s.} = K \} \subset \{ D_{n,K} \le 0 \}.
$$

We will thus control the probability of the latter event for all $K < K^*$ in the first case and $K > K^*$ in the second case.

**Proof of Theorem 3** Let $M_0 \in \mathcal{M}$. We will choose a suitable value for this integer later in the proof. Assume $n \ge M_0$. Then by definition of $D_{n,K}$ and of $\nu$ (equation (4)),

$$
\begin{align*}
D_{n,K} &\ge \gamma_n(\hat{g}_{K,\hat{M}_K}) + \text{pen}(n, \hat{M}_K, K) - \gamma_n(g_{K^*,M_0}^*) - \text{pen}(n, M_0, K^*) \\
&\ge \|g^* - \hat{g}_{K,\hat{M}_K}\|_2^2 - \|g^* - g_{K^*,M_0}^*\|_2^2 - 2\nu(\hat{g}_{K,\hat{M}_K} - g_{K^*,M_0}^*) \\
&\quad + \text{pen}(n, \hat{M}_K, K) - \text{pen}(n, M_0, K^*).
\end{align*}
$$

Using the definition of $Z_{K,M}$ (equation (5)), one gets that

$$
\begin{align*}
|\nu(\hat{g}_{K, \hat{M}_K} - g_{K^*, M_0}^*)| &\le |\nu(\hat{g}_{K, \hat{M}_K} - g^*)| + |\nu(g^* - g_{K^*, M_0}^*)| \\
&\le Z_{K, \hat{M}_K}(g^*)(\|g^* - \hat{g}_{K, \hat{M}_K}\|_2^2 + x_{K, \hat{M}_K}^2) \\
&\quad + Z_{K^*, M_0}(g^*)(\|g^* - g_{K^*, M_0}^*\|_2^2 + x_{K^*, M_0}^2).
\end{align*}
$$

Let $n_0$, $\rho$ and $A$ be as in Lemma 16. We can assume that $n_0 \ge K^*$ so that $K^* \le n$. Let us introduce the function $\widetilde{\text{pen}}(n, M, K) = \rho(MK + K^2 - 1)^{\frac{\log(n)}{n}}$. Let $n \ge n_0$ and $x > 0$ and assume we are in the event of probability $1 - e^{-x}$ of Lemma 16. Then, for all $K \le n$:

$$
\begin{align*}
|\nu(\hat{g}_{K, \hat{M}_K} - g_{K^*, M_0}^*)| \le {}& \frac{1}{4} \|g^* - \hat{g}_{K, \hat{M}_K}\|_2^2 + \frac{1}{2} A \frac{x}{n} + \frac{1}{2} \widetilde{\text{pen}}(n, \hat{M}_K, K) \\
& + \frac{1}{4} \|g^* - g_{K^*, M_0}^*\|_2^2 + \frac{1}{2} A \frac{x}{n} + \frac{1}{2} \widetilde{\text{pen}}(n, M_0, K^*)
\end{align*}
$$

and

$$
\begin{align*}
D_{n,K} \ge \frac{1}{2} \|g^* - \hat{g}_{K, \hat{M}_K}\|_2^2 - \frac{3}{2} \|g^* - g_{K^*, M_0}^*\|_2^2 - 2A \frac{x}{n} + \text{pen}(n, \hat{M}_K, K) \\
\qquad - \text{pen}(n, M_0, K^*) - \widetilde{\text{pen}}(n, \hat{M}_K, K) - \widetilde{\text{pen}}(n, M_0, K^*).
\end{align*}
$$

We assumed $\text{pen} \ge \widetilde{\text{pen}}$, so that

$$
D_{n,K} \ge \frac{1}{2} \|g^* - \hat{g}_{K, \hat{M}_K}\|_2^2 - \frac{3}{2} \|g^* - g_{K^*, M_0}^*\|_2^2 - 2A \frac{x}{n} - 2\text{pen}(n, M_0, K^*)
$$
Corollary 2 ensures that

$$d := \inf_{K<K^*} \inf_{t \in S_K} \|t - g^*\|_2 > 0,$$

so that for all $K < K^*$,

$$D_{n,K} \ge \frac{d^2}{2} - \frac{3}{2} \|g^* - g_{K^*,M_0}\|_2^2 - 2A \frac{x}{n} - 2\text{pen}(n, M_0, K^*).$$

By density of $(\mathfrak{P}_M)_{M \in \mathcal{M}}$ in $\mathcal{F}$, one gets that

$$\inf_M \|g_{K^*,M}^* - g^*\|_2 = 0$$

so that there exists $M_0$ such that $\|g^* - g_{K^*,M_0}\|_2^2 \le d^2/6$. If we choose this $M_0$, we get that

$$D_{n,K} \ge \frac{d^2}{4} - 2A \frac{x}{n} - 2\text{pen}(n, M_0, K^*).$$

Which implies that $D_{n,K} > 0$ as soon as $2Ax/n < d^2/4 - 2\text{pen}(n, M_0, K^*)$, i.e.

$$x < \left( \frac{d^2}{8} - \text{pen}(n, M_0, K^*) \right) \frac{n}{A}.$$

To conclude, note that there exists $\tilde{n}_0 \ge \max(n_0, M_0)$ such that for all $n \ge \tilde{n}_0$, $\text{pen}(n, M_0, K^*) \le \frac{d^2}{16}$. Then, letting $\beta = \frac{d^2}{16A}$, one has for all $n \ge \tilde{n}_0$, with probability $1 - e^{-\beta n}$, for all $K < K^*$, $D_{n,K} > 0$, which implies that $\hat{K}_{1,s.} \ne K$.

**Proof of Theorem 4** For all $K \ge K^*$,

$$D_{n,K} \ge \gamma_n(\hat{g}_{K,\hat{M}_K}) + \text{pen}(n, \hat{M}_K, K) - \gamma_n(g_{K^*,\hat{M}_K}^*) - \text{pen}(n, \hat{M}_K, K^*)$$

and

$$\gamma_n(\hat{g}_{K,\hat{M}_K}) - \gamma_n(g_{K^*,\hat{M}_K}^*) = \|\hat{g}_{K,\hat{M}_K} - g^*\|_2^2 - \|g_{K^*,\hat{M}_K}^* - g^*\|_2^2 \\ - 2\nu(\hat{g}_{K,\hat{M}_K} - g_{K^*,\hat{M}_K}^*).$$

Note that $g_{K^*,\hat{M}_K}^* = g_{K,\hat{M}_K}^*$ is the orthogonal projection of $g^*$ on $\mathfrak{P}_{\hat{M}_K}^{\otimes L}$ and $\hat{g}_{K,\hat{M}_K} \in S_{K,\hat{M}_K} \subset \mathfrak{P}_{\hat{M}_K}^{\otimes L}$, so that, using the Pythagorean Theorem,

$$\|\hat{g}_{K,\hat{M}_K} - g^*\|_2^2 - \|g_{K^*,\hat{M}_K}^* - g^*\|_2^2 = \|\hat{g}_{K,\hat{M}_K} - g_{K^*,\hat{M}_K}^*\|_2^2.$$

Let $n_0$, $\rho$ and $A$ be as in Lemma 16. We can assume that $n_0 \ge K^*$ so that $K^* \le n$. Let us introduce the function $\text{pen}(n, M, K) = \rho(MK + K^2 - 1) \frac{\log(n)}{n}$. Let $n \ge n_0$ and $x > 0$
and assume we are in the event of probability $1 - e^{-x}$ of Lemma 16. Then, for all $K \le n$ such that $K \ge K^*$:

$$ \begin{aligned} |\nu(\hat{g}_{K, \hat{M}_K} - g_{K^*, \hat{M}_K}^*)| &= |\nu(\hat{g}_{K, \hat{M}_K} - g_{K, \hat{M}_K}^*)| \\ &\le Z_{K, \hat{M}_K} \left( (g_{K', M'}^*)_{K', M'} \|\hat{g}_{K, \hat{M}_K} - g_{K, \hat{M}_K}^*\|_2^2 \right. \\ &\qquad \left. + Z_{K, \hat{M}_K} \left( (g_{K', M'}^*)_{K', M'} \right) x_{K, \hat{M}_K}^2 \right) \\ &\le \frac{1}{4} \|\hat{g}_{K, \hat{M}_K} - g_{K, \hat{M}_K}^*\|_2^2 + \frac{1}{2} A \frac{x}{n} + \frac{1}{2} \widetilde{\text{pen}}(n, \hat{M}_K, K), \end{aligned} $$

which implies

$$ \begin{aligned} \gamma_n(\hat{g}_{K, \hat{M}_K}) - \gamma_n(g_{K^*, \hat{M}_K}^*) &\ge \frac{1}{2} \|\hat{g}_{K, \hat{M}_K} - g_{K, \hat{M}_K}^*\|_2^2 - A \frac{x}{n} - \widetilde{\text{pen}}(n, \hat{M}_K, K) \\ &\ge -A \frac{x}{n} - \widetilde{\text{pen}}(n, \hat{M}_K, K) \end{aligned} $$

so that for all $K \le n$ such that $K \ge K^*$:

$$ D_{n,K} \ge \text{pen}(n, \hat{M}_K, K) - \text{pen}(n, \hat{M}_K, K^*) - \widetilde{\text{pen}}(n, \hat{M}_K, K) - A \frac{x}{n}. $$

Now, assume that $[\text{Hpen}](\alpha, \rho)$ holds for some $\alpha > 0$ and the above constant $\rho$. Then there exists $n_1$ such that for all $n \ge n_1$ and for all $K \le n$ such that $K \ge K^*$,

$$ D_{n,K} \ge \alpha \frac{\log(n)}{n} - A \frac{x}{n}, $$

which is strictly positive as soon as $x < \alpha \log(n)/A$. Thus, letting $\beta = 1/(2A)$, one has for all $n \ge \max(n_0, n_1, K^*)$, with probability $1 - n^{-\beta\alpha}$, for all $K \le n$ such that $K > K^*$, $D_{n,K} > 0$, which implies that $\hat{K}_{1,s.} \ne K$. This concludes the proof.

# 7. Acknowledgment

We would like to thank Elisabeth Gassiat for her precious advice and Yohann de Castro for his codes which were at the root of our numerical experiments.

# References

* ALEXANDROVICH, G. and HOLZMANN, H. (2014). Nonparametric identification of hidden Markov models. *arXiv preprint arXiv:1404.4210*.

* ALLMAN, E. S., MATIAS, C. and RHODES, J. A. (2009). Identifiability of parameters in latent structure models with many observed variables. *The Annals of Statistics* 3099–3132.
ANANDKUMAR, A., HSU, D. J. and KAKADE, S. M. (2012). A Method of Moments for Mixture Models and Hidden Markov Models. In *COLT* 1 4.

BAUDRY, J.-P., MAUGIS, C. and MICHEL, B. (2012). Slope heuristics: overview and implementation. *Statistics and Computing* **22** 455–470.

BICKEL, P. J., RITOV, Y., RYDEN, T. et al. (1998). Asymptotic normality of the maximum-likelihood estimator for general hidden Markov models. *The Annals of Statistics* **26** 1614–1635.

BIRGÉ, L. and MASSART, P. (2007). Minimal penalties for Gaussian model selection. *Probability theory and related fields* **138** 33–73.

CELEUX, G. and DURAND, J.-B. (2008). Selecting hidden Markov model state number with cross-validated likelihood. *Computational Statistics* **23** 541–564.

CHAMBAZ, A., GARIVIER, A. and GASSIAT, E. (2009). A minimum description length approach to hidden Markov models with Poisson and Gaussian emissions. Application to order identification. *Journal of Statistical Planning and Inference* **139** 962–977.

COUVREUR, L. and COUVREUR, C. (2000). Wavelet-based non-parametric HMM's: theory and applications. In *Acoustics, Speech, and Signal Processing, 2000. ICASSP'00. Proceedings. 2000 IEEE International Conference on* 1 604–607. IEEE.

DE CASTRO, Y., GASSIAT, É. and LACOUR, C. (2016). Minimax Adaptive Estimation of Nonparametric hidden Markov models. *Journal of Machine Learning Research* **17** 1–43.

DE CASTRO, Y., GASSIAT, E. and LE CORFF, S. Consistent estimation of the filtering and marginal smoothing distributions in nonparametric hidden Markov models. *IEEE Information Theory, to appear*.

DEVORE, R. A. and LORENTZ, G. G. (1993). *Constructive approximation* **303**. Springer Science & Business Media.

DOUC, R., MOULINES, E., RYDÉN, T. et al. (2004). Asymptotic properties of the maximum likelihood estimator in autoregressive models with Markov regime. *The Annals of statistics* **32** 2254–2304.

GASSIAT, E. (2002). Likelihood ratio inequalities with applications to various mixtures. In *Annales de l'IHP Probabilités et statistiques* **38** 897–906.

GASSIAT, E. and BOUCHERON, S. (2003). Optimal error exponents in hidden Markov models order estimation. *Information Theory, IEEE Transactions on* **49** 964–980.

GASSIAT, E., CLEYNEN, A. and ROBIN, S. (2015). Finite state space non parametric hidden Markov models are in general identifiable. *Stat. Comp.* 1–11.

GASSIAT, E. and KERIBIN, C. (2000). The likelihood ratio test for the number of components in a mixture with Markov regime. *ESAIM: Probability and Statistics* **4** 25–52.

GASSIAT, E. and ROUSSEAU, J. (2014). About the posterior distribution in hidden Markov models with unknown number of states. *Bernoulli* **20** 2039–2075.

HANSEN, N. (2006). The CMA evolution strategy: a comparing review. In *Towards a new evolutionary computation* 75–102. Springer.

HSU, D., KAKADE, S. M. and ZHANG, T. (2012). A spectral algorithm for learning hidden Markov models. *Journal of Computer and System Sciences* **78** 1460–1480.

KLEIBERGEN, F. and PAAP, R. (2006). Generalized reduced rank tests using the singular value decomposition. *Journal of econometrics* **133** 97–126.
LAMBERT, M. F., WHITING, J. P. and METCALFE, A. V. (2003). A non-parametric hidden Markov model for climate state identification. *Hydrology and Earth System Sciences Discussions* **7** 652–667.

LANGROCK, R., KNEIB, T., SOHN, A. and DERUITER, S. L. (2015). Nonparametric inference in hidden Markov models using P-splines. *Biometrics* **71** 520–528.

LE GLAND, F. and MEVEL, L. (2000). Exponential forgetting and geometric ergodicity in hidden Markov models. *Mathematics of Control, Signals and Systems* **13** 63–93.

LEFÈVRE, F. (2003). Non-parametric probability estimation for HMM-based automatic speech recognition. *Computer Speech & Language* **17** 113–136.

LEHÉRICY, L. (2015). Estimation adaptative non paramétrique pour les modèles à chaîne de Markov cachée. Mémoire de M2, Orsay.

MASSART, P. (2007). Concentration inequalities and model selection. In *Lecture Notes in Mathematics*, **1896** Springer, Berlin.

PAULIN, D. (2013). Concentration inequalities for Markov chains by Marton couplings. *arXiv preprint arxiv:1212.2015v2*.

ROBIN, J.-M., BONHOMME, S. and JOCHMANS, K. (2014). Estimating Multivariate Latent-Structure Models.

ROBIN, J.-M. and SMITH, R. J. (2000). Tests of rank. *Econometric Theory* **16** 151–175.

SHANG, L. and CHAN, K.-P. (2009). Nonparametric discriminant HMM and application to facial expression recognition. In *Computer Vision and Pattern Recognition, 2009. CVPR 2009. IEEE Conference on* 2090–2096. IEEE.

STEWART, G. and SUN, J.-G. (1990). Matrix Perturbation Theory (Computer Science and Scientific Computing).

VAN HAVRE, Z., ROUSSEAU, J., WHITE, N. and MENGERSEN, K. (2016). Overfitting hidden Markov models with an unknown number of states. *arXiv preprint arXiv:1602.02466*.

VOLANT, S., BÉRARD, C., MARTIN-MAGNIETTE, M.-L. and ROBIN, S. (2014). Hidden Markov models with mixtures as emission distributions. *Statistics and Computing* **24** 493–504.

YAU, C., PAPASPILIΟPOULΟS, O., ROBERTS, G. O. and HOLMES, C. (2011). Bayesian non-parametric hidden Markov models with applications in genomics. *Journal of the Royal Statistical Society: Series B (Statistical Methodology)* **73** 37–57.
# Appendix A: Spectral algorithm

**Algorithm 1:** Spectral estimation of HMM parameters (de Castro, Gassiat and Lacour (2016), de Castro, Gassiat and Le Corff)

**Data:** An observed chain $(Y_1, \dots, Y_n)$ and an order $K$.

**Result:** Spectral estimators $\hat{\pi}$, $\hat{Q}$ and the estimators $(\hat{f}_{M,k})_{k \in \mathcal{X}}$ of $(f_k^*)_{k \in \mathcal{X}}$ in $\mathfrak{P}_M$ (equipped with an orthonormal basis $\Phi_M = (\varphi_1, \dots, \varphi_M)$).

[Step 1] Consider the following empirical estimators: for any $a, b, c$ in $\{1, \dots, M\}$,

* $\hat{\mathbf{L}}_M(a) := \frac{1}{n} \sum_{s=1}^n \varphi_a(Y_1^{(s)})$,

* $\hat{\mathbf{M}}_M(a, b, c) := \frac{1}{n} \sum_{s=1}^n \varphi_a(Y_1^{(s)}) \varphi_b(Y_2^{(s)}) \varphi_c(Y_3^{(s)})$,

* $\hat{\mathbf{N}}_M(a, b) := \frac{1}{n} \sum_{s=1}^n \varphi_a(Y_1^{(s)}) \varphi_b(Y_2^{(s)})$,

* $\hat{\mathbf{P}}_M(a, c) := \frac{1}{n} \sum_{s=1}^n \varphi_a(Y_1^{(s)}) \varphi_c(Y_3^{(s)})$.

[Step 2] Let $\hat{\mathbf{U}}$ be the $M \times K$ matrix of orthonormal right singular vectors of $\hat{\mathbf{P}}_M$ corresponding to its top $K$ singular values.

[Step 3] Form the matrices $\hat{\mathbf{B}}(b) := (\hat{\mathbf{U}}^\top \hat{\mathbf{P}}_M \hat{\mathbf{U}})^{-1} \hat{\mathbf{U}}^\top \hat{\mathbf{M}}_M(\cdot, b, \cdot) \hat{\mathbf{U}}$ for all $b \in \{1, \dots, M\}$.

[Step 4] Set $\Theta$ a $(K \times K)$ uniformly drawn random unitary matrix and form the matrices $\hat{\mathbf{C}}(k) := \sum_{b=1}^M (\hat{\mathbf{U}}\Theta)(b, k) \hat{\mathbf{B}}(b)$ for all $k \in \{1, \dots, K\}$.

[Step 5] Compute $\hat{\mathbf{R}}$ a $(K \times K)$ unit Euclidean norm columns matrix that diagonalizes the matrix $\hat{\mathbf{C}}(1): \hat{\mathbf{R}}^{-1} \hat{\mathbf{C}}(1) \hat{\mathbf{R}} = \text{Diag}(\hat{\Lambda}(1, 1), \dots, \hat{\Lambda}(1, K))$.

[Step 6] Set $\hat{\Lambda}(k, k') := (\hat{\mathbf{R}}^{-1} \hat{\mathbf{C}}(k) \hat{\mathbf{R}})(k', k')$ for all $k, k' \in \mathcal{X}$ and $\hat{\mathbf{O}}_M := \hat{\mathbf{U}}\Theta\hat{\Lambda}$.

[Step 7] Consider the emission distributions estimator $\hat{\mathbf{f}} := (\hat{f}_{M,k})_{k \in \mathcal{X}}$ defined by $\hat{f}_{M,k} := \sum_{m=1}^M \hat{\mathbf{O}}_M(m, k)\varphi_m$ for all $k \in \mathcal{X}$.

[Step 8] Set $\hat{\pi} := \Pi_{\Delta_K}((\hat{\mathbf{U}}^\top \hat{\mathbf{O}}_M)^{-1} \hat{\mathbf{U}}^\top \hat{\mathbf{L}}_M)$ where $\Pi_{\Delta_K}$ denotes the projection onto the simplex in dimension $K$.

[Step 9] Consider the transition matrix estimator:

$$ \hat{\mathbf{Q}} := \Pi_{\text{TM}}((\hat{\mathbf{U}}^\top \hat{\mathbf{O}}_M \text{Diag}\hat{\pi})^{-1} \hat{\mathbf{U}}^\top \hat{\mathbf{N}}_M \hat{\mathbf{U}} (\hat{\mathbf{O}}_M^\top \hat{\mathbf{U}})^{-1}), $$

where $\Pi_{\text{TM}}$ denotes the projection onto the convex set of transition matrices, and define $\hat{\pi}$ as the stationary distribution of $\hat{\mathbf{Q}}$.
# Appendix B: Proofs of the oracle inequalities

## B.1. Proof of Theorem 7

Let $K \le n$ and $M \le n$. Then

$$ \begin{aligned} \gamma_n(\hat{g}) + \text{pen}(n, \hat{M}, \hat{K}_{1.s.}) &\le \gamma_n(\hat{g}_{K,M}) + \text{pen}(n, M, K) \\ &\le \gamma_n(g_{K,M}^*) + \text{pen}(n, M, K) \end{aligned} $$

where the first inequality comes from the definition of $(\hat{K}_{1.s.}, \hat{M})$ and the second from the definition of $\hat{g}_{K,M}$. Therefore,

$$ \gamma_n(\hat{g}) - \gamma_n(g_{K,M}^*) \le \text{pen}(n, M, K) - \text{pen}(n, \hat{M}, \hat{K}_{1.s.}). $$

By definition of $\nu$ (equation 4),

$$ \gamma_n(t_1) - \gamma_n(t_2) = \|t_1 - g^*\|_2^2 - \|t_2 - g^*\|_2^2 - 2\nu(t_1 - t_2) $$

so that

$$ \|\hat{g} - g^*\|_2^2 \le \|g_{K,M}^* - g^*\|_2^2 + \text{pen}(n, M, K) - \text{pen}(n, \hat{M}, \hat{K}_{1.s.}) + 2\nu(\hat{g}_{\hat{M}, \hat{K}_{1.s.}} - g_{K,M}^*) $$

Now we want to control the $\nu$ term. By linearity,

$$ \nu(\hat{g}_{\hat{K}_{1.s.}, \hat{M}} - g_{K,M}^*) = \nu(\hat{g}_{\hat{K}_{1.s.}, \hat{M}} - g^*) + \nu(g^* - g_{K,M}^*) $$

Using the definition of $Z_{K,M}$ (equation 5), we get that

$$ \begin{cases} |\nu(\hat{g}_{\hat{K}_{1.s.}, \hat{M}} - g^*)| \le Z_{\hat{K}_{1.s.}, \hat{M}}(g^*)(\|\hat{g}_{\hat{K}_{1.s.}, \hat{M}} - g^*\|_2^2 + x_{\hat{K}_{1.s.}, \hat{M}}^2) \\ |\nu(g_{K,M}^* - g^*)| \le Z_{K,M}(g^*)(\|g_{K,M}^* - g^*\|_2^2 + x_{K,M}^2) \end{cases} $$

so that, using Lemma 16, for all $n \ge n_0$ and $x > 0$, with probability larger than $1 - e^{-x}$, for all $M \le n$ and $K \le n$,

$$ |\nu(\hat{g}_{\hat{K}_{1.s.}, \hat{M}} - g_{K,M}^*)| \le \frac{1}{4}\|\hat{g} - g^*\|_2^2 + \frac{1}{4}\|g_{K,M}^* - g^*\|_2^2 + A\frac{x}{n} + \frac{1}{2}\text{pen}(n, \hat{M}, \hat{K}_{1.s.}) + \frac{1}{2}\text{pen}(n, M, K) $$

so that

$$ \|\hat{g} - g^*\|_2^2 \le \|g_{K,M}^* - g^*\|_2^2 + 2\text{pen}(n, M, K) + \frac{1}{2}\|\hat{g} - g^*\|_2^2 + \frac{1}{2}\|g_{K,M}^* - g^*\|_2^2 + 2A\frac{x}{n}, $$
which means that

$$ \frac{1}{2} \|\hat{g} - g^*\|_2^2 \le \frac{3}{2} \|g_{K,M}^* - g^*\|_2^2 + 2\text{pen}(n, M, K) + 2A \frac{x}{n} $$

and finally

$$ \|\hat{g} - g^*\|_2^2 \le 4 \inf_{K \le n, M \le n} \{\|g_{K,M}^* - g^*\|_2^2 + \text{pen}(n, M, K)\} + 4A \frac{x}{n} $$

which is the expected inequality.

## B.2. Proof of equation 1

First, decompose the difference in three terms.

$$ \|g^{\pi_1, \mathbf{Q}_1, \mathbf{f}_1} - g^{\pi_2, \mathbf{Q}_2, \mathbf{f}_2}\|_2 \le \|g^{\pi_1, \mathbf{Q}_1, \mathbf{f}_1} - g^{\pi_2, \mathbf{Q}_1, \mathbf{f}_1}\|_2 + \|g^{\pi_2, \mathbf{Q}_2, \mathbf{f}_1} - g^{\pi_2, \mathbf{Q}_2, \mathbf{f}_1}\|_2 \\ + \|g^{\pi_2, \mathbf{Q}_2, \mathbf{f}_1} - g^{\pi_2, \mathbf{Q}_2, \mathbf{f}_2}\|_2 $$

Then we can control each term separately. Let $(\varphi_m)_{m \in \mathbb{N}^*}$ be an orthonormal basis of $\cup_M \mathfrak{P}_M$.

$$ \begin{aligned} \|g^{\pi_1, \mathbf{Q}, \mathbf{f}} - g^{\pi_2, \mathbf{Q}, \mathbf{f}}\|_2^2 &= \left\| \sum_{\mathbf{k} \in \mathcal{X}^L} (\pi_1 - \pi_2)_{k_1} \mathbf{Q}_{k_1, k_2} \cdots \mathbf{Q}_{k_{L-1}, k_L} \bigotimes_{i=1}^L f_{k_i} \right\|_2^2 \\ &= \sum_{\mathbf{m} \in (\mathbb{N}^*)^L} \left( \sum_{\mathbf{k} \in \mathcal{X}^L} (\pi_1 - \pi_2)_{k_1} \mathbf{Q}_{k_1, k_2} \cdots \mathbf{Q}_{k_{L-1}, k_L} \prod_{i=1}^L \langle f_{k_i}, \varphi_{m_i} \rangle \right)^2 \\ &\le \sum_{\mathbf{k} \in \mathcal{X}^L} (\pi_1 - \pi_2)_{k_1}^2 \mathbf{Q}_{k_1, k_2} \cdots \mathbf{Q}_{k_{L-1}, k_L} \\ &\quad \times \sum_{\mathbf{k}' \in \mathcal{X}^L} \mathbf{Q}_{k_1', k_2'} \cdots \mathbf{Q}_{k_{L-1}', k_L'} \prod_{i=1}^L \sum_{m_i \in \mathbb{N}^*} \langle f_{k_i'}, \varphi_{m_i} \rangle^2 \end{aligned} $$

using Cauchy-Schwarz inequality. Then, since $\sum_{m_i \in \mathbb{N}^*} \langle f_{k_i'}, \varphi_{m_i} \rangle^2 = \|f_{k_i'}\|_2^2 \le C_{\mathcal{F},2}^2$ by [HF] and $\mathbf{Q}$ is a transition matrix, we get that

$$ \|g^{\pi_1, \mathbf{Q}, \mathbf{f}} - g^{\pi_2, \mathbf{Q}, \mathbf{f}}\|_2^2 \le KC_{\mathcal{F},2}^{2L} \|\pi_1 - \pi_2\|^2 $$

A similar decomposition leads to

$$ \|g^{\pi, \mathbf{Q}_1, \mathbf{f}} - g^{\pi, \mathbf{Q}_2, \mathbf{f}}\|_2^2 \le (L-1)KC_{\mathcal{F},2}^{2L} \|\mathbf{Q}_1 - \mathbf{Q}_2\|_F^2 $$

and

$$ \|g^{\pi, \mathbf{Q}, \mathbf{f}_1} - g^{\pi, \mathbf{Q}, \mathbf{f}_2}\|_2^2 \le LKC_{\mathcal{F},2}^{2(L-1)} \sum_{k \in \mathcal{X}} \|(\mathbf{f}_1)_k - (\mathbf{f}_2)_k\|_2^2 $$

These inequalities remain true if the states of the second set of parameters are swapped. Then, we use that $C_{\mathcal{F},2} \ge 1$ by [HF] to conclude.
## B.3. Proof of Lemma 8

In the following, we will identify the quadratic form $M$ derived from the second order expansion of $x \mapsto \mathfrak{N}(x)$ and its matrix. Likewise, we will identify the quadratic form $M_{\mathfrak{N}}$ derived from the second order expansion of $x \mapsto \mathfrak{N}(I_{\mathfrak{N}}(x))$ with its matrix. Without loss of generality, one can assume $L = 3$.

**Choice of parameters and expression of $M$.** Let $\pi \in \Delta_{K^*}$ be the uniform distribution on $\mathcal{X}$, $\mathbf{Q} = \text{Id}_{K^*}$ and $\mathbf{f}$ such that $\langle f_i, f_j \rangle = F \mathbf{1}_{i=j}$ for some constant $F > 0$. For instance, the $f_i$'s are $F$ times the indicating functions of distinct measurable sets with same measure $\frac{1}{F}$ for $\mu$. In that case, $(f_i/\sqrt{F})_i$ is an orthonormal basis, and the quantity $g^{\pi+p,\mathbf{Q}+q,\mathbf{f}+Af} - g^{\pi,\mathbf{Q},\mathbf{f}}$ can be broken down into three order one terms in $p, q$ and $A$:

* the term in $p$: $\sum_i p_i f_i \otimes f_i \otimes f_i$;

* the term in $q$: $\sum_{i,k} q(i,k) f_i \otimes (f_i + f_k) \otimes f_k$;

* the term in $A$: $\sum_i ((Af)_i \otimes f_i \otimes f_i + f_i \otimes (Af)_i \otimes f_i)$.

Now we can make the list of all second-order terms in the expansion of the quantity $\|g^{\pi+p,\mathbf{Q}+q,\mathbf{f}+Af} - g^{\pi,\mathbf{Q},\mathbf{f}}\|_2^2$:

* $p$ and $p$: $F^3 \sum_i p_i^2$;

* $p$ and $q$: $2F^3 \sum_i p_i q(i, i)$;

* $p$ and $A$: $3F^3 \sum_i p_i A_{i,i}$;

* $q$ and $q$: $2F^3 \sum_{i,k} q(i,k)^2 + 2F^3 \sum_i q(i,i)^2$;

* $q$ and $A$: $F^3 \sum_{i,k} q(i,k) A_{i,k} + F^3 \sum_{i,k} q(i,k) A_{i,k} + 4F^3 \sum_i q(i,i) A_{i,i}$;

* $A$ and $A$: $6F^3 \sum_i A_{i,i}^2 + 3F^3 \sum_{i,k} A_{i,k}^2$.

We can now write the matrix $M$. In order to clarify the structure of this matrix, let us swap the components of the parameters $(p, q, A)$ and consider the new parameters $(A_{\text{diag}}, A_{\text{else}}, p, q_{\text{diag}}, q_{\text{else}})$, where $A_{\text{diag}}$ (resp. $q_{\text{diag}}$) is a vector of size $K^*$ containing the diagonal coefficients of $A$ (resp. $q$) and $A_{\text{else}}$ (resp. $q_{\text{else}}$) contains its other coefficients. Then the matrix is:

$$ M_{\text{swapped}} = F^3 \begin{pmatrix} 9\text{Id}_{K^*} & 0 & 3\text{Id}_{K^*} & 6\text{Id}_{K^*} & 0 \\ 0 & 3\text{Id}_{K^*(K^*-1)} & 0 & 0 & X \\ 3\text{Id}_{K^*} & 0 & \text{Id}_{K^*} & 2\text{Id}_{K^*} & 0 \\ 6\text{Id}_{K^*} & 0 & 2\text{Id}_{K^*} & 4\text{Id}_{K^*} & 0 \\ 0 & X & 0 & 0 & 2\text{Id}_{K^*(K^*-1)} \end{pmatrix}, $$

where $X[(A_{i,j})_{i \neq j}] = (A_{i,j} + A_{j,i})_{i \neq j}$.

**Kernel of $M$.** Subtracting the first block of lines to the third and fourth blocks of lines and then the first block of columns to the third and fourth blocks of columns does
not change the rank and leads to the matrix

$$F^3 \begin{pmatrix} 9\mathrm{Id}_K & 0 & 0 & 0 & 0 \\ 0 & 3\mathrm{Id}_{K(K-1)} & 0 & 0 & X \\ 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ 0 & X & 0 & 0 & 2\mathrm{Id}_{K(K-1)} \end{pmatrix}$$

Thus $\dim(\mathrm{Ker}(M)) \ge 2K$, where $\mathrm{Ker}(M)$ is the kernel of $M$ and $\dim$ denotes the dimension. If one takes away the lines and columns corresponding to $p$ and $q_{\mathrm{diag}}$, one gets the matrix

$$F^3 \begin{pmatrix} 9\mathrm{Id}_{K^*} & 0 & 0 & 0 & 0 \\ 0 & 3\mathrm{Id}_{K^*(K^*-1)} & X & 0 & 0 \\ 0 & X & 2\mathrm{Id}_{K^*(K^*-1)} & 0 & 0 \end{pmatrix}.$$

This matrix is invertible. Therefore, $\dim(\mathrm{Ker}(M)) = 2K$. Now, for all $i \in [K^*]$, let $e_i^1$ and $e_i^2$ be the vectors defined as

$$\left\{ \begin{array}{ll} (e_i^1)_{p_k} = 0 & \text{for all } k \\ (e_i^1)_{A_{k,l}} = 0 & \text{for all } (k,l) \neq (i,i) \\ (e_i^1)_{q(k,l)} = 0 & \text{for all } (k,l) \neq (i,i) \\ (e_i^1)_{A_{i,i}} = 2 & \\ (e_i^1)_{q(i,i)} = -3 & \end{array} \right.$$

and

$$\left\{ \begin{array}{ll} (e_i^2)_{p_k} = 0 & \text{for all } k \neq i \\ (e_i^2)_{A_{k,l}} = 0 & \text{for all } (k,l) \neq (i,i) \\ (e_i^2)_{q(k,l)} = 0 & \text{for all } (k,l) \\ (e_i^2)_{A_{i,i}} = 1 & \\ (e_i^2)_{p_i} = -3 & \end{array} \right.$$

One can easily check that these vectors are linearly independent and are all in $\mathrm{Ker}(M)$. Thus, they are a basis of the kernel of $M$: $\mathrm{Ker}(M) = \mathrm{Span}(\{e_i^1, e_i^2 | i \in [K]\})$.

**Nondegeneracy of $M$ restricted on $\mathfrak{C}$.** Since $M$ is symmetric, and thus diagonalisable in an orthonormal basis,

$$M = P_{\mathrm{Ker}(M)^{\perp}}^{\top} M_{\mathrm{Ker}(M)^{\perp}} P_{\mathrm{Ker}(M)^{\perp}} \quad (6)$$

where $P_{\mathrm{Ker}(M)^{\perp}}$ is the orthogonal projection on the space of vectors orthogonal to $\mathrm{Ker}(M)$ and $M_{\mathrm{Ker}(M)^{\perp}}$ is a symmetric positive definite matrix, whose smallest eigenvalue will be written $c_0$ in the following. The last step to conclude will require the two following lemmas:

**Lemma 18.** $\mathrm{Ker}(M) \cap \mathfrak{C} = \{0\}$.
**Proof.** Let $x \in \mathrm{Ker}(M) \cap \mathfrak{C}$, then $x = \sum_i (\lambda_i e_i^1 + \mu_i e_i^2)$ because $(e_i^1, e_i^2)_i$ is a basis of $\mathrm{Ker}(M)$. Since $x \in \mathfrak{C}$, one gets $\lambda_i = 0$ for all $i$ because of the conditions on $q$. Then, the conditions on $A$ imply $\mu_i = 0$ for all $i$, so that $x = 0$. $\square$

**Lemma 19.** There exists a constant $\kappa > 0$ such that for all $x \in \mathfrak{C}$,

$$ \|P_{\mathrm{Ker}(M)^{\perp}} x\|_{F}^{2} \geq \kappa \|x\|_{F}^{2}. \qquad (7) $$

**Proof.** $P_{\mathrm{Ker}(M)^{\perp}}$ is continuous. By compacity, the quantity

$$ \kappa := \inf\{\|P_{\mathrm{Ker}(M)^{\perp}} x\|_{F}^{2} | x \in \mathfrak{C}, \|x\|_{F}^{2} = 1\} $$

is reached for some $x_0 \in \mathfrak{C} \setminus \{0\}$. If $\kappa = 0$, then $x_0 \in \mathrm{Ker}(M)$, but this is impossible because of Lemma 18. Therefore $\kappa > 0$. $\square$

Finally, for all $x \in \mathfrak{C}$,

$$ \begin{aligned} x^{\top} M x &= x^{\top} P_{\mathrm{Ker}(M)^{\perp}}^{\top} M_{\mathrm{Ker}(M)^{\perp}} P_{\mathrm{Ker}(M)^{\perp}} x \\ &= (P_{\mathrm{Ker}(M)^{\perp}} x)^{\top} M_{\mathrm{Ker}(M)^{\perp}} (P_{\mathrm{Ker}(M)^{\perp}} x) \\ &\geq c_0 \|P_{\mathrm{Ker}(M)^{\perp}} x\|_{F}^{2} \\ &\geq c_0 \kappa \|x\|_{F}^{2}. \end{aligned} $$

Therefore, the quadratic form with matrix $M$ is nondegenerate on $\mathfrak{C}$, which shows that $H$ is non-zero for these $(\pi, \mathbf{Q}, \mathbf{f})$. To conclude, observe that $H$ is continuous and that our choice of parameters can be approximated by parameters satisfying $[\mathbf{H}\mathbf{X}]$ and $[\mathbf{H}\mathbf{d}\mathbf{A}]$.

## B.4. Proof of Theorem 9

First, assume that the quadratic form obtained from the second order expansion of

$$ \mathcal{D} : (p, q, \mathbf{h}) \in \{(p, q, \mathbf{A}f) \mid (p, q, A) \in \mathfrak{C}\} \mapsto \|g^{\pi+p, \mathbf{Q}+q, \mathbf{f}+\mathbf{h}} - g^{\pi, \mathbf{Q}, \mathbf{f}}\|_{2}^{2} $$

is nondegenerate. Then, a careful reading of the proof of Theorem 8 of de Castro, Gassiat and Lacour (2016) shows that their result can be adapted to our setting and leads to the desired minoration.

Thus, what we need to show is that $[\mathbf{H}\mathbf{d}\mathbf{e}\mathbf{t}]$ (which implied the nondegeneracy of the quadratic form from $\mathfrak{N}$) implies the nondegeneracy of the quadratic form from $\mathcal{D}$ (the trick being that $\mathcal{D}$ takes $\mathbf{h} = \mathbf{A}f$ as parameter while $\mathfrak{N}$ takes $A$). Assume $[\mathbf{H}\mathbf{d}\mathbf{e}\mathbf{t}]$, then there exists $c_0 > 0$ such that

$$ \mathrm{Quad}_{\mathfrak{N}}(p, q, A) \geq c_0 (\|p\|_2^2 + \|\mathbf{Q}\|_F^2 + \|A\|_F^2) $$

with the notation $\mathrm{Quad}_{\mathfrak{N}}$ referring to the quadratic form in the second order expansion of $\mathfrak{N}$.
Since [HidA] holds, $\mathbf{f}$ is linearly independent, so that the application $J: A \in \mathbb{R}^{K^* \times K^*} \to Af \in \text{Span}(\mathbf{f})^{K^*}$ is invertible. Thus, $\mathbf{h} \mapsto \sum_{i \in \mathcal{X}} \|h_i\|_2^2$ and $\mathbf{h} \mapsto \|J^{-1}(\mathbf{h})\|_F^2$ are two norms on the same finite-dimensional linear space $\text{Span}(\mathbf{f})^{K^*}$, so that they are equivalent. In particular, there exists a constant $c_1 \le 1$ such that $\|J^{-1}(\mathbf{h})\|_F^2 \ge c_1 \sum_{i \in \mathcal{X}} \|h_i\|_2^2$. Therefore,

$$ \begin{aligned} \text{Quad}_{\mathcal{D}}(p, q, \mathbf{h}) &= \text{Quad}_{\mathcal{N}}(p, q, J^{-1}(\mathbf{h})) \\ &\ge c_0 c_1 \left( \|p\|_2^2 + \|\mathbf{Q}\|_F^2 + \sum_{i \in \mathcal{X}} \|h_i\|_2^2 \right), \end{aligned} $$

which is what we wanted to prove.

# Appendix C: Proof of the control of $Z_{K,M}$

This section contains the proof of Lemma 16.

## C.1. Concentration inequality on $Z_{K,M}(s)$

Define for all $\sigma > 0$ the sets

$$ B_{\sigma} = \{t \in S_{K,M}, C_{\mathcal{F},\infty}^{L/2} \|t - s_{K,M}\|_2 \le \sigma\} $$

Let $d_{g^*}$ be the semi-distance defined by $d_{g^*}^2(t_1, t_2) = \mathbb{E}[(t_1 - t_2)^2(Z_1)] = \int g^*(t_1 - t_2)^2 d\mu^{\otimes L}$, and $d_2$ the distance induced by the norm on $\mathbf{L}^2(\mathcal{Y}^L, \mu^{\otimes L})$.

Let $N(\epsilon, A, d) = e^{H(\epsilon, A, d)}$ denote the minimal cardinality of a covering of $A$ by brackets of size $\epsilon$ for the semi-distance $d$, that is by sets $[t_1, t_2] = \{t: \mathcal{Y}^L \to \mathbb{R}, t_1(\cdot) \le t(\cdot) \le t_2(\cdot)\}$ such that $d(t_1, t_2) \le \epsilon$. $H(\cdot, A, d)$ is called the bracketing entropy of $A$ for the semi-distance $d$.

The following lemma is a Bernstein-like inequality that follows from Paulin (2013), Theorem 2.4:

**Lemma 20.** Let $t$ be a real valued and measurable bounded function on $\mathcal{Y}^L$. Let $V = \mathbb{E}[t^2(Z_1)]$. There exists a positive constant $c^*$ depending only on $\mathbf{Q}^*$ and $L$ such that for all $0 \le \lambda \le 1/(2\sqrt{2c^*}\|t\|_{\infty})$ and for all $n \in \mathbb{N}$:

$$ \log \mathbb{E} \exp \left[ \lambda \sum_{s=1}^{n} (t(Z_s) - \mathbb{E}t(Z_s)) \right] \le \frac{2nc^*V\lambda^2}{1 - 2\sqrt{2c^*}\|t\|_{\infty}\lambda} $$

The following lemma is an extension of Theorem 6.8 from Massart (2007) and allows to obtain a concentration inequality on the supremum on all functions of a class when one can control its bracketing entropy.
**Lemma 21.** Let $\Xi$ be some measurable space, $(\xi_i)_{1\le i\le n}$ a sequence of random variables on $\Xi$, $\mathcal{T}$ some countable class of real valued and measurable functions on $\Xi$. Assume that there exists some positive numbers a and b such that for all $t \in \mathcal{T}$, $\|t\|_{\infty} \le b$ and $\sup_i \mathbb{E}[t^2(\xi_i)] \le a^2$.

Assume also that there exists some constant $C_{\xi} \ge 1/4$ such that for all $0 \le \lambda \le 1/(2\sqrt{2C_{\xi}b})$ and for all $t \in \mathcal{T}$:

$$ \log \mathbb{E} \exp \left[ \lambda \sum_{s=1}^{n} (t(\xi_s) - \mathbb{E}t(\xi_s)) \right] \le \frac{2nC_{\xi}a^2\lambda^2}{1 - 2\sqrt{2C_{\xi}b\lambda}} \quad (8) $$

Assume furthermore that for any positive number $\delta$, there exists some finite set $\mathcal{B}_{\delta}$ of brackets covering $\mathcal{T}$ such that for any bracket $[t_1, t_2] \in \mathcal{B}_{\delta}$, $\|t_1 - t_2\|_{\infty} \le b$ and $\sup_i \mathbb{E}[(t_1 - t_2)^2(\xi_i)] \le \delta^2$. Let $e^{H(\delta)}$ denote the minimal cardinality of such a covering. Then, there exists a numerical constant $\kappa > 0$ such that for any measurable set $A$ such that $\mathbb{P}(A) > 0$,

$$ \mathbb{E}^A \left( \sup_{t \in \mathcal{T}} \sum_{s=1}^{n} (t(\xi_s) - \mathbb{E}t(\xi_s)) \right) \le \kappa C_{\xi} \left[ E + a \sqrt{n \log \left( \frac{1}{\mathbb{P}(A)} \right)} + b \log \left( \frac{1}{\mathbb{P}(A)} \right) \right] $$

where

$$ E = \sqrt{n} \int_{0}^{a} \sqrt{H(u) \wedge ndu} + (b + a)H(a) $$

and for any measurable random variable $W$, $\mathbb{E}^A[W] = \mathbb{E}[W1_A]/\mathbb{P}(A)$.

**Comment.** The assumption $C_{\xi} \ge 1/4$ is only used to factorise the upper bound by $C_{\xi}$. Without it, the upper bound would be

$$ \kappa' \left[ E + a \sqrt{C_{\xi} n \log \left( \frac{1}{\mathbb{P}(A)} \right)} + b C_{\xi} \log \left( \frac{1}{\mathbb{P}(A)} \right) \right] $$

In practice, this assumption doesn't cost anything: if equation (8) holds for some constant $C_{\xi}$, then it holds for any constant $C' \ge C_{\xi}$.

We will apply this lemma to $\Xi = \mathcal{Y}^L$ and $\xi_i = Z_i$. Using Lemma 20, equation (8) holds with $C_{\xi} = \max(c^*, 1/4)$.

Take $\mathcal{T} = (B_{\sigma} - s_{K,M}) \cup (-B_{\sigma} + s_{K,M})$, so that $\sup_{t \in \mathcal{T}} \nu(t) = \sup_{t \in B_{\sigma}} |\nu(t - s_{K,M})|$. Then, one can check using Lemma 28 that the assumptions $\|t\|_{\infty} \le b$ and $\sup_i \mathbb{E}[t^2(\xi_i)] \le a^2$ hold with

* $b = 2C_{\mathcal{F},\infty}^L$

* $a = 2 \min(\sigma, C_{\mathcal{F},\infty}^{L/2} C_{\mathcal{F},2}^L)$

and $H(u) \le \log(2) + H(u, B_{\sigma} - s_{K,M}, d_{g^*})$.

We can do without assuming $\mathcal{T}$ to be countable. Indeed, $\nu$ is continuous on $\mathcal{T}$ equipped with the infinity norm. This entails that the supremum of $\nu$ over $\mathcal{T}$ is equal to the
supremum of $\nu$ over any dense subset of $(\mathcal{T}, \|\cdot\|_{\infty})$. Since $\mathcal{T} \subset (\mathfrak{P}_M)^{\otimes L}$, which is a finite dimensional metric linear space for the infinity norm, it is separable. Therefore, without loss of generality, we can get rid of the countability assumption on $\mathcal{T}$.

Rewriting these results, we get the following lemma:

**Lemma 22.** There exists a constant $C^*$ depending only on $\mathbf{Q}^*$ and $L$ such that for all $\sigma > 0$, for all measurable $A$ such that $\mathbb{P}(A) > 0$:

$$ \mathbb{E}^A \left( \sup_{t \in B_\sigma} |\nu(t - s_{K,M})| \right) \le C^* \left[ \frac{E}{n} + \sigma \sqrt{\frac{1}{n} \log \left( \frac{1}{\mathbb{P}(A)} \right)} + \frac{2C_{\mathcal{F},\infty}^L}{n} \log \left( \frac{1}{\mathbb{P}(A)} \right) \right] $$

where

$$ E = \sqrt{n} \int_0^\sigma \sqrt{H(u, B_\sigma - s_{K,M}, d_{g^*}) \wedge ndu} + \log(2)\sigma\sqrt{n} + 2(C_{\mathcal{F},\infty}^L + C_{\mathcal{F},\infty}^{L/2} C_{\mathcal{F},2}^L)H(\sigma, B_\sigma - s_{K,M}, d_{g^*}) $$

The core of the proof consists in controlling the bracketing entropy in order to find a "good" function $\varphi$ and constants $C$ and $\sigma_{K,M}$ depending on $C_{\mathcal{F},2}$, $C_{\mathcal{F},\infty}$ and $L$ such that $x \mapsto \frac{\varphi(x)}{x}$ is nonincreasing and

$$ \forall \sigma \ge \sigma_{K,M} \quad E \le C\varphi(\sigma)\sqrt{n}. \qquad (9) $$

For ease of notation, we did not write the dependency of $C$ and $\varphi$ on $K$ and $M$.

Let us see how to conclude with such an inequality. We shall use the following result (lemma 4.23 from Massart (2007)).

**Lemma 23.** Let $S$ be some countable set, $u \in S$ and $a: S \mapsto \mathbb{R}_+$ such that $a(u) = \inf_{t \in S} a(t)$. Let $Z$ be some process indexed by $S$ and assume that $\sup_{t \in \mathcal{B}(\lambda)} Z(t) - Z(u)$ has finite expectation for any positive number $\lambda \ge 0$, where

$$ \mathbf{B}(\lambda) = \{t \in S, a(t) \le \lambda\} $$

Then, for any function $\phi$ on $\mathbb{R}_+$ such that $x \mapsto \phi(x)/x$ is nonincreasing on $\mathbb{R}_+$ and satisfies for some $\lambda_* \ge 0$ to

$$ \forall \lambda \ge \lambda_* \ge 0, \quad \mathbb{E} \left[ \sup_{t \in \mathcal{B}(\lambda)} Z(t) - Z(u) \right] \le \phi(\lambda) $$

one has for any $x \ge \lambda_*:$

$$ \mathbb{E} \left[ \sup_{t \in S} \left( \frac{Z(t) - Z(u)}{a(t)^2 + x^2} \right) \right] \le 4 \frac{\phi(x)}{x^2} $$
In our case,

$$
\left\{
\begin{array}{l}
S = S_{K,M} - s_{K,M} \\
u = s_{K,M} \\
a(t) = C_{\mathcal{F},\infty}^{L/2} \|t - s_{K,M}\|_2 \\
Z(t) = |\nu(t - s_{K,M})| \\
\lambda_*= \sigma_{K,M} \\
\phi(x) = C^* \left[ C \frac{\varphi(x)}{\sqrt{n}} + x \sqrt{\frac{1}{n} \log \left( \frac{1}{\mathbb{P}(A)} \right)} + \frac{2C_{\mathcal{F},\infty}^L}{n} \log \left( \frac{1}{\mathbb{P}(A)} \right) \right]
\end{array}
\right.
$$

With this choice of S, a and Z, this proposition holds even if S is not countable for the
same reason as in Lemma 22.

It follows that for all $x \ge \sigma_{K,M}$:

$$
\mathbb{E}^A \left[ \sup_{t \in S_{K,M}} \frac{|\nu(t - s_{K,M})|}{C_{\mathcal{F},\infty}^L \|t - s_{K,M}\|_2^2 + x^2} \right] \le 4 \frac{\phi(x)}{x^2},
$$

so that if $x_{K,M} \ge \frac{\sigma_{K,M}}{C_{\mathcal{F},\infty}^{L/2}}$:

$$
\mathbb{E}^A[Z_{K,M}(s)] \le 4 \frac{\phi(x_{K,M} C_{\mathcal{F},\infty}^{L/2})}{x_{K,M}^2}
$$

and then

$$
\begin{align*}
\mathbb{E}^A[Z_{K,M}(s)] &\le 4 \frac{C^*}{x_{K,M}^2} \left[ C \frac{\varphi(x_{K,M} C_{\mathcal{F},\infty}^{L/2})}{\sqrt{n}} + x_{K,M} C_{\mathcal{F},\infty}^{L/2} \sqrt{\frac{1}{n} \log \left( \frac{1}{\mathbb{P}(A)} \right)} \right. \\
&\qquad \left. + \frac{2C_{\mathcal{F},\infty}^L}{n} \log \left( \frac{1}{\mathbb{P}(A)} \right) \right] \\
&:= \psi \left( \log \left( \frac{1}{\mathbb{P}(A)} \right) \right)
\end{align*}
$$

Note that the function $\psi$ is nondecreasing. On the event $A = \{Z_{K,M}(s) \ge \psi(x)\}$,

$$
\psi(x) \le \mathbb{E}^A[Z_{K,M}(s)] \le \psi\left(\log\left(\frac{1}{\mathbb{P}(A)}\right)\right)
$$

so that $x \le \log \left( \frac{1}{\mathbb{P}(A)} \right)$ and finally $\mathbb{P}(A) \le e^{-x}$.

It follows that with probability $1 - e^{-z_{K,M}-z}$:

$$
Z_{K,M}(s) \le 4C^* \left[ C \frac{\varphi(x_{K,M} C_{\mathcal{F},\infty}^{L/2})}{x_{K,M}^2 \sqrt{n}} + C_{\mathcal{F},\infty}^{L/2} \sqrt{\frac{z_{K,M}+z}{x_{K,M}^2 n}} + 2C_{\mathcal{F},\infty}^L \frac{z_{K,M}+z}{x_{K,M}^2 n} \right] \quad (10)
$$

and the last step of the proof will be to choose the right $x_{K,M}$ and $z_{K,M}$ (see Section C.3).
## C.2. Control of the bracketing entropy

The goal of this section is to prove equation (9), that is to find $\varphi$, $C$ and $\sigma_{K,M}$ such that

$$ \forall \sigma \ge \sigma_{K,M} \qquad E \le C\varphi(\sigma)\sqrt{n}. $$

The bracketing entropy is invariant under translation and increasing with respect to the inclusion relation, so

$$ H(u, B_{\sigma} - s_{K,M}, d_{g^{*}}) = H(u, B_{\sigma}, d_{g^{*}}) \le H(u, S_{K,M}, d_{g^{*}}) $$

Using Lemma 28, we get that for all $t \in L^2(Y^L, \mathbb{R})$, $\int t^2 g^* d\mu \le C_{\mathcal{F},\infty}^L \|t\|_2^2$. Therefore, a bracket of size $u/C_{\mathcal{F},\infty}^{L/2}$ for $d_2$ is also a bracket of size $u$ for $d_{g^*}$, which implies that

$$ H(u, B_{\sigma} - s_{K,M}, d_{g^{*}}) \le H\left(\frac{u}{C_{\mathcal{F},\infty}^{L/2}}, S_{K,M}, d_2\right) \quad (11) $$

Let us now rewrite the definition of $S_{K,M}$:

$$ S_{K,M} = \left\{ \sum_{\mathbf{k} \in \{1, \dots, K\}^L} \pi_{k_1} \prod_{i=2}^{L} \mathbf{Q}_{k_{i-1}, k_i} \bigotimes_{i=1}^{L} f_{k_i}, \mathbf{Q} \in \mathcal{Q}_K, \pi \mathbf{Q} = \pi, \mathbf{f} \in (\mathcal{F} \cap \mathfrak{P}_M)^K \right\} \\ \subset \left\{ \sum_{\mathbf{k} \in \{1, \dots, K\}^L} \mu_{\mathbf{k}} \phi_{\mathbf{k}}, \mu \in \mathcal{U}, \phi \in \Phi \right\} $$

where

$$ \left\{ \begin{aligned} \mathcal{U} &= \left\{ (\pi_{k_1} \prod_{i=2}^{L} \mathbf{Q}_{k_{i-1}, k_i})_{k_1, \dots, k_L}, \mathbf{Q} \text{ transition matrix } K \times K, \pi \ge 0, \pi \in \mathbb{S}_{K-1} \right\} \\ \mathcal{F} &= \left\{ \bigotimes_{i=1}^{L} f_{k_i} \right\}_{k_1, \dots, k_L, \mathbf{f} \in (\mathcal{F} \cap \mathfrak{P}_M)^K \} \end{aligned} \right. $$

$\mathcal{U}$ is equipped with the distance $d_2(a, b) = (\sum_{\mathbf{k}} (b_{\mathbf{k}}^i - a_{\mathbf{k}}^i)^2)^{1/2}$. A bracket for $\mathcal{U}$ will be a set $[a, b] = \{c | \forall \mathbf{k} \in \{1, \dots, K\}^L, a_{\mathbf{k}} \le c_{\mathbf{k}} \le b_{\mathbf{k}}\}$.

$\Phi$ is equipped with the distance $d_{\infty,2}(u, v) = \max_{\mathbf{k}} \|v_{\mathbf{k}}^i - u_{\mathbf{k}}^i\|_2$. A bracket $\Phi$ will be a set $[u, v] = \{t | \forall \mathbf{k} \in \{1, \dots, K\}^L, u_{\mathbf{k}}(\cdot) \le t_{\mathbf{k}}(\cdot) \le v_{\mathbf{k}}(\cdot)\}$.

Controlling the bracketing entropy on each of these sets will allow to control the bracketing entropy of $S_{K,M}$. Let us start with them:

**Lemma 24.** There exists a bracket covering $\{[a^i, b^i]\}_{1 \le i \le N_{\mathcal{U}}(\epsilon)}$ of size $\epsilon$ of $\mathcal{U}$ for the distance $d_2$ with cardinality

$$ N_{\mathcal{U}}(\epsilon) \le \max \left( \frac{2LK^{L/2}}{\epsilon}, 1 \right)^{K^2-1} \quad (12) $$

such that for all $i$ and $\mathbf{k}$, $0 \le a_{\mathbf{k}}^i \le 1$.
**Lemma 25.** There exists a bracket covering $\{[u^i, v^i]\}_{1\le i\le N_\Phi(\epsilon)}$ of size $\epsilon$ of $\Phi$ for the distance $d_{\infty,2}$ of cardinality

$$N_{\Phi}(\epsilon) \le \max \left( \frac{L(4C_{\mathcal{F},2}M)^L}{\epsilon}, 1 \right)^{MK} \quad (13)$$

such that

$$\max_i \max_k \|v_k^i\|_2^2 \le (8M^2 C_{\mathcal{F},2}^2)^L.$$

Let us take such bracketings and consider the following set of brackets:

$$\left\{ \left[ \sum_k A_k^{i,j}, \sum_k B_k^{i,j} \right] \right\}_{1 \le i \le N_{\mathcal{U}}(\epsilon), 1 \le j \le N_{\Phi}(\epsilon)}$$

where

$$\forall y \in \mathcal{Y}^L, \quad \left\{ \begin{array}{l} A_k^{i,j}(y) = \min\{a_k^i u_k^j(y), b_k^i v_k^j(y)\} \\ B_k^{i,j}(y) = \max\{a_k^i u_k^j(y), b_k^i v_k^j(y)\} \end{array} \right. .$$

This set covers $S_{K,M}$: for all $\mu \in \mathcal{U}$, $\phi \in \Phi$, there exists $i \in \{1, \dots, N_{\mathcal{U}}(\epsilon)\}$ and $j \in \{1, \dots, N_{\Phi}(\epsilon)\}$ such that $\mu \in [a^i, b^i]$ and $\phi \in [u^j, v^j]$, and then by construction $\sum_k \mu_k \phi_k \in [\sum_k A_k^{i,j}, \sum_k B_k^{i,j}]$.

Let us now bound the size of these brackets. Let $[a, b] \in \{[a^i, b^i]\}_{1\le i\le N_{\mathcal{U}}(\epsilon)}$ and $[u, v] \in \{[u^i, v^i]\}_{1\le i\le N_{\Phi}(\epsilon)}$, then if one denotes by $[A, B]$ the corresponding bracket, there exists $(\sigma_k)_k \in \{-1, 1\}^{KL}$ such that:

$$\begin{aligned} \left\| \sum_k A_k - \sum_k B_k \right\|_2^2 &= \left\| \sum_k \sigma_k (b_k v_k - a_k u_k) \right\|_2^2 \\ &\le \left\| \sum_k |b_k v_k - a_k u_k| \right\|_2^2 \\ &\le K^L \sum_k \|a_k u_k - b_k v_k\|_2^2 \\ &= K^L \sum_k \|(a_k - b_k)v_k + a_k(u_k - v_k)\|_2^2 \\ &\le 2K^L \left( \sum_k \|(a_k - b_k)v_k\|_2^2 + \sum_k \|a_k(u_k - v_k)\|_2^2 \right) \\ &= 2K^L \left( \sum_k (a_k - b_k)^2 \|v_k\|_2^2 + \sum_k a_k^2 \|u_k - v_k\|_2^2 \right). \end{aligned}$$
Then, by definition of the brackets, $||u_k - v_k||_2^2 \le \epsilon^2$ and $\sum_k (a_k - b_k)^2 \le \epsilon^2$. In addition, we assumed $|a_k| \le 1$ and $||v_k||_2^2 \le (8M^2C_{\mathcal{F},2}^2)^L$ for all $k$, so that

$$ \| \sum_k \mathcal{A}_k - \sum_k \mathcal{B}_k \|_2^2 \le 2K^L \epsilon^2 ((8M^2C_{\mathcal{F},2}^2)^L + K^L), $$

which implies

$$ N(\epsilon, S_{K,M}, d_2) \le N_U \left( \frac{\epsilon}{\sqrt{2K^L(K^L + (8M^2C_{\mathcal{F},2}^2)^L)}} \right) \times N_{\Phi} \left( \frac{\epsilon}{\sqrt{2K^L(K^L + (8M^2C_{\mathcal{F},2}^2)^L)}} \right), \quad (14) $$

and finally by combining 11, 12, 13 and 14:

$$
\begin{align*}
H(u, B_{\sigma} - s_{K,M}, d_{g*}) &\le (K^2 - 1) \log \max \left( \frac{C_{\mathcal{F},\infty}^{L/2} \sqrt{2K^L(K^L + (8M^2C_{\mathcal{F},2}^2)^L)2LK^{L/2}}}{u}, 1 \right) \\
&\quad + MK \log \max \left( \frac{C_{\mathcal{F},\infty}^{L/2} \sqrt{2K^L(K^L + (8M^2C_{\mathcal{F},2}^2)^L)L(4C_{\mathcal{F},2}M)^L}}{u}, 1 \right) \\
&\le (MK + K^2 - 1) \log \max \left( \frac{C_{\mathcal{F},\infty}^{L/2} \sqrt{2(K^L + (8M^2C_{\mathcal{F},2}^2)^L)LK^L(4C_{\mathcal{F},2}M)^L}}{u}, 1 \right) \\
&\le (MK + K^2 - 1) \log \max \left( \frac{C_{\mathcal{F},\infty}^{L/2} \sqrt{2(n^L + (8C_{\mathcal{F},2}^2)^L n^{2L})nn^L(4C_{\mathcal{F},2})^L n^L}}{u}, 1 \right) \\
&\le (MK + K^2 - 1) \log \max \left( \frac{C_{\mathcal{F},\infty}^{L/2} 2(8C_{\mathcal{F},2}^2)^{L/2} n^L nn^L (4C_{\mathcal{F},2})^L n^L}{u}, 1 \right) \\
&\le (MK + K^2 - 1) \log \max \left( \frac{2(16C_{\mathcal{F},\infty}^{1/2} C_{\mathcal{F},2}^2)^L n^{3L+1}}{u}, 1 \right) \\
&\le (MK + K^2 - 1) \log \max \left( \frac{n^{6L}}{u}, 1 \right)
\end{align*}
$$

for $n$ large enough ($n \ge n_0 := 16C_{\mathcal{F},\infty}^{1/2} C_{\mathcal{F},2}^2$) because we assumed $M \le n$, $K \le n$, $L \le n$, $C_{\mathcal{F},2} \ge 1$ and $C_{\mathcal{F},\infty} \ge 1$. Thus, Lemma 29 implies that if we write $C_0 = \sqrt{\pi}$ and

$$ \varphi(\sigma) = C_0 \sigma \sqrt{MK + K^2 - 1} \left( 1 + \sqrt{\log \left( \max \left\{ \frac{n^{6L}}{\sigma}, 1 \right\} \right)} \right) $$
then for all $n \ge n_0$ and $\sigma > 0$,

$$ \left\{ \begin{array}{l} \sigma^2 H(\sigma, S_{K,M}, d_2) \le \varphi(\sigma)^2 \\ \displaystyle\int_0^\sigma \sqrt{H(u, S_{K,M}, d_2)} du \le \varphi(\sigma) \\ \log(2)\sigma \le \varphi(\sigma) \end{array} \right. $$

Let us now check that this function $\varphi$ satisfies equation (9). First, note that $x \mapsto \frac{\varphi(x)}{x}$ is nonincreasing, so that $x \mapsto \frac{\varphi(x)}{x^2}$ is also nonincreasing. Thus, we may define $\sigma_{K,M}$ as the unique solution of the equation $\varphi(x) = \sqrt{n}x^2$, and then for all $\sigma \ge \sigma_{K,M}$:

$$ H(\sigma, B_{\sigma} - s_{K,M}, d_{g^*}) \le \frac{\varphi(\sigma)^2}{\sigma^2} \le \frac{\varphi(\sigma)}{\sigma} \sigma \sqrt{n} = \varphi(\sigma) \sqrt{n} $$

Equation (9) follows immediately with $C = 2(1 + C_{\mathcal{F},\infty}^L + C_{\mathcal{F},\infty}^{L/2} C_{\mathcal{F},2}^L)$.

**Proof of Lemma 24** Let $\epsilon \in (0, 2)$.

We start with the family $\{[k/n, (k+1)/n], k \in \{0, \dots, n-1\}\}$ with $n$ an integer between $1/\epsilon$ and $2/\epsilon$, which gives a bracket covering of size $\epsilon$ of $[0, 1]$ with cardinality smaller than $2/\epsilon$. These brackets will be used to control each free component of $\mathbf{Q}$ and $\pi$, that is $K^2 - 1$ components.

More precisely, we define the following bracket set:

$$ \begin{aligned} & \{[A, B] \mid A_{\mathbf{k}} = \frac{1}{n^L} p_{k_1} \prod_{i=2}^{L} a_{k_{i-1}, k_i}, B_{\mathbf{k}} = \frac{1}{n^L} (p_{k_1} + 1) \prod_{i=2}^{L} (a_{k_{i-1}, k_i} + 1), \\ & \qquad p \in \{0, \dots, n-1\}^{K-1}, \sum_{k=1}^{K-1} p_k < n, p_K = n - \sum_{k=1}^{K-1} (p_k + 1), \\ & \qquad a \in \{0, \dots, n-1\}^{K \times (K-1)}, \forall i \in \{1, \dots, K\}, \sum_{k=1}^{K-1} a_{i,k} < n \text{ and} \\ & \qquad a_{i,K} = n - \sum_{k=1}^{K-1} (a_{i,k} + 1) \}. \end{aligned} $$

This set covers $\mathcal{U}$ and its cardinality is smaller than $(\frac{2}{\epsilon})^{K^2-1}$. To get the bracket's size,
note that

$$
\begin{align*}
\sum_{\mathbf{k} \in \{1, \dots, K\}^L} \left( \frac{1}{n^L} p_{k_1} \prod_{i=2}^{L} a_{k_{i-1}, k_i} - \frac{1}{n^L} (p_{k_1} + 1) \prod_{i=2}^{L} (a_{k_{i-1}, k_i} + 1) \right)^2 \\
&= \frac{1}{n^{2L}} \sum_{\mathbf{k} \in \{1, \dots, K\}^L} \left( \prod_{i=2}^{L} a_{k_{i-1}, k_i} + \sum_{j=2}^{L} p_{k_1} \prod_{i \neq j, i \ge 2} a_{k_{i-1}, k_i} \right)^2 \\
&\le \frac{L^2 n^{2L-2} K^L}{n^{2L}} \\
&\le L^2 K^L \epsilon^2,
\end{align*}
$$

and in the end

$$
N(u, \mathcal{U}, d_2) \le \max \left( \frac{LK^{L/2}}{u}, 1 \right)^{K^2-1} .
$$

**Proof of Lemma 25** All $f \in \mathcal{F} \cap \mathfrak{P}_M$ can be written as $\sum_{m=1}^M \lambda_m \varphi_m$ where $(\varphi_m)_{m \in \{1, \dots, M\}}$ is an orthonormal basis of $\mathfrak{P}_M$. Then, assumption [HF] implies that $|\lambda_m| \le C_{\mathcal{F},2}$ for all $m \in \{1, \dots, M\}$.

We will therefore start from a bracket covering of the euclidian ball of radius $C_{\mathcal{F},2}$ of $\mathbb{R}^M$, from which we will construct a covering of $\mathcal{F} \cap \mathfrak{P}_M$ and of $\Phi$.

**Lemma 26.** Let $\epsilon \in (0, 4)$. There exists a bracket covering $\{[a^i, b^i]\}_{1\le i\le N_M}$ of size $\epsilon$ of the euclidian ball of radius $C_{\mathcal{F},2}$ of $\mathbb{R}^M$ with cardinality

$$
N_M \le \max \left( \frac{4C_{\mathcal{F},2}\sqrt{M}}{\epsilon}, 1 \right)^M
$$

such that for all $m \in \{1, \dots, M\}$, $i \in \{1, \dots, N_M\}$, $-C_{\mathcal{F},2} \le a_m^i \le b_m^i \le C_{\mathcal{F},2}$.

**Proof.** We start with a bracket covering of size $\epsilon/\sqrt{M}$ of the infinity ball of radius $C_{\mathcal{F},2}$ of $\mathbb{R}^M$. This can be done by a regular partition with $\max([2C_{\mathcal{F},2}/\epsilon], 1)$ pieces along each coordinate. One can easily check that such a covering is also a covering of size $\epsilon$ of the euclidian ball of radius $C_{\mathcal{F},2}$ of $\mathbb{R}^M$. To conclude, it is enough to notice that $[x] \le 2x$ as soon as $x > 1/2$, and that $2C_{\mathcal{F},2}/\epsilon > 1/2$ because $C_{\mathcal{F},2} \ge 1$ and $\epsilon < 4$. $\square$

Let $\{[a^i, b^i]\}_{1\le i\le N_M}$ be such a covering. For all $m \in \{1, \dots, M\}$, $i \in \{1, \dots, N_M\}$ and $y \in \mathcal{Y}$, let

$$
u_m^i(y) = \begin{cases} a_m^i & \text{if } \varphi_m(y) \le 0 \\ b_m^i & \text{otherwise} \end{cases}
$$

$$
v_m^i(y) = a_m^i + b_m^i - u_m^i(y)
$$
and for all $i \in \{1, \dots, N_M\}$ and $y \in \mathcal{Y}$,

$$ egin{cases} U_1^i(y) = \sum_{m=1}^{M} u_m^i(y) \varphi_m(y) \\ U_2^i(y) = \sum_{m=1}^{M} v_m^i(y) \varphi_m(y) \end{cases} $$

and finally for all $\mathbf{i} = (i_1, \dots, i_K) \in \{1, \dots, N_M\}^K$ and $\mathbf{k} = (k_1, \dots, k_L) \in \{1, \dots, K\}^L$:

$$ egin{cases} (V^{\mathbf{i}})_{\mathbf{k}} = \min \left\{ \bigotimes_{\beta=1}^{L} U_{\sigma_{\beta}}^{i_{k_{\beta}}} ; \quad \sigma \in \{1, 2\}^{L} \right\} \\ (W^{\mathbf{i}})_{\mathbf{k}} = \max \left\{ \bigotimes_{\beta=1}^{L} U_{\sigma_{\beta}}^{i_{k_{\beta}}} ; \quad \sigma \in \{1, 2\}^{L} \right\} \end{cases} $$

It is enough to show that $\{[V^i, W^i]\}, \mathbf{i} \in \{1, \dots, N_M\}^K\}$ is a bracket covering of size $L(4C_{\mathcal{F},2}M)^{L-1}\sqrt{M\epsilon}$ of $\Phi$ that satisfies

$$ \max_{i} \max_{\mathbf{k}} \int (W_{\mathbf{k}}^{i})^{2} d\mu^{\otimes L} \leq (8M^{2}C_{\mathcal{F},2}^{2})^{L}. $$

Applying the Cauchy-Schwarz inequality, one gets that for all $i \in \{1, \dots, N_M\}$,

$$ egin{aligned} \|U_2^i - U_1^i\|_2^2 &= \left\| \sum_{m=1}^{M} |b_m^i - a_m^i| \cdot |\varphi_m| \right\|_2^2 \\ &\leq M \|b^i - a^i\|_2^2 \\ &\leq M \epsilon^2. \end{aligned} $$

Moreover, for all $i \in \{1, \dots, N_M\}$ and $\sigma \in \{1, 2\}$,

$$ egin{aligned} \|U_{\sigma}^{i}\|_{2}^{2} &\leq \left\| \sum_{m_i=1}^{M} |b_m^i + a_m^i| \cdot |\varphi_m| \right\|_{2}^{2} \\ &\leq 2M (\|a^i\|_{2}^{2} + \|b^i\|_{2}^{2}) \\ &\leq 4M^{2}C_{\mathcal{F},2}^{2}. \end{aligned} $$

We then use that for all $\mathbf{i} \in \{1, \dots, N_M\}^K$ and $\mathbf{k} \in \{1, \dots, K\}^L$,

$$ egin{aligned} |W_{\mathbf{k}}^{i} - V_{\mathbf{k}}^{i}|(y) &\leq \sum_{\gamma=1}^{L} |U_{2}^{i_{k_{\gamma}}} - U_{1}^{i_{k_{\gamma}}}| (y_{\gamma}) \max_{\mathbf{j} \in \{1,2\}^L} \prod_{\beta \neq \gamma, \beta=1}^{L} |U_{j_{\beta}}^{i_{k_{\beta}}}| (y_{\beta}) \\ &\leq \sum_{\gamma=1}^{L} |U_{2}^{i_{k_{\gamma}}} - U_{1}^{i_{k_{\gamma}}}| (y_{\gamma}) \prod_{\beta \neq \gamma, \beta=1}^{L} (|U_{1}^{i_{k_{\beta}}}| + |U_{2}^{i_{k_{\beta}}}|) (y_{\beta}) \end{aligned} $$
so that

$$
\begin{align*}
\|W_{\mathbf{k}}^{i} - V_{\mathbf{k}}^{i}\|_{2}^{2} &\le L \sum_{\gamma=1}^{L} \|U_{2}^{i_{k_{\gamma}}} - U_{1}^{i_{k_{\gamma}}}\|_{2}^{2} \prod_{\beta \ne \gamma, \beta=1}^{L} 2 \left( \|U_{1}^{i_{k_{\beta}}}\|_{2}^{2} + \|U_{2}^{i_{k_{\beta}}}\|_{2}^{2} \right) \\
&\le L 2^{L-1} \sum_{\gamma=1}^{L} M \epsilon^{2} \prod_{\beta \ne \gamma, \beta=1}^{L} (2 \times 4 M^{2} C_{\mathcal{F},2}^{2}) \\
&= L^{2} (16 M^{2} C_{\mathcal{F},2}^{2})^{L-1} M \epsilon^{2} \\
&= (L (4 C_{\mathcal{F},2} M)^{L-1} \sqrt{M} \epsilon)^{2}
\end{align*}
$$

and finally $d_{\infty,2}(W^i, V^i) \le L(4C_{\mathcal{F},2}M)^{L-1}\sqrt{M\epsilon}$ for all $i \in \{1, \dots, N_M\}^K$.

The last part of the lemma is proved by noting that for all i and k,

$$
\begin{align*}
(W^i)_k^2 &= \max\{\bigotimes_{\beta=1}^L (U_{\sigma_\beta}^{i_{k_\beta}})^2; \quad \sigma \in \{1,2\}^L\} \\
&\le \sum_{\sigma \in \{1,2\}^L} \bigotimes_{\beta=1}^L (U_{\sigma_\beta}^{i_{k_\beta}})^2,
\end{align*}
$$

so that

$$
\begin{align*}
\int (W^i)_k^2 d\mu^{\otimes L} &\le \sum_{\sigma \in \{1,2\}^L} \prod_{\beta=1}^L \|U_{\sigma_\beta}^{i_{k_\beta}}\|_2^2 \\
&\le \sum_{\sigma \in \{1,2\}^L} (4M^2 C_{\mathcal{F},2}^2)^L \\
&\le (8M^2 C_{\mathcal{F},2}^2)^L.
\end{align*}
$$

C.3. Choice of parameters

Let us come back to equation (10). Since $x \mapsto \frac{\varphi(x)}{x}$ is nonincreasing, one has $\frac{\varphi(x_{K,M} C_{\mathcal{F},\infty}^{L/2})}{x_{K,M} \sqrt{n}} \le \sigma_{K,M} C_{\mathcal{F},\infty}^{L/2}$ as soon as $x_{K,M} \ge \frac{\sigma_{K,M}}{C_{\mathcal{F},\infty}^{L/2}}$, so with probability $1 - e^{-z_{K,M}-z}$:

$$
Z_{K,M}(s) \le 4C^* \left[ C C_{\mathcal{F},\infty}^{L/2} \frac{\sigma_{K,M}}{x_{K,M}} + C_{\mathcal{F},\infty}^{L/2} \sqrt{\frac{z_{K,M}+z}{x_{K,M}^2 n}} + 2 C_{\mathcal{F},\infty}^{L} \frac{z_{K,M}+z}{x_{K,M}^2 n} \right].
$$

Let $C' = C^* \max(C, 1) C_{\mathcal{F},\infty}^L$. One gets

$$
Z_{K,M}(s) \le 4C' \left[ \frac{\sigma_{K,M}}{x_{K,M}} + \sqrt{\frac{z_{K,M}+z}{x_{K,M}^2 n}} + \frac{z_{K,M}+z}{x_{K,M}^2 n} \right].
$$
Let $x_{K,M} = \theta^{-1}\sqrt{\sigma_{K,M}^2 + \frac{z_{K,M}+z}{n}}$ with $\theta$ such that $2\theta + \theta^2 \le 1/(16C')$. Then, with probability $1 - e^{-z_{K,M}-z}$:

$$Z_{K,M}(s) \le 4C'(\theta + \theta + \theta^2) \le \frac{1}{4}$$

Now choose $z_{K,M} = M + K$, it follows that $\sum_{K \in \mathbb{N}^*, M \in \mathcal{M}} e^{-z_{K,M}} \le (e-1)^{-2} \le 1$ and the first point of the lemma is proved.

Moreover, one has with probability $1 - e^{-z}$, for all $K, M$:

$$\begin{aligned}
Z_{K,M}(s)x_{K,M}^2 &\le 4C' \left[ \sigma_{K,M}x_{K,M} + x_{K,M}\sqrt{\frac{z_{K,M}+z}{n}} + \frac{z_{K,M}+z}{n} \right] \\
&\le 4C' \left[ 2\theta x_{K,M}^2 + \frac{z_{K,M}+z}{n} \right] \\
&= 4C' \left[ 2\theta^{-1}\sigma_{K,M}^2 + (2\theta^{-1}+1)\frac{M+K}{n} + (2\theta^{-1}+1)\frac{z}{n} \right]
\end{aligned}$$

Let $A = 4C'(2\theta^{-1} + 1)$. We get that with probability $1 - e^{-z}$, for all $K, M$:

$$Z_{K,M}(s)x_{K,M}^2 \le A \left[ \sigma_{K,M}^2 + \frac{M+K}{n} + \frac{z}{n} \right]$$

Therefore the lemma holds as soon as

$$\forall K \le n, \forall M \le n, \quad \widetilde{\text{pen}}(n, M, K) \ge A \left[ \sigma_{K,M}^2 + \frac{M+K}{n} \right] \quad (15)$$

**Lemma 27.** There exists constants $C_1$ and $n_1$ such that for all $n \ge n_1$:

$$\sigma_{K,M} \le C_1 \sqrt{\frac{MK + K^2 - 1}{n}} (1 + \sqrt{\log(n)})$$

**Proof.** Let $x(C) = C\sqrt{\frac{MK+K^2-1}{n}}(1+\sqrt{\log(n)})$.

$\sigma_{K,M}$ is defined by the equation $\frac{\varphi(x)}{x^2\sqrt{n}} = 1$. The function $x \mapsto \frac{\varphi(x)}{x^2}$ is nondecreasing, so it is enough to show that $\frac{\varphi(x(C))}{x(C)^2\sqrt{n}} \le 1$ for some constant $C$ that we can assume to be greater than 1.

It is easy to check that there exists a constant $n_1$ such that for all $n \ge n_1$, $\frac{\varphi(n^{6L})}{(n^{6L})^2\sqrt{n}} \le 1$,
so that $\sigma_{K,M} \le n^{6L}$, which makes it possible to assume $x(C) \le n^{6L}$. Then

$$ \frac{\varphi(x(C))}{x(C)^2\sqrt{n}} = \frac{C_0}{C} \frac{1 + \sqrt{\log\left(\frac{n^{6L+1/2}}{C\sqrt{(MK+K^2-1)(1+\sqrt{\log(n)})}}\right)}}{1 + \sqrt{\log(n)}} \\ \le \frac{C_0}{C} \frac{1 + \sqrt{\log(n^{7L})}}{1 + \sqrt{\log(n)}} \\ = \frac{C_0}{C} \frac{1 + \sqrt{7L\sqrt{\log(n)}}}{1 + \sqrt{\log(n)}} $$

and by taking $C_1 = \max(C_0\sqrt{7L}, 1)$, one gets that

$$ \frac{\varphi(x(C_1))}{x(C_1)^2\sqrt{n}} \le 1 $$

which means that $\sigma_{K,M} \le x(C_1)$.

<figure><img src="image_16.png" /></figure>

The condition of equation (15) becomes

$$ \widetilde{\text{pen}}(n, M, K) \ge A \left[ \frac{C_1^2(MK + K^2 - 1)(1 + \sqrt{\log(n)})^2 + M + K}{n} \right] $$

which is implied by

$$ \widetilde{\text{pen}}(n, M, K) \ge \rho(MK + K^2 - 1) \frac{\log(n)}{n} $$

for some constant $\rho$ depending only on $C_{\mathcal{F},2}$, $C_{\mathcal{F},\infty}$, $\mathbf{Q}^*$ and $L$. This concludes the proof.

# Appendix D

## D.1. Proof of Proposition 6

Let $m \ge 3$. Note $r = \frac{m}{m-1}$ and $K_0 = (m-1)^m$. One can check that $K = K_0r^m \ge 2K_0$ and $K_0r^k \in \mathbb{N}^*$ for all $k \in \{0, \dots, m\}$.

Denote by $n(K)$ the integer $n_1$ in the hypothesis [Hpen](0, $\rho$) corresponding to $K^* = K$. Then for all $n \ge \sup_{k \in \{0, \dots, m-1\}} n(K_0r^k)$, for all $M$ and for all $k \in \{1, \dots, m\}$,

$$ \text{pen}(n, M, K_0 r^k) - \text{pen}(n, M, K_0 r^{k-1}) \ge \rho(MK_0 r^k + K_0^2 (r^2)^k - 1) \frac{\log(n)}{n}. $$
Taking the sum over $k \in \{1, \dots, m\}$, one gets that

$$ 
\begin{aligned}
\mathrm{pen}(n, M, K) &\ge \rho \left( M \frac{r}{r-1} (K - K_0) + \frac{r^2}{r^2-1} (K^2 - K_0^2) - m \right) \frac{\log(n)}{n} \\
&\ge \rho \left( M \frac{r}{r-1} (K - K_0) + \frac{r^2}{r^2-1} (K^2 - 2K_0^2) \right) \frac{\log(n)}{n}
\end{aligned}
$$

since $m \le K_0^2 = (m-1)^{2m}$. Using that $K \ge 2K_0$,

$$ \mathrm{pen}(n, M, K) \ge \frac{\rho}{2} \left( \frac{r}{r-1} MK + \frac{r^2}{r^2-1} K^2 \right) \frac{\log(n)}{n}. $$

Let $v_m = \frac{\rho}{2} \min \left( \frac{r}{r-1}, \frac{r^2}{r^2-1} \right)$. One gets

$$ \mathrm{pen}(n, M, K) \ge v_m (MK + K^2) \frac{\log(n)}{n}. $$

Therefore, there exists a non-decreasing sequence $(u_n)_{n \ge 1}$ such that

$$ \begin{cases} \forall n, \forall M \le n, \forall K \le n, \mathrm{pen}(n, M, K) \ge u_n(MK + K^2 - 1) \frac{\log(n)}{n} \\ \forall m, u_{\max(m, \sup_{k \in \{0, \dots, m-1\}} n(K_0 r^k)} \ge v_m \end{cases}. $$

and since $v_m \to \infty$, we get that $u_n \to \infty$, which concludes the proof. We could for instance take

$$ u_n = \max \left( 0, \sup \left\{ v_i \mid i \le n \text{ s.t. } \sup_{k \in \{0, \dots, i-1\}} n(i^k(i-1)^{i-k}) \le n \right\} \right). $$

## D.2. Auxiliary lemmas

**Lemma 28.**

$$ \forall t \in \bigcup_K S_K, \quad \begin{cases} \|t\|_{\infty} \le C_{\mathcal{F},\infty}^L \\ \|t\|_2 \le C_{\mathcal{F},2}^L \\ \mathbb{E}[t^2] \le C_{\mathcal{F},\infty}^L \|t\|_2^2 \end{cases} $$

*Proof.* $t$ can be written as $t = g^{\pi, \mathcal{Q}, f}$ with $\pi$ a probability $K$-uple, $\mathcal{Q}$ a transition matrix of size $K$ and $f \in \mathcal{F}^K$ for some $K \ge 1$.
The first point follows from

$$
\begin{align*}
\|t\|_{\infty} &= \left\| \sum_{k_1, \dots, k_L = 1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \bigotimes_{i=1}^{L} f_{k_i} \right\|_{\infty} \\
&\le \sum_{k_1, \dots, k_L = 1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \left\| \bigotimes_{i=1}^{L} f_{k_i} \right\|_{\infty} \\
&\le \sum_{k_1, \dots, k_L = 1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \prod_{i=1}^{L} \|f_{k_i}\|_{\infty} \\
&\le C_{\mathcal{F}, \infty}^{L} \sum_{k_1, \dots, k_L = 1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \\
&= C_{\mathcal{F}, \infty}^{L}
\end{align*}
$$

For the second point, we use the Cauchy-Schwarz inequality:

$$
\begin{align*}
\|t\|_2^2 &= \int \left( \sum_{k_1, \dots, k_L=1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \prod_{i=1}^{L} f_{k_i}(y_i) \right)^2 d\mu(y_1) \dots d\mu(y_L) \\
&= \int \left( \sum_{k_1, \dots, k_L=1}^{K} \sqrt{\pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i)} \left( \sqrt{\pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i)} \prod_{i=1}^{L} f_{k_i}(y_i) \right)^2 \right) d\mu(y_1) \dots d\mu(y_L) \\
&\le \int \left( \sum_{k_1', \dots, k_L'=1}^{K} \pi(k_1') \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}', k_i') \right) \left( \sum_{k_1, \dots, k_L=1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \prod_{i=1}^{L} f_{k_i}^2(y_i) \right) d\mu(y_1) \dots d\mu(y_L) \\
&= \sum_{k_1, \dots, k_L=1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \int \prod_{i=1}^{L} f_{k_i}^2(y_i) d\mu(y_1) \dots d\mu(y_L) \\
&= \sum_{k_1, \dots, k_L=1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) \prod_{i=1}^{L} \|f_{k_i}\|_2^2 \\
&\le \sum_{k_1, \dots, k_L=1}^{K} \pi(k_1) \prod_{i=2}^{L} \mathbf{Q}(k_{i-1}, k_i) C_{\mathcal{F},2}^{2L}
\end{align*}
$$
$$=C_{\mathcal{F},2}^{2L}$$

The last point comes from

$$ \begin{aligned} \mathbb{E}[t^2] &= \int g^*t^2 d\mu^{\otimes L} \\ &\le \int \|g^*\|_{\infty} t^2 d\mu^{\otimes L} \\ &\le C_{\mathcal{F},\infty}^L \int t^2 d\mu^{\otimes L} \quad \text{par le premier point} \\ &= C_{\mathcal{F},\infty}^L \|t\|_2^2 \end{aligned} $$

□

**Lemma 29.** Let $A, B \in \mathbb{R}_+^*$. Let $H: x \in \mathbb{R}_+^* \mapsto A \log \max(\frac{B}{x}, 1)$, and $\varphi(x) : x \in \mathbb{R}_+^* \mapsto x\sqrt{\pi A}(1 + \sqrt{\log \max(\frac{B}{x}, 1)}).$ Then:

$$ \begin{cases} x^2 H(x) \le \varphi(x)^2 \\ \int_0^x \sqrt{H(u)} du \le \varphi(x) \end{cases} $$

*Proof.* The first point is straightforward.
For the second point, we have two cases.

**Case 1:** $x \le B$. Then $H(x) = \log(\frac{B}{x})$. Therefore, we can use that $\int_0^\sigma \sqrt{\log(\frac{B}{x})} dx \le \sigma(\sqrt{\pi} + \sqrt{\log(\frac{B}{\sigma})})$, which is enough to conclude.

**Case 2:** $x \ge B$. Then $H(x) = 0$ and $\varphi(x) = x\sqrt{\pi A} \ge B\sqrt{\pi A} = \varphi(B)$. Thus,

$$ \begin{aligned} \int_0^x \sqrt{H(u)} du &= \int_0^B \sqrt{H(u)} du \\ &\le \varphi(B) \\ &\le \varphi(x) \end{aligned} $$

□