プリンキピア

第18章ガウス過程

18.3.1. Posterior Inference for Regression18.3.1 回帰のための事後推論

An observation model relates the function we want to learn, f(x), to our observations y(x), both indexed by some input x. In classification, x could be the pixels of an image, and y could be the associated class label. In regression, y typically represents a continuous output, such as a land surface temperature, a sea-level, a CO2 concentration, etc.
英語のヒント
観測モデルは、学習したい関数f(x)を観測y(x)に関係づける。どちらも何らかの入力xでインデックスづけされている。分類では、xは画像の画素で、yはそれに結びついたクラスラベルでありうる。回帰では、yはふつう、地表の気温、海面の高さ、CO2の濃度などの連続的な出力を表す。
In regression, we often assume the outputs are given by a latent noise-free function f(x) plus i.i.d. Gaussian noise ϵ(x):
英語のヒント
回帰ではしばしば、出力が、ノイズのない潜在的な関数f(x)に独立同分布のガウスノイズϵ(x)を加えたもので与えられると仮定する。
y(x)=f(x)+ϵ(x),(18.3.1)
with ϵ(x)∼𝒩(0,σ2). Let 𝐲=y(X)=(y(x1),…,y(xn))⊤ be a vector of our training observations, and 𝐟=(f(x1),…,f(xn))⊤ be a vector of the latent noise-free function values, queried at the training inputs X=x1,…,xn.
英語のヒント
ここで、ϵ(x)∼𝒩(0,σ2)である。𝐲=y(X)=(y(x1),…,y(xn))⊤を訓練の観測値のベクトル、𝐟=(f(x1),…,f(xn))⊤を訓練入力X=x1,…,xnで問い合わせた、ノイズのない潜在的な関数の値のベクトルとする。
We will assume f(x)∼𝒢𝒫(m,k), which means that any collection of function values 𝐟 has a joint multivariate Gaussian distribution, with mean vector μi=m(xi) and covariance matrix Kij=k(xi,xj). The RBF kernel k(xi,xj)=a2exp⁡(−12ℓ2||xi−xj||2) would be a standard choice of covariance function. For notational simplicity, we will assume the mean function m(x)=0; our derivations can easily be generalized later on.
英語のヒント
f(x)∼𝒢𝒫(m,k)と仮定する。これは、関数の値の任意の集まり𝐟が、平均ベクトルμi=m(xi)と共分散行列Kij=k(xi,xj)をもつ同時多変量ガウス分布に従うことを意味する。RBFカーネルk(xi,xj)=a2exp⁡(−12ℓ2||xi−xj||2)は、共分散関数の標準的な選び方だろう。記法を簡単にするため、平均関数をm(x)=0と仮定する。この導出は後で簡単に一般化できる。
Suppose we want to make predictions at a set of inputs
英語のヒント
入力の集合で予測をしたいとしよう。
X∗=x∗1,x∗2,…,x∗m.(18.3.2)
Then we want to find x2 and p(𝐟∗|𝐲,X). In the regression setting, we can conveniently find this distribution by using Gaussian identities, after finding the joint distribution over 𝐟∗=f(X∗) and 𝐲.
英語のヒント
すると、x2とp(𝐟∗|𝐲,X)を見つけたい。回帰の設定では、𝐟∗=f(X∗)と𝐲の上の同時分布を見つけた後、ガウス分布の恒等式を使って、この分布を都合よく見つけられる。
If we evaluate equation (18.3.1) at the training inputs X, we have 𝐲=𝐟+ϵ. By the definition of a Gaussian process (see last section), 𝐟∼𝒩(0,K(X,X)) where K(X,X) is an n×n matrix formed by evaluating our covariance function (aka kernel) at all possible pairs of inputs xi,xj∈X. ϵ is simply a vector comprised of iid samples from 𝒩(0,σ2) and thus has distribution 𝒩(0,σ2I). 𝐲 is therefore a sum of two independent multivariate Gaussian variables, and thus has distribution 𝒩(0,K(X,X)+σ2I). One can also show that cov(𝐟∗,𝐲)=cov(𝐲,𝐟∗)⊤=K(X∗,X) where K(X∗,X) is an m×n matrix formed by evaluating the kernel at all pairs of test and training inputs.
英語のヒント
訓練入力Xで式(18.3.1)を評価すると、𝐲=𝐟+ϵとなる。ガウス過程の定義(前の節を参照)から、𝐟∼𝒩(0,K(X,X))である。ここで、K(X,X)は、入力のありうるすべての対xi,xj∈Xで共分散関数(つまりカーネル)を評価してできるn×nの行列である。ϵは単に𝒩(0,σ2)からの独立同分布の標本からなるベクトルであり、したがって分布𝒩(0,σ2I)に従う。したがって、𝐲は二つの独立な多変量ガウス変数の和であり、分布𝒩(0,K(X,X)+σ2I)に従う。また、cov(𝐟∗,𝐲)=cov(𝐲,𝐟∗)⊤=K(X∗,X)であることも示せる。ここで、K(X∗,X)は、テスト入力と訓練入力のすべての対でカーネルを評価してできるm×nの行列である。
[𝐲𝐟∗]∼𝒩(0,𝐀=[K(X,X)+σ2IK(X,X∗)K(X∗,X)K(X∗,X∗)])(18.3.3)
We can then use standard Gaussian identities to find the conditional distribution from the joint distribution (see, e.g., Bishop Chapter 2), 𝐟∗|𝐲,X,X∗∼𝒩(m∗,S∗), where m∗=K(X∗,X)[K(X,X)+σ2I]−1𝐲, and S=K(X∗,X∗)−K(X∗,X)[K(X,X)+σ2I]−1K(X,X∗).
英語のヒント
それから、標準的なガウス分布の恒等式を使って、同時分布から条件付き分布𝐟∗|𝐲,X,X∗∼𝒩(m∗,S∗)を見つけられる(たとえば、Bishopの第2章を参照)。ここで、m∗=K(X∗,X)[K(X,X)+σ2I]−1𝐲、S=K(X∗,X∗)−K(X∗,X)[K(X,X)+σ2I]−1K(X,X∗)である。
Typically, we do not need to make use of the full predictive covariance matrix S, and instead use the diagonal of S for uncertainty about each prediction. Often for this reason we write the predictive distribution for a single test point x∗, rather than a collection of test points.
英語のヒント
ふつうは、予測の共分散行列S全体を使う必要はなく、代わりに各予測についての不確かさにはSの対角成分を使う。この理由で、テスト点の集まりではなく、一つのテスト点x∗についての予測分布を書くことが多い。
The kernel matrix has parameters θ that we also wish to estimate, such the amplitude a and lengthscale ℓ of the RBF kernel above. For these purposes we use the marginal likelihood, p(𝐲|θ,X), which we already derived in working out the marginal distributions to find the joint distribution over 𝐲,𝐟∗. As we will see, the marginal likelihood compartmentalizes into model fit and model complexity terms, and automatically encodes a notion of Occam’s razor for learning hyperparameters. For a full discussion, see MacKay Ch. 28 (MacKay, 2003), and Rasmussen and Williams Ch. 5 (Rasmussen and Williams, 2006).
英語のヒント
カーネル行列には、上のRBFカーネルの振幅aや長さスケールℓのような、やはり推定したいパラメータθがある。この目的のためには周辺尤度p(𝐲|θ,X)を使う。これは、𝐲,𝐟∗の上の同時分布を見つけるために周辺分布を求めたときに、すでに導いている。後で見るように、周辺尤度はモデルの当てはまりの項とモデルの複雑さの項に分かれ、ハイパーパラメータの学習についてのオッカムの剃刀の考え方を自動的に符号化する。詳しい議論については、MacKayの第28章(MacKay, 2003)と、RasmussenとWilliamsの第5章(Rasmussen and Williams, 2006)を参照せよ。
import math
import os
import gpytorch
import matplotlib.pyplot as plt
import numpy as np
import torch
from scipy import optimize
from scipy.spatial import distance_matrix
from d2l import torch as d2l

d2l.set_figsize()