プリンキピア

第18章ガウス過程

18.1. Introduction to Gaussian Processes18.1 ガウス過程への導入

In many cases, machine learning amounts to estimating parameters from data. These parameters are often numerous and relatively uninterpretable — such as the weights of a neural network. Gaussian processes, by contrast, provide a mechanism for directly reasoning about the high-level properties of functions that could fit our data. For example, we may have a sense of whether these functions are quickly varying, periodic, involve conditional independencies, or translation invariance. Gaussian processes enable us to easily incorporate these properties into our model, by directly specifying a Gaussian distribution over the function values that could fit our data.
英語のヒント
多くの場合、機械学習はデータからパラメータを推定することに等しい。こうしたパラメータは、ニューラルネットワークの重みのように、たいてい数が多く、比較的解釈しにくい。これに対して、ガウス過程は、データに当てはまりうる関数の高水準の性質について直接考えるための仕組みを与える。たとえば、そうした関数が急速に変化するのか、周期的なのか、条件付き独立性を含むのか、平行移動に対して不変なのかについて、見当がついているかもしれない。ガウス過程を使えば、データに当てはまりうる関数の値の上のガウス分布を直接指定することで、こうした性質をモデルに簡単に組み込める。
Let’s get a feel for how Gaussian processes operate, by starting with some examples.
英語のヒント
いくつかの例から始めて、ガウス過程がどう働くかの感覚をつかもう。
Suppose we observe the following dataset, of regression targets (outputs), y, indexed by inputs, x. As an example, the targets could be changes in carbon dioxide concentrations, and the inputs could be the times at which these targets have been recorded. What are some features of the data? How quickly does it seem to varying? Do we have data points collected at regular intervals, or are there missing inputs? How would you imagine filling in the missing regions, or forecasting up until x=25?
英語のヒント
入力xでインデックスづけされた、回帰の目標値(出力)yからなる次のデータセットを観測するとしよう。例として、目標値は二酸化炭素の濃度の変化で、入力はこれらの目標値が記録された時刻でありうる。このデータにはどんな特徴があるか。どれくらい速く変化しているように見えるか。データ点は一定の間隔で集められているか、それとも欠けている入力があるか。欠けている領域を埋めたり、x=25まで予測したりするのを、どう想像するか。
Fig. 18.1.1図18.1.1
Observed data.
英語のヒント
観測されたデータ。
In order to fit the data with a Gaussian process, we start by specifying a prior distribution over what types of functions we might believe to be reasonable. Here we show several sample functions from a Gaussian process. Does this prior look reasonable? Note here we are not looking for functions that fit our dataset, but instead for specifying reasonable high-level properties of the solutions, such as how quickly they vary with inputs. Note that we will see code for reproducing all of the plots in this notebook, in the next notebooks on priors and inference.
英語のヒント
データにガウス過程を当てはめるため、どんな種類の関数が妥当だと考えられるかについての事前分布を指定することから始める。ここでは、ガウス過程からのいくつかの見本の関数を示す。この事前分布は妥当に見えるか。ここでは、データセットに当てはまる関数を探しているのではなく、入力に対してどれくらい速く変化するかのような、解の妥当な高水準の性質を指定しようとしていることに注意しよう。このノートブックのすべてのプロットを再現するコードは、事前分布と推論についての次のノートブックで見ることに注意しよう。
Fig. 18.1.2図18.1.2
Sample prior functions that we may want to represent with our model.
英語のヒント
モデルで表したいかもしれない、事前分布からの見本の関数。
Once we condition on data, we can use this prior to infer a posterior distribution over functions that could fit the data. Here we show sample posterior functions.
英語のヒント
データで条件づければ、この事前分布を使って、データに当てはまりうる関数の上の事後分布を推論できる。ここでは、事後分布からの見本の関数を示す。
Fig. 18.1.3図18.1.3
Sample posterior functions, once we have observed the data.
英語のヒント
データを観測した後の、事後分布からの見本の関数。
We see that each of these functions are entirely consistent with our data, perfectly running through each observation. In order to use these posterior samples to make predictions, we can average the values of every possible sample function from the posterior, to create the curve below, in thick blue. Note that we do not actually have to take an infinite number of samples to compute this expectation; as we will see later, we can compute the expectation in closed form.
英語のヒント
これらの関数はどれもデータと完全に整合しており、各観測点をぴったり通っている。これらの事後分布の標本を使って予測をするには、事後分布からのありうるすべての見本の関数の値を平均して、下の太い青の曲線を作ればよい。この期待値を計算するのに、実際に無限個の標本をとる必要はないことに注意しよう。後で見るように、期待値は閉じた形で計算できる。
Fig. 18.1.4図18.1.4
Posterior samples, alongside posterior mean, which can be used for point predictions, in blue.
英語のヒント
事後分布の標本と、点予測に使える事後平均(青)。
We may also want a representation of uncertainty, so we know how confident we should be in our predictions. Intuitively, we should have more uncertainty where there is more variability in the sample posterior functions, as this tells us there are many more possible values the true function could take. This type of uncertainty is called epistemic uncertainty, which is the reducible uncertainty associated with lack of information. As we acquire more data, this type of uncertainty disappears, as there will be increasingly fewer solutions consistent with what we observe. Like with the posterior mean, we can compute the posterior variance (the variability of these functions in the posterior) in closed form. With shade, we show two times the posterior standard deviation on either side of the mean, creating a credible interval that has a 95% probability of containing the true value of the function for any input x.
英語のヒント
予測にどれだけ自信をもってよいかがわかるように、不確かさの表現もほしいかもしれない。直観的には、事後分布の見本の関数のばらつきが大きいところほど、不確かさは大きいはずである。それは、真の関数がとりうる値がずっと多くあることを示すからである。この種類の不確かさは認識論的不確かさと呼ばれ、情報の不足に結びついた、減らすことのできる不確かさである。もっと多くのデータを得るにつれて、観測したものと整合する解がますます少なくなるので、この種類の不確かさは消えていく。事後平均と同じように、事後分散(事後分布でのこれらの関数のばらつき)は閉じた形で計算できる。網かけで、平均の両側に事後標準偏差の2倍を示し、任意の入力xについて関数の真の値を含む確率が95%の信用区間を作っている。
Fig. 18.1.5図18.1.5
Posterior samples, including 95% credible set.
英語のヒント
95%信用集合を含む事後分布の標本。
The plot looks somewhat cleaner if we remove the posterior samples, simply visualizing the data, posterior mean, and 95% credible set. Notice how the uncertainty grows away from the data, a property of epistemic uncertainty.
英語のヒント
事後分布の標本を取り除いて、データ、事後平均、95%信用集合だけを可視化すると、プロットはいくぶんすっきりする。データから離れるにつれて不確かさが大きくなることに注意しよう。これは認識論的不確かさの性質である。
Fig. 18.1.6図18.1.6
Point predictions, and credible set.
英語のヒント
点予測と信用集合。
The properties of the Gaussian process that we used to fit the data are strongly controlled by what’s called a covariance function, also known as a kernel. The covariance function we used is called the RBF (Radial Basis Function) kernel, which has the form
英語のヒント
データに当てはめるのに使ったガウス過程の性質は、カーネルとしても知られる、共分散関数と呼ばれるものによって強く制御される。使った共分散関数はRBF(動径基底関数)カーネルと呼ばれ、次の形をもつ。
kRBF(x,x′)=Cov(f(x),f(x′))=a2exp⁡(−12ℓ2||x−x′||2)(18.1.1)
The hyperparameters of this kernel are interpretable. The amplitude parameter a controls the vertical scale over which the function is varying, and the length-scale parameter ℓ controls the rate of variation (the wiggliness) of the function. Larger a means larger function values, and larger ℓ means more slowly varying functions. Let’s see what happens to our sample prior and posterior functions as we vary a and ℓ.
英語のヒント
このカーネルのハイパーパラメータは解釈できる。振幅パラメータaは関数が変化する縦方向の尺度を制御し、長さスケールパラメータℓは関数の変化の速さ(くねくね具合)を制御する。aが大きいほど関数の値は大きく、ℓが大きいほど関数はゆっくり変化する。aとℓを変えると、事前分布と事後分布の見本の関数に何が起こるかを見よう。
The length-scale has a particularly pronounced effect on the predictions and uncertainty of a GP. At ||x−x′||=ℓ , the covariance between a pair of function values is a2exp⁡(−0.5). At larger distances than ℓ , the values of the function values becomes nearly uncorrelated. This means that if we want to make a prediction at a point x∗, then function values with inputs x such that ||x−x′||>ℓ will not have a strong effect on our predictions.
英語のヒント
長さスケールは、GPの予測と不確かさにとりわけ顕著な影響を与える。||x−x′||=ℓでは、関数の値の対の間の共分散はa2exp⁡(−0.5)である。ℓより大きな距離では、関数の値はほとんど無相関になる。これは、点x∗で予測をしたいとき、||x−x′||>ℓとなる入力xでの関数の値は、予測に強い影響を与えないことを意味する。
Let’s see how changing the lengthscale affects sample prior and posterior functions, and credible sets. The above fits use a length-scale of 2. Let’s now consider ℓ=0.1,0.5,2,5,10 . A length-scale of 0.1 is very small relative to the range of the input domain we are considering, 25. For example, the values of the function at x=5 and x=10 will have essentially no correlation at such a length-scale. On the other hand, for a length-scale of 10, the function values at these inputs will be highly correlated. Note that the vertical scale changes in the following figures.
英語のヒント
長さスケールを変えると、事前分布と事後分布の見本の関数や信用集合がどう影響を受けるかを見よう。上の当てはめでは、長さスケール2を使っている。では、ℓ=0.1,0.5,2,5,10を考えよう。長さスケール0.1は、考えている入力の定義域の範囲25に比べてとても小さい。たとえば、そうした長さスケールでは、x=5とx=10での関数の値は本質的に相関をもたない。一方、長さスケールが10のときは、これらの入力での関数の値は強く相関する。以下の図では縦方向の尺度が変わることに注意しよう。
Notice as the length-scale increases the ‘wiggliness’ of the functions decrease, and our uncertainty decreases. If the length-scale is small, the uncertainty will quickly increase as we move away from the data, as the datapoints become less informative about the function values.
英語のヒント
長さスケールが大きくなるにつれて、関数の「くねくね具合」が小さくなり、不確かさも小さくなることに注意しよう。長さスケールが小さいと、データ点が関数の値についてもつ情報が少なくなるので、データから離れるにつれて不確かさが急速に大きくなる。
Now, let’s vary the amplitude parameter, holding the length-scale fixed at 2. Note the vertical scale is held fixed for the prior samples, and varies for the posterior samples, so you can clearly see both the increasing scale of the function, and the fits to the data.
英語のヒント
では、長さスケールを2に固定したまま、振幅パラメータを変えてみよう。関数の尺度が大きくなる様子とデータへの当てはまりの両方がはっきり見えるように、縦方向の尺度は、事前分布の標本では固定し、事後分布の標本では変えていることに注意しよう。
We see the amplitude parameter affects the scale of the function, but not the rate of variation. At this point, we also have the sense that the generalization performance of our procedure will depend on having reasonable values for these hyperparameters. Values of ℓ=2 and a=1 appeared to provide reasonable fits, while some of the other values did not. Fortunately, there is a robust and automatic way to specify these hyperparameters, using what is called the marginal likelihood, which we will return to in the notebook on inference.
英語のヒント
振幅パラメータは関数の尺度に影響するが、変化の速さには影響しないことがわかる。ここまでで、この手続きの汎化性能は、これらのハイパーパラメータに妥当な値をもたせられるかどうかに左右されるという感覚もつかめた。ℓ=2とa=1の値は妥当な当てはまりを与えたように見えたが、ほかの値のいくつかはそうではなかった。幸い、周辺尤度と呼ばれるものを使って、これらのハイパーパラメータを頑健かつ自動的に指定する方法がある。これについては、推論のノートブックで再び取り上げる。
So what is a GP, really? As we started, a GP simply says that any collection of function values f(x1),…,f(xn), indexed by any collection of inputs x1,…,xn has a joint multivariate Gaussian distribution. The mean vector μ of this distribution is given by a mean function, which is typically taken to be a constant or zero. The covariance matrix of this distribution is given by the kernel evaluated at all pairs of the inputs x.
英語のヒント
では、GPとは本当のところ何なのか。最初に述べたように、GPは単に、任意の入力の集まりx1,…,xnでインデックスづけされた関数の値の任意の集まりf(x1),…,f(xn)が、同時多変量ガウス分布をもつと言っているにすぎない。この分布の平均ベクトルμは平均関数で与えられ、平均関数はふつう定数か0にとられる。この分布の共分散行列は、入力xのすべての対で評価したカーネルで与えられる。
[f(x)f(x1)⋮f(xn)]∼𝒩(μ,[k(x,x)k(x,x1)…k(x,xn)k(x1,x)k(x1,x1)…k(x1,xn)⋮⋮⋱⋮k(xn,x)k(xn,x1)…k(xn,xn)])(18.1.2)
Equation (18.1.2) specifies a GP prior. We can compute the conditional distribution of f(x) for any x given f(x1),…,f(xn), the function values we have observed. This conditional distribution is called the posterior, and it is what we use to make predictions.
英語のヒント
式(18.1.2)はGPの事前分布を指定する。観測した関数の値f(x1),…,f(xn)が与えられたときの、任意のxについてのf(x)の条件付き分布を計算できる。この条件付き分布は事後分布と呼ばれ、予測をするのに使うのはこれである。
In particular,
英語のヒント
特に、
f(x)|f(x1),…,f(xn)∼𝒩(m,s2)(18.1.3)
where
英語のヒント
ここで、
m=k(x,x1:n)k(x1:n,x1:n)−1f(x1:n)(18.1.4)
s2=k(x,x)−k(x,x1:n)k(x1:n,x1:n)−1k(x,x1:n)(18.1.5)
where k(x,x1:n) is a 1×n vector formed by evaluating k(x,xi) for i=1,…,n and k(x1:n,x1:n) is an n×n matrix formed by evaluating k(xi,xj) for i,j=1,…,n. m is what we can use as a point predictor for any x, and s2 is what we use for uncertainty: if we want to create an interval with a 95% probability that f(x) is in the interval, we would use m±2s. The predictive means and uncertainties for all the above figures were created using these equations. The observed data points were given by f(x1),…,f(xn) and chose a fine grained set of x points to make predictions.
英語のヒント
ここで、k(x,x1:n)はi=1,…,nについてk(x,xi)を評価してできる1×nのベクトルであり、k(x1:n,x1:n)はi,j=1,…,nについてk(xi,xj)を評価してできるn×nの行列である。mは任意のxについての点予測量として使えるもので、s2は不確かさに使うものである。f(x)が区間に入る確率が95%の区間を作りたければ、m±2sを使えばよい。上のすべての図の予測平均と不確かさは、これらの式を使って作った。観測したデータ点はf(x1),…,f(xn)で与えられ、予測をするためにxの点のきめ細かな集合を選んだ。
Let’s suppose we observe a single datapoint, f(x1), and we want to determine the value of f(x) at some x. Because f(x) is described by a Gaussian process, we know the joint distribution over (f(x),f(x1)) is Gaussian:
英語のヒント
一つのデータ点f(x1)を観測し、あるxでのf(x)の値を決めたいとしよう。f(x)はガウス過程で記述されるので、(f(x),f(x1))の上の同時分布はガウス分布であることがわかる。
[f(x)f(x1)]∼𝒩(μ,[k(x,x)k(x,x1)k(x1,x)k(x1,x1)])(18.1.6)
The off-diagonal expression k(x,x1)=k(x1,x) tells us how correlated the function values will be — how strongly determined f(x) will be from f(x1). We have seen already that if we use a large length-scale, relative to the distance between x and x1, ||x−x1||, then the function values will be highly correlated. We can visualize the process of determining f(x) from f(x1) both in the space of functions, and in the joint distribution over f(x1),f(x). Let’s initially consider an x such that k(x,x1)=0.9, and k(x,x)=1, meaning that the value of f(x) is moderately correlated with the value of f(x1). In the joint distribution, the contours of constant probability will be relatively narrow ellipses.
英語のヒント
非対角の式k(x,x1)=k(x1,x)は、関数の値がどれだけ相関するか、つまりf(x1)からf(x)がどれだけ強く決まるかを教えてくれる。xとx1の間の距離||x−x1||に比べて大きな長さスケールを使えば、関数の値は強く相関することはすでに見た。f(x1)からf(x)を決める過程は、関数の空間でも、f(x1),f(x)の上の同時分布でも可視化できる。まず、k(x,x1)=0.9かつk(x,x)=1となるxを考えよう。これは、f(x)の値がf(x1)の値とほどほどに相関していることを意味する。同時分布では、確率が一定の等高線は比較的細い楕円になる。
Suppose we observe f(x1)=1.2. To condition on this value of f(x1), we can draw a horizontal line at 1.2 on our plot of the density, and see that the value of f(x) is mostly constrained to [0.64,1.52]. We have also drawn this plot in function space, showing the observed point f(x1) in orange, and 1 standard deviation of the Gaussian process predictive distribution for f(x) in blue, about the mean value of 1.08.
英語のヒント
f(x1)=1.2を観測したとしよう。f(x1)のこの値で条件づけるには、密度のプロットの1.2のところに水平な線を引けばよく、f(x)の値がおおむね[0.64,1.52]に制約されることがわかる。このプロットは関数空間でも描いてあり、観測した点f(x1)をオレンジで、f(x)についてのガウス過程の予測分布の平均値1.08のまわりの1標準偏差を青で示している。
Now suppose we have a stronger correlation, k(x,x1)=0.95. Now the ellipses have narrowed further, and the value of f(x) is even more strongly determined by f(x1). Drawing a horizontal line at 1.2, we see the contours for f(x) support values mostly within [0.83,1.45]. Again, we also show the plot in function space, with one standard deviation about the mean predictive value of 1.14.
英語のヒント
次に、もっと強い相関k(x,x1)=0.95があるとしよう。すると楕円はさらに細くなり、f(x)の値はf(x1)によっていっそう強く決まる。1.2のところに水平な線を引くと、f(x)の等高線がおおむね[0.83,1.45]の中の値を支持していることがわかる。やはり、予測平均値1.14のまわりの1標準偏差とともに、関数空間でのプロットも示す。
We see that the posterior mean predictor of our Gaussian process is closer to 1.2, because there is now a stronger correlation. We also see that our uncertainty (the error bars) have somewhat decreased. Despite the strong correlation between these function values, our uncertainty is still righly quite large, because we have only observed a single data point!
英語のヒント
相関がより強くなったので、ガウス過程の事後平均による予測量は1.2に近づいていることがわかる。不確かさ(誤差棒)もいくぶん小さくなったこともわかる。これらの関数の値の間には強い相関があるにもかかわらず、不確かさは当然ながらまだかなり大きい。観測したデータ点が一つだけだからである!
This procedure can give us a posterior on f(x) for any x, for any number of points we have observed. Suppose we observe f(x1),f(x2). We now visualize the posterior for f(x) at a particular x=x′ in function space. The exact distribution for f(x) is given by the above equations. f(x) is Gaussian distributed, with mean
英語のヒント
この手続きにより、観測した点がいくつであっても、任意のxについてf(x)の事後分布が得られる。f(x1),f(x2)を観測したとしよう。ここでは、関数空間で、特定のx=x′でのf(x)の事後分布を可視化する。f(x)の正確な分布は上の式で与えられる。f(x)はガウス分布に従い、その平均は次のとおりである。
m=k(x,x1:3)k(x1:3,x1:3)−1f(x1:3)(18.1.7)
and variance
英語のヒント
そして分散は次のとおりである。
s2=k(x,x)−k(x,x1:3)k(x1:3,x1:3)−1k(x,x1:3)(18.1.8)
In this introductory notebook, we have been considering noise free observations. As we will see, it is easy to include observation noise. If we assume that the data are generated from a latent noise free function f(x) plus iid Gaussian noise ϵ(x)∼𝒩(0,σ2) with variance σ2, then our covariance function simply becomes k(xi,xj)→k(xi,xj)+δijσ2, where δij=1 if i=j and 0 otherwise.
英語のヒント
この導入のノートブックでは、ノイズのない観測を考えてきた。後で見るように、観測ノイズを含めるのはたやすい。データが、ノイズのない潜在的な関数f(x)に、分散σ2の独立同分布のガウスノイズϵ(x)∼𝒩(0,σ2)を加えたものから生成されると仮定すれば、共分散関数は単にk(xi,xj)→k(xi,xj)+δijσ2になる。ここで、i=jならδij=1、そうでなければ0である。
We have already started getting some intuition about how we can use a Gaussian process to specify a prior and posterior over solutions, and how the kernel function affects the properties of these solutions. In the following notebooks, we will precisely show how to specify a Gaussian process prior, introduce and derive various kernel functions, and then go through the mechanics of how to automatically learn kernel hyperparameters, and form a Gaussian process posterior to make predictions. While it takes time and practice to get used to concepts such as a “distributions over functions”, the actual mechanics of finding the GP predictive equations is actually quite simple — making it easy to get practice to form an intuitive understanding of these concepts.
英語のヒント
ガウス過程を使って解の上の事前分布と事後分布をどう指定できるか、そしてカーネル関数がこれらの解の性質にどう影響するかについて、すでにいくらか直観を得はじめている。次のノートブックでは、ガウス過程の事前分布をどう指定するかを正確に示し、さまざまなカーネル関数を紹介して導出し、それからカーネルのハイパーパラメータを自動的に学習し、予測をするためにガウス過程の事後分布を作る仕組みをたどる。「関数の上の分布」のような概念に慣れるには時間と練習が要るが、GPの予測の式を見つける実際の仕組みは実はかなり単純である。そのため、練習を積んでこれらの概念を直観的に理解するのはたやすい。