Tôi sẽ (cố gắng) trả lời điều này theo ba bước: trước tiên, hãy xác định chính xác ý nghĩa của chúng tôi bằng cách làm trơn tru đơn biến. Tiếp theo, chúng tôi sẽ mô tả một mịn đa biến (cụ thể, trơn tru của hai biến). Cuối cùng, tôi sẽ cố gắng hết sức để mô tả một sản phẩm tenor trơn tru.
1) mịn màng
Hãy nói rằng chúng tôi có một số phản ứng dữ liệu rằng chúng tôi phỏng đoán là một chức năng chưa biết f của một biến dự đoán x cộng với một số lỗi ε . Mô hình sẽ là:yfxε
y=f(x)+ε
Now, in order to fit this model, we have to identify the functional form of f. The way we do this is by identifying basis functions, which are superposed in order to represent the function f in its entirety. A very simple example is a linear regression, in which the basis functions are just β2x and β1, the intercept. Applying the basis expansion, we have
y=β1+β2x+ε
In matrix form, we would have:
Y=Xβ+ε
Trong trường hợp là một vector cột n-by-1, X là một mô hình ma trận n-by-2, β là một vector cột 2-by-1 trong tổng số hệ số mô hình, và ε là một vector cột n-by-1 lỗi . X có hai cột vì có hai thuật ngữ trong mở rộng cơ sở của chúng tôi: thuật ngữ tuyến tính và chặn.YXβεX
Nguyên tắc tương tự áp dụng cho việc mở rộng cơ sở trong MGCV, mặc dù các chức năng cơ bản phức tạp hơn nhiều. Cụ thể, các hàm cơ sở riêng lẻ không cần được xác định trên toàn bộ miền của biến độc lập . Điều này thường xảy ra khi sử dụng các cơ sở dựa trên nút thắt (xem "ví dụ dựa trên nút thắt"x). Mô hình sau đó được biểu diễn dưới dạng tổng của các hàm cơ sở, mỗi hàm được đánh giá ở mọi giá trị của biến độc lập. Tuy nhiên, như tôi đã đề cập, một số hàm cơ bản này có giá trị bằng 0 bên ngoài một khoảng nhất định và do đó không đóng góp vào việc mở rộng cơ sở bên ngoài khoảng đó. Ví dụ, hãy xem xét một cơ sở spline hình khối trong đó mỗi hàm cơ sở đối xứng với một giá trị (nút) khác nhau của biến độc lập - nói cách khác, mọi hàm cơ sở trông giống nhau nhưng chỉ được dịch chuyển dọc theo trục của biến độc lập (đây là một sự đơn giản hóa, vì bất kỳ cơ sở thực tế nào cũng sẽ bao gồm một đánh chặn và một thuật ngữ tuyến tính, nhưng hy vọng bạn có được ý tưởng).
To be explicit, a basis expansion of dimension i−2 could look like:
y=β1+β2x+β3f1(x)+β4f2(x)+...+βifi−2(x)+ε
where each function f is, perhaps, a cubic function of the independent variable x.
The matrix equation Y=Xβ+ε can still be used to represent our model. The only difference is that X is now an n-by-i matrix; that is, it has a column for every term in the basis expansion (including the intercept and linear term). Since the process of basis expansion has allowed us to represent the model in the form of a matrix equation, we can use linear least squares to fit the model and find the coefficients β.
This is an example of unpenalized regression, and one of the main strengths of MGCV is its smoothness estimation via a penalty matrix and smoothing parameter. In other words, instead of:
β=(XTX)−1XTY
we have:
β=(XTX+λS)−1XTY
where S is a quadratic i-by-i penalty matrix and λ is a scalar smoothing parameter. I will not go into the specification of the penalty matrix here, but it should suffice to say that for any given basis expansion of some independent variable and definition of a quadratic "wiggliness" penalty (for example, a second-derivative penalty), one can calculate the penalty matrix S.
MGCV can use various means of estimating the optimal smoothing parameter λ. I will not go into that subject since my goal here was to give a broad overview of how a univariate smooth is constructed, which I believe I have done.
2) Multivariate smooth
The above explanation can be generalized to multiple dimensions. Let's go back to our model that gives the response y as a function f of predictors x and z. The restriction to two independent variables will prevent cluttering the explanation with arcane notation. The model is then:
y=f(x,z)+ε
Now, it should be intuitively obvious that we are going to represent f(x,z) with a basis expansion (that is, a superposition of basis functions) just like we did in the univariate case of f(x) above. It should also be obvious that at least one, and almost certainly many more, of these basis functions must be functions of both x and z (if this was not the case, then implicitly f would be separable such that f(x,z)=fx(x)+fz(z)). A visual illustration of a multidimensional spline basis can be found here. A full two dimensional basis expansion of dimension i−3 could look something like:
y=β1+β2x+β3z+β4f1(x,z)+...+βifi−3(x,z)+ε
I think it's pretty clear that we can still represent this in matrix form with:
Y=Xβ+ε
by simply evaluating each basis function at every unique combination of x and z. The solution is still:
β=(XTX)−1XTY
Computing the second derivative penalty matrix is very much the same as in the univariate case, except that instead of integrating the second derivative of each basis function with respect to a single variable, we integrate the sum of all second derivatives (including partials) with respect to all independent variables. The details of the foregoing are not especially important: the point is that we can still construct penalty matrix S and use the same method to get the optimal value of smoothing parameter λ, and given that smoothing parameter, the vector of coefficients is still:
β=(XTX+λS)−1XTY
Now, this two-dimensional smooth has an isotropic penalty: this means that a single value of λ applies in both directions. This works fine when both x and z are on approximately the same scale, such as a spatial application. But what if we replace spatial variable z with temporal variable t? The units of t may be much larger or smaller than the units of x, and this can throw off the integration of our second derivatives because some of those derivatives will contribute disproportionately to the overall integration (for example, if we measure t in nanoseconds and x in light years, the integral of the second derivative with respect to t may be vastly larger than the integral of the second derivative with respect to x, and thus "wiggliness" along the x direction may go largely unpenalized). Slide 15 of the "smooth toolbox" I linked has more detail on this topic.
It is worth noting that we did not decompose the basis functions into marginal bases of x and z. The implication here is that multivariate smooths must be constructed from bases supporting multiple variables. Tensor product smooths support construction of multivariate bases from univariate marginal bases, as I explain below.
3) Tensor product smooths
Tensor product smooths address the issue of modeling responses to interactions of multiple inputs with different units. Let's suppose we have a response y that is a function f of spatial variable x and temporal variable t. Our model is then:
y=f(x,t)+ε
What we'd like to do is construct a two-dimensional basis for the variables x and t. This will be a lot easier if we can represent f as:
f(x,t)=fx(x)ft(t)
In an algebraic / analytical sense, this is not necessarily possible. But remember, we are discretizing the domains of x and t (imagine a two-dimensional "lattice" defined by the locations of knots on the x and t axes) such that the "true" function f is represented by the superposition of basis functions. Just as we assumed that a very complex univariate function may be approximated by a simple cubic function on a specific interval of its domain, we may assume that the non-separable function f(x,t) may be approximated by the product of simpler functions fx(x) and ft(t) on an interval—provided that our choice of basis dimensions makes those intervals sufficiently small!
Our basis expansion, given an i-dimensional basis in x and j-dimensional basis in t, would then look like:
y=β1+β2x+β3fx1(x)+β4fx2(x)+...+βifx(i−3)(x)+βi+1t+βi+2tx+βi+3tfx1(x)+βi+4tfx2(x)+...+β2itfx(i−3)(x)+β2i+1ft1(t)+β2i+2ft1(t)x+β2i+3ft1(t)fx1(x)+βi+4ft1(t)fx2(x)+...+β2ift1(t)fx(i−3)(x)+…+βijft(j−3)(t)fx(i−3)(x)+ε
Which may be interpreted as a tensor product. Imagine that we evaluated each basis function in x and t, thereby constructing n-by-i and n-by-j model matrices X and T, respectively. We could then compute the n2-by-ij tensor product X⊗T of these two model matrices and reorganize into columns, such that each column represented a unique combination ij. Recall that the marginal model matrices had i and j columns, respectively. These values correspond to their respective basis dimensions. Our new two-variable basis should then have dimension ij, and therefore the same number of columns in its model matrix.
NOTE: I'd like to point out that since we explicitly constructed the tensor product basis functions by taking products of marginal basis functions, tensor product bases may be constructed from marginal bases of any type. They need not support more than one variable, unlike the multivariate smooth discussed above.
In reality, this process results in an overall basis expansion of dimension ij−i−j+1 because the full multiplication includes multiplying every t basis function by the x-intercept βx1 (so we subtract j) as well as multiplying every x basis function by the t-intercept βt1 (so we subtract i), but we must add the intercept back in by itself (so we add 1). This is known as applying an identifiability constraint.
So we can represent this as:
y=β1+β2x+β3t+β4f1(x,t)+β5f2(x,t)+...+βij−i−j+1fij−i−j−2(x,t)+ε
Where each of the multivariate basis functions f is the product of a pair of marginal x and t basis functions. Again, it's pretty clear having constructed this basis that we can still represent this with the matrix equation:
Y=Xβ+ε
Which (still) has the solution:
β=(XTX)−1XTY
Where the model matrix X has ij−i−j+1 columns. As for the penalty matrices Jx and Jt, these are are constructed separately for each independent variable as follows:
Jx=βTIj⊗Sxβ
and,
Jt=βTSt⊗Iiβ
This allows for an overall anisotropic (different in each direction) penalty (Note: the penalties on the second derivative of x are added up at each knot on the t axis, and vice versa). The smoothing parameters λx and λt may now be estimated in much the same way as the single smoothing parameter was for the univariate and multivariate smooths. The result is that the overall shape of a tensor product smooth is invariant to rescaling of its independent variables.
I recommend reading all the vignettes on the MGCV website, as well as "Generalized Additive Models: and introduction with R." Long live Simon Wood.