Path: news.mathworks.com!not-for-mail
From: Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Mahalanobis Distance Calculation
Date: Tue, 02 Sep 2008 13:49:45 -0400
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <g9jubp$pkv$1@fred.mathworks.com>
References: <g999ca$lao$1@fred.mathworks.com>
NNTP-Posting-Host: perkinsp.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1220377785 26271 172.31.57.88 (2 Sep 2008 17:49:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 2 Sep 2008 17:49:45 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
In-Reply-To: <g999ca$lao$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:488294



Baris Yenidunya wrote:
> Hi,
> 
> I'm trying to understand how mahal function in MATLAB works.
> I see that the method used is different than the MD
> calculations in the literature. How is QR decomposition used
> here? Any help (maybe references, links etc.) will be
> appreciated.

Baris, presumably by "in the literature", you mean formulas like the one that appears in the help for MAHAL.  That's fine for understanding what the Mahalanobis distance is, but not so good for computational purposes.  MAHAL rewrites that explicit inversion of the cov matrix as a solution of a linear system, by noticing that the (squared) Mahalanobis distance can be expressed as

D = Y0*S^(-1)*Y0'
  = Y0*(X0'*X0)^(-1)*Y0'
  = Y0*((Q*R)'*(Q*R))^(-1)*Y0'
  = Y0*(R'*R)^(-1)*Y0'
  = Y0*R^(-1) * (Y0*R^(-1))'

and then noticing that you can do that using MATLAB's backslash operator.

Hope this helps.