Validation and cross validation of metamodels


In ordinary validation of a metamodel, we hold some observations from the sample and train the model on the remaining observations. Then, we test the metamodel against the hold out observations. One of the problems of this method is that the surrogate model is trained using only a subset of the available data. As a consequence, the estimated error can be pessimistic or, on the contrary, overly optimistic. In cross-validation, the entirety of the data set is sequentially used for either training or validation. Hence, more of the available data is used, resulting in an improved accuracy of the estimated error of the metamodel. One of the problems of cross-validation is that we have to train the metamodel several times, which can be time consuming. In this case, the fast methods that we present below can be useful.

Let \model: \physicalInputSpace \rightarrow \Rset be a physical model where \physicalInputSpace \subseteq \Rset^{\inputDim} is the domain of the input parameters \inputReal. Let \metaModel be a metamodel of \model, i.e. an approximation of the function. Once the metamodel \metaModel of the original numerical model \model has been built, we may estimate the mean squared error, i.e. the discrepancy between the response surface and the true model response in terms of the weighted L^2-norm:

\operatorname{MSE} \left(\metaModel\right)
& = \left\| \model(\inputReal) - \metaModel(\inputReal) \right\|_{L^2(\physicalInputSpace)}^2 \\
& = \int_{\physicalInputSpace} \left( \model(\inputReal) - \metaModel(\inputReal) \right)^2  \inputProbabilityDensityFunction(\inputReal) d\inputReal

where \inputProbabilityDensityFunction is the probability density function of the random vector \inputRV. In this section, we present the cross-validation of linear least squares models, as presented in [wang2012] page 485.

The fraction of variance unexplained (FVU) is:

= \frac{\operatorname{MSE}\left(\metaModel\right)}{\Var{Y}}

where \Var{Y} is the variance of the random output Y = \model(\inputRV). The fraction of variance unexplained is a relative mean squared error. The coefficient of determination is:

R^2 & = 1 - \operatorname{FVU} \\
& = 1 - \frac{\operatorname{MSE}\left(\metaModel\right)}{\Var{Y}}

Simple validation

In the ordinary or naive validation method, we divide the data sample (i.e. the experimental design) into two independent sub-samples: the training and the test set. In this case, the metamodel \metaModel is built from one sub-sample, i.e. the training set, and its performance is assessed by comparing its predictions to the other subset, i.e. the test set. A single split will lead to a validation estimate. When several splits are created, the cross-validation error estimate is obtained by averaging over the splits. When the coefficient of determination is evaluated on a test set which is independent from the training set, the coefficient of determination is sometimes called the Q^2 score.

Validation of a surrogate

Figure 1. Validation using one single split.

Let \sampleSize \in \Nset be an integer representing the sample size. Let \set{D}_n \subseteq \physicalInputSpace be a set of \sampleSize independent observations of the random vector \inputRV:

\set{D}_n = \left\{\inputReal^{(1)}, ..., \inputReal^{(\sampleSize)} \in \Rset^{\inputDim}\right\}

and consider the corresponding outputs of the model:

\left\{y^{(1)}, ..., y^{(\sampleSize)}  \in \Rset\right\}


y^{(j)} = \model\left(\inputReal^{(j)}\right)

for j = 1, ..., \sampleSize. The Monte-Carlo estimator of the mean squared error is:

= \frac{1}{\sampleSize} \sum_{j = 1}^\sampleSize \left( y^{(j)} - \metaModel \left(\inputReal^{(j)}\right) \right)^2

The previous equation can be equivalently expressed depending on the model since y^{(j)} = \model\left(\inputReal^{(j)}\right). It seems, however, more consistent to use y^{(j)} because the true model g is unknown (otherwise we would not use a surrogate).

The sample relative mean squared error is:

= \frac{\widehat{\operatorname{MSE}}\left(\metaModel\right)}{\widehat{\sigma}^2(Y)}

where \widehat{\sigma}^2(Y) is the sample variance of the random output:

= \frac{1}{\sampleSize - 1} \sum_{j = 1}^\sampleSize \left( y^{(j)} -   \bar{y} \right)^2

where \bar{y} is the sample mean of the output:

\bar{y} = \frac{1}{\sampleSize} \sum_{j = 1}^\sampleSize y^{(j)}.

If the test set \set{D}_n is not independent from the training set (the set used to calibrate the metamodel), then the previous estimator may underestimate the true value of the mean squared error. Assuming that the sample is made of i.i.d. observations, in order to create a test set independent from the training set, a simple method is to split the data set into two parts. The drawback of this method is that this reduces the size of the training set, so that the mean squared error evaluated on the test set can be pessimistic (because the metamodel is trained with less data) or optimistic (because the R2 score has a greater variability). The leave-one-out (LOO) and K-Fold cross validation methods presented in the next sections have the advantage of using all of the available data.

Naive and fast cross-validation

As seen in the previous section, the simplest method of performing the validation consists in splitting the data into a training set and a test set. Moreover, provided these two sets are independent, then the estimate of the error is unbiased. In order to use all the available data instead of a subset of it, two other estimators can be considered: the leave-one-out and K-Fold estimators, which are the topic of the next sections.

When implemented naively, these methods may require to build many metamodels, which can be time-consuming. Fortunately, there are shortcuts for many metamodels including linear least squares and splines (and others). For a linear least squares model, some methods use the Sherman-Morrisson-Woodbury formula to get updates of the inverse Gram matrix, as we are going to see later in this document. This makes it possible to easily evaluate metamodel errors of a linear least squares model.

Leave-one-out cross-validation

In this section, we present the naive leave-one-out error estimator, also known as jackknife in statistics. Let \metaModel^{(-j)} be the metamodel estimated from the leave-one-out experimental design \set{D}_n \setminus \{\inputReal^{(j)}\}. This is the experimental design where the j-th observation \inputReal^{(j)} is set aside. The corresponding set of observation indices is:

\set{S}_{-j} = \{1, ..., j - 1, j + 1, ..., \sampleSize\},

the corresponding input observations are:

\set{D}_n \setminus \{\inputReal^{(j)}\}
= \left\{\inputReal^{(1)}, ..., \inputReal^{(j - 1)},
\inputReal^{(j + 1)}, ..., \inputReal^{(\sampleSize)}\right\}
= \left\{\inputReal^{(j)}, \; j \in \set{S}_{-j}\right\}

and the corresponding output observations are:

\left\{y^{(1)}, ..., y^{(j - 1)}, y^{(j + 1)}, ..., y^{(\sampleSize)}\right\}.

The leave-one-out residual is defined as the difference between the model evaluation at \inputReal^{(j)} and its leave-one-out prediction (see [blatman2009] eq. 4.26 page 85):

= y^{(j)} - \metaModel^{(-j)}\left(\inputReal^{(j)}\right)

We repeat this process for all observations in the experimental design and obtain the predicted residuals \Delta^{(j)} for j = 1, \dots, \sampleSize. Finally, the LOO mean squared error estimator is:

& =  \frac{1}{\sampleSize} \sum_{j = 1}^\sampleSize \left( \Delta^{(j)} \right)^2

One of the drawbacks of the naive method is that it may require to estimate \sampleSize different metamodels. If \sampleSize is large or if training each metamodel is costly, then the leave-one-out method can be impractical. If, however, the metamodel is based on the linear least squares method, then the leave-one-out error may be computed much more efficiently, as shown in the next section.

Fast leave-one-out cross-validation of a linear model

In this section, we present the fast leave-one-out error estimator of a linear least squares model. In the special case of a linear least squares model, [stone1974] (see eq. 3.13 page 121) showed that the leave-one-out residuals have an expression which depends on the diagonal of the projection matrix. In this case, the evaluation of the leave-one-out mean squared error involves the multiplication of the raw residuals by a correction which involves the leverages of the model. This method makes it possible to directly evaluate the mean squared error without necessarily estimating the coefficients of \sampleSize different leave-one-out least squares models. It is then much faster than the naive leave-one-out method.

Assume that the model is linear:

\model(\inputReal) = a_0 + \sum_{i=1}^{\inputDim} a_i x_i

for any \inputReal \in \physicalInputSpace where \vect{a} \in \Rset^{\inputDim + 1} is the vector of parameters. Let \vect{y} \in \Rset^\sampleSize be the vector of output observations:

\vect{y} = \left(y^{(1)}, ..., y^{(\sampleSize)} \right)^T.

The goal of the least squares method is to estimate the coefficients \vect{a} using the vector of observations \vect{y}. The output vector from the linear model is:

\vect{y} =  \boldsymbol{D} \vect{a}

for any \inputReal \in \physicalInputSpace where \boldsymbol{D} \in \Rset^{\sampleSize \times (\inputDim + 1)} is the design matrix. For a linear model, the columns of the design matrix correspond to the input parameters and the rows correspond to the observations:

1      & x_1^{(1)} & \ldots  & x_{\inputDim}^{(1)} \\
\vdots &           &         & \vdots \\
1      & x_1^{(\sampleSize)} & \ldots  & x_{\inputDim}^{(\sampleSize)}

In the previous equation, notice that the design matrix depends on the experimental design \set{D}_n.

Assume that the matrix \boldsymbol{D} has full rank. The solution of the linear least squares problem is given by the normal equations (see [Bjorck1996] eq. 1.1.15 page 6):

\widehat{\vect{a}} = \left(\boldsymbol{D}^T \boldsymbol{D} \right)^{-1} \boldsymbol{D}^T \vect{y}.

The linear metamodel is the linear model with estimated coefficients:

\metaModel(\inputReal) = \hat{a}_0 + \sum_{i=1}^{\inputDim} \hat{a}_i x_i.

The vector of predictions from the metamodel is:

\widehat{\vect{y}} = \boldsymbol{D} \widehat{\vect{a}}

for any \inputReal \in \physicalInputSpace where \widehat{\vect{a}} is the estimate from linear least squares. We substitute the estimator in the previous equation and get the value of the surrogate linear model:

= \boldsymbol{D} \left(\boldsymbol{D}^T \boldsymbol{D} \right)^{-1} \boldsymbol{D}^T \vect{y}

Let \boldsymbol{H} \in \Rset^{\sampleSize \times \sampleSize} be the projection (“hat”) matrix (see [wang2012] eq. 16.8 page 472):

= \boldsymbol{D} \left(\boldsymbol{D}^T \boldsymbol{D} \right)^{-1} \boldsymbol{D}^T.

Hence, the value of the linear model is the matrix-vector product:

\widehat{\vect{y}} = \boldsymbol{H} \vect{y}.

We can prove that the LOO residual is:

(1)y^{(j)} - \widehat{g}^{(-j)}\left(\inputReal^{(j)}\right)
= \frac{y^{(j)} - \widehat{g}\left(\inputReal^{(j)}\right)}{1 - h_{jj}}

where h_{jj} is the j-th diagonal term of the hat matrix. In other words, the residual of the LOO metamodel is equal to the residual of the full metamodel corrected by 1 - h_{jj}.

The number h_{jj} is the leverage of the j-th observation. It can be proved (see [sen1990] page 157) that:

\frac{1}{\sampleSize} \leq h_{jj} \leq 1.

Moreover (see [sen1990] eq. 5.10 page 106):

\sum_{j = 1}^{\sampleSize} h_{jj}  = \operatorname{Tr}(H) = \inputDim + 1

where \operatorname{Tr}(H) is the trace of the hat matrix. The leverage describes how far away the individual data point is from the centroid of all data points (see [sen1990] page 155). The equation (1) implies that if h_{jj} is large (i.e. close to 1), then removing the j-th observation from the training sample changes the residual of the leave-one-out metamodel significantly.

Using the equation (1) avoids to actually build the LOO surrogate. We substitute the previous expression in the definition of the leave-one-out mean squared error estimator and get the fast leave-one-out cross validation error (see [wang2012] eq. 16.25 page 487):

= \frac{1}{\sampleSize} \sum_ {j = 1}^\sampleSize \left( \frac{y^{(j)} -
      \widehat{g}\left(\inputReal^{(j)}\right)}{1 - h_{jj}} \right)^2

Corrected leave-one-out

A penalized variant of the leave-one-out mean squared error may be used in order to increase its robustness with respect to overfitting. This is done using a criterion which takes into account the number of coefficients compared to the size of the experimental design. The corrected leave-one-out error is (see [chapelle2002], [blatman2009] eq. 4.38 page 86):

= \widehat{\operatorname{MSE}}_{LOO} T(\inputDim, \sampleSize)

where the penalty factor is:

T(\inputDim, \sampleSize)
= \frac{\sampleSize}{\sampleSize - (\inputDim + 1)}  \left(1 + \frac{\operatorname{Tr} \left( \boldsymbol{C}_{emp}^{-1}  \right) }{\sampleSize} \right)

where \boldsymbol{C}_{emp} is the matrix:

\boldsymbol{C}_{emp} = \frac{1}{\sampleSize}\boldsymbol{D}^{\textsf{T}}\boldsymbol{D}

and \operatorname{Tr} is the trace operator.

K-fold cross-validation

In this section, we present the naive K-Fold cross-validation. Let k \in \Nset be a parameter representing the number of splits in the data set. The k-fold cross-validation technique relies on splitting the data set \set{D}_n into k sub-samples \set{D}_{\sampleSize_1}, \dots, \set{D}_{\sampleSize_k}, called the folds. The corresponding set of indices:

\set{S}_1 \; \cup \; \cdots \; \cup \; \set{S}_k
= \{1, ..., \sampleSize\}

and the corresponding set of input observations is:

\set{D}_n = \set{D}_{\sampleSize_1} \; \cup \; \cdots \; \cup \; \set{D}_{\sampleSize_k}.

The next figure presents this type of cross validation.

K-Fold validation

Figure 2. K-Fold cross-validation.

The k folds are generally chosen to be of approximately equal sizes. If the sample size \sampleSize is a multiple of k, then the folds can have exactly the same size.

For any \ell \in \{1, ..., k\}, let \metaModel^{(-\set{D}_{\sampleSize_\ell})} be the metamodel estimated on the K-fold sample \set{D}_n \setminus \set{D}_{\sampleSize_\ell}. Let \Delta^{(\ell, j)} be defined as the K-Fold residual:

\Delta^{(\ell, j)}
= y^{(j)} - \widehat{g}^{(-\set{D}_{\sampleSize_\ell})} \left(\inputReal^{(j)}\right)

for \ell = 1, ..., k and j \in \set{S}_{\ell}. In the previous equation, the predicted residual y^{(j)} - \metaModel^{(-\set{D}_{\sampleSize_\ell})} \left(\inputReal^{(j)}\right) is the difference between the evaluation of \model and the value of the K-Fold surrogate \metaModel^{(-\set{D}_{\sampleSize_\ell})} at the point \inputReal^{(j)}. The local approximation error is estimated on the sample \set{D}_{\sampleSize_\ell}: