mahal
混合ガウス成分に対するマハラノビス距離
説明
例
マハラノビス距離の測定
関数 mvnrnd
を使用して、2 つの二変量ガウス分布の混合に従う確率変量を生成します。関数 fitgmdist
を使用して、生成されたデータに混合ガウス モデル (GMM) を当てはめます。次に、生成されたデータと当てはめた GMM の混合成分の間のマハラノビス距離を計算します。
2 つの二変量混合ガウス成分の分布パラメーター (平均と共分散) を定義します。
rng('default') % For reproducibility mu1 = [1 2]; % Mean of the 1st component sigma1 = [2 0; 0 .5]; % Covariance of the 1st component mu2 = [-3 -5]; % Mean of the 2nd component sigma2 = [1 0; 0 1]; % Covariance of the 2nd component
各成分から同じ個数の確率変量を生成し、2 組の確率変量を結合します。
r1 = mvnrnd(mu1,sigma1,1000); r2 = mvnrnd(mu2,sigma2,1000); X = [r1; r2];
結合したデータ セット X
には、2 つの二変量ガウス分布の混合に従う確率変量が含まれています。
2 成分の GMM を X
に当てはめます。
gm = fitgmdist(X,2)
gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.500000 Mean: -2.9617 -4.9727 Component 2: Mixing proportion: 0.500000 Mean: 0.9539 2.0261
fitgmdist
は、2 つの混合成分を使用して GMM を X
に当てはめます。Component
1
の平均は [-2.9617,-4.9727]
、Component
2
の平均は [0.9539,2.0261]
であり、それぞれ mu2
および mu1
に近くなっています。
gm
の各成分に対する X
内の各点のマハラノビス距離を計算します。
d2 = mahal(gm,X);
scatter
を使用して、X
をプロットします。マーカーの色を使用して、Component
1
に対するマハラノビス距離を可視化します。
scatter(X(:,1),X(:,2),10,d2(:,1),'.') % Scatter plot with points of size 10 c = colorbar; ylabel(c,'Mahalanobis Distance to Component 1')
入力引数
gm
— 混合ガウス分布
gmdistribution
オブジェクト
混合ガウス分布。混合ガウス モデル (GMM) とも呼ばれます。gmdistribution
オブジェクトを指定します。
gmdistribution
オブジェクトは、gmdistribution
または fitgmdist
を使用して作成できます。分布パラメーターを指定して gmdistribution
オブジェクトを作成するには、関数 gmdistribution
を使用します。固定数の成分に対して gmdistribution
モデルをデータに当てはめるには、関数 fitgmdist
を使用します。
X
— データ
n 行 m 列の数値行列
データ。n 行 m 列の数値行列を指定します。n は観測値の個数、m は各観測値の変数の個数です。
X
の行に NaNs
が含まれている場合、mahal
はその行を計算から除外します。d2
内の対応する値は NaN
になります。
データ型: single
| double
出力引数
詳細
マハラノビス距離
マハラノビス距離は、標本点と分布の間の尺度です。
ベクトル x から平均 μ および共分散 Σ をもつ分布までのマハラノビス距離は次のようになります。
この距離は、標準偏差単位で x が平均からどの程度離れているかを表します。
mahal
は、X
内の各観測値から gm
内の混合成分までのマハラノビス平方距離 d2 を返します。
バージョン履歴
R2007b で導入
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)