讓我們回到小球檢測的栗子,在一元高斯分布下,我們只使用了色相值這一個性質。然而,顏色其實是用多個維度來定義的。比如,在HSV模型下,除了色相值還有飽和度(Saturation)和亮度(Value)。而我們通常使用的三原色光模式(RGB模型)將顏色表示成紅色(R)、綠色(G)和藍色(B)的疊加。如果我們用RGB值來表示一個顏色,怎樣表示我們栗子中的小球呢?我們將圖片中所有像素點的RGB值用散點圖的形式畫出來可以得到下面的圖:

那我們怎樣對這種圖形進行建模呢?如這一節的題目所說,我們將一元高斯分布擴展到多元高斯分布並對RGB值進行建模。
讓我們首先來介紹多元高斯分布的數學形式吧:
![[公式]](/image/aHR0cHM6Ly93d3cuemhpaHUuY29tL2VxdWF0aW9uP3RleD1wJTI4JTVDYm9sZHN5bWJvbCU3QnglN0QlMjkrJTNEKyU1Q2ZyYWMlN0IxJTdEJTdCJTI4MiU1Q3BpJTI5JTVFJTdCRCUyRjIlN0QlN0MlNUNTaWdtYSU3QyU1RSU3QjElMkYyJTdEJTdEJTVDZXhwJTVDJTdCLSU1Q2ZyYWMlN0IxJTdEJTdCMiU3RCUyOCU1Q2JvbGRzeW1ib2wlN0J4JTdELSU1Q2JvbGRzeW1ib2wlNUNtdSUyOSU1RVQlNUNTaWdtYSU1RSU3Qi0xJTdEJTI4JTVDYm9sZHN5bWJvbCU3QnglN0QtJTVDYm9sZHN5bWJvbCU1Q211JTI5JTVDJTdE.png)
多元高斯分布和一元高斯分布是十分相似的,我們用加粗的
來表示變量(一個向量),
表示維度(元的數目),加粗的
表示平均向量,大寫的
表示協方差矩陣(Covariance Matrix,是一個方陣),
表示
的行列式值,
表示矩陣
的轉置。
值得一提的是協方差矩陣,它由兩部分組成,方差(Variance)和相關性(Correlation),對角線上的值表示方差,非對角線上的值表示維度之間的相關性。拿一個二維協方差矩陣作栗子:

其中,對角線上的
和
分別表示變量
和
的獨立方差,非對角線上的
表示兩個變量之間的相關性(注意
和
是相等的)。
回到小球檢測的栗子,我們考慮用RGB來對“紅色”小球進行多元高斯分布的建模,那么各個參數就如下圖所示了:
我們來看一下標准二元高斯分布圖:

2、求解多元高斯分布:最大似然估計
和求解一元高斯分布類似,我們將問題描述為:給定觀測值
,求
和
,使得似然函數最大:
![[公式]](/image/aHR0cHM6Ly93d3cuemhpaHUuY29tL2VxdWF0aW9uP3RleD0lNUNoYXQlN0IlNUNib2xkc3ltYm9sJTVDbXUlN0QlMkMrJTVDaGF0JTdCJTVDU2lnbWElN0QlM0QlNUN0ZXh0JTdCYXJnJTdEJTVDKyU1Q3VuZGVyc2V0JTdCJTVDYm9sZHN5bWJvbCU1Q211JTJDJTVDU2lnbWElN0QlN0IlNUNtYXglN0QlNUMrJTdCcCUyOCU1QyU3QiU1Q2JvbGRzeW1ib2wlN0J4X2klN0QlNUMlN0QlN0MlNUNib2xkc3ltYm9sJTVDbXUlMkMlNUNTaWdtYSUyOSU3RA==.png)
同樣,假設觀測值兩兩相互獨立,根據獨立概率公式,我們有:
![[公式]](/image/aHR0cHM6Ly93d3cuemhpaHUuY29tL2VxdWF0aW9uP3RleD0lNUNoYXQlN0IlNUNib2xkc3ltYm9sJTVDbXUlN0QlMkMrJTVDaGF0JTdCJTVDU2lnbWElN0QlM0QlNUN0ZXh0JTdCYXJnJTdEJTVDKyU1Q3VuZGVyc2V0JTdCJTVDYm9sZHN5bWJvbCU1Q211JTJDJTVDU2lnbWElN0QlN0IlNUNtYXglN0QlNUMrJTdCJTVDcHJvZF8lN0JpJTNEMSU3RCU1RU4rcCUyOCU1Q2JvbGRzeW1ib2wlN0J4X2klN0QlN0MlNUNib2xkc3ltYm9sJTVDbXUlMkMlNUNTaWdtYSUyOSU3RA==.png)
同樣(1)取對數,(2)將多元高斯分布的形式帶入,我們有:
![[公式]](/image/aHR0cHM6Ly93d3cuemhpaHUuY29tL2VxdWF0aW9uP3RleD0lNUNiZWdpbiU3QmFsaWduJTdEJTBBJTVDaGF0JTdCJTVDYm9sZHN5bWJvbCU1Q211JTdEJTJDKyU1Q2hhdCU3QiU1Q1N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GRzeW1ib2wlNUNtdSUyQyU1Q1NpZ21hJTdEJTdCJTVDbWluJTdEJTVDKyU1Q3N1bV8lN0JpJTNEMSU3RCU1RU4rJTI4KyU1Q2ZyYWMlN0IxJTdEJTdCMiU3RCUyOCU1Q2JvbGRzeW1ib2wlN0J4X2klN0QtJTVDYm9sZHN5bWJvbCU1Q211JTI5JTVFVCU1Q1NpZ21hJTVFJTdCLTElN0QlMjglNUNib2xkc3ltYm9sJTdCeF9pJTdELSU1Q2JvbGRzeW1ib2wlNUNtdSUyOSslMkIrJTVDZnJhYyU3QjElN0QlN0IyJTdEJTVDbG4rJTdDJTVDU2lnbWElN0MrKyUyOSUwQSU1Q2VuZCU3QmFsaWduJTdE.png)
我們給目標函數做個記號,令
![[公式]](/image/aHR0cHM6Ly93d3cuemhpaHUuY29tL2VxdWF0aW9uP3RleD1KJTI4JTVDYm9sZHN5bWJvbCU1Q211JTJDKyU1Q1NpZ21hJTI5KyUzRCslNUNzdW1fJTdCaSUzRDElN0QlNUVOKyUyOCslNUNmcmFjJTdCMSU3RCU3QjIlN0QlMjglNUNib2xkc3ltYm9sJTdCeF9pJTdELSU1Q2JvbGRzeW1ib2wlNUNtdSUyOSU1RVQlNUNTaWdtYSU1RSU3Qi0xJTdEJTI4JTVDYm9sZHN5bWJvbCU3QnhfaSU3RC0lNUNib2xkc3ltYm9sJTVDbXUlMjkrJTJCKyU1Q2ZyYWMlN0IxJTdEJTdCMiU3RCU1Q2xuKyU3QyU1Q1NpZ21hJTdDKyslMjk=.png)
我們仍然分別對
和
求偏導來計算
和
。(這里需要矩陣求導的知識,可以參考Matrix Calculus Manual)
![[公式]](/image/aHR0cHM6Ly93d3cuemhpaHUuY29tL2VxdWF0aW9uP3RleD0lNUNiZWdpbiU3QmFsaWduJTdEJTBBJTVDZnJhYyU3QiU1Q3BhcnRpYWwrSiU3RCU3QiU1Q3BhcnRpYWwrJTVDYm9sZHN5bWJvbCU1Q211JTdEJTBBJTI2JTNEKyU1Q2Zy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