网站大量收购闲置独家精品文档,联系QQ:2885784924

怎样求马氏距离.doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
怎样求马氏距离

怎样求马氏距离(Mahalanobis distance )matlab版 HYPERLINK /blog/ \l m=0t=1c=fks_087068084081081071081087094095093080088070082087082 学习 2010-01-06 15:33:51 阅读396 评论1 字号:大中小 ? 求马氏距离(matlab版): 方法一:? X = [1 2; 1 3; 2 2; 3 1]; [mx,nx] = size(X); Dis = ones(mx,nx); Cov = cov(X); for i=1:mx for j=1:nx D(i,j)=((X(i,:)-X(j,:))*inv(C)*(X(i,:)-X(j,:)))^0.5; end end D X X = ???? 1???? 2 ???? 1???? 3 ???? 2???? 2 ???? 3???? 1 D D = ???????? 0??? 2.3452??? 2.0000??? 2.3452 ??? 2.3452???????? 0??? 1.2247??? 2.4495 ??? 2.0000??? 1.2247???????? 0??? 1.2247 ??? 2.3452??? 2.4495??? 1.2247???????? 0 2.3452???????? X的第一行向量与第二行向量之间的马氏距离。 ???? 2.0000???????? X的第一行向量与第三行向量之间的马氏距离。 ?? ? 。。。 方法二: X = [1 2; 1 3; 2 2; 3 1] X = ???? 1???? 2 ???? 1???? 3 ???? 2???? 2 ???? 3???? 1 Y = pdist(X,mahal) Y = ??? 2.3452??? 2.0000??? 2.3452??? 1.2247??? 2.4495??? 1.2247 function d = mahalanobis(X, Mu, C) %MAHALANOBIS Mahalanobis distance. % D = MAHALANOBIS(X, MU, C) returns the Mahalanobis distance between % the length p vectors X and MU given the p by p covariance matrix % C. If omitted, it is assumed that C is the identity matrix(单位矩阵/恒等矩阵) % EYE(p). If either X or MU is an n by p matrix, D will be returned % as an n by g matrix where n is the number of rows in X and g is % the number of rows in MU where each entry i, j corresponds to the % mahalanobis distance between row i of X and row j of MU. If MU is % simply 0, it is treated as the origin from which Mahalanobis % distance to X is calculated. C must be a positive, definite, % symmetric matrix. % % The Mahalanobis distance between vectors X(i,:) and MU(j,:) is % defined as: % % D(i,j) = ((X(i,:) - MU(j,:))*INV(C)*(X(i,:) - MU(j,:))).^(1/2) % Copyright (c) 1999 Michael Kiefte. % $Log$ error(nargchk(2, 3, nargin)) if isempty(X) | ~isa(X, double) | ~isreal(X) | ... any(any(isnan(X) | isinf(X))) error([X must be a vector or matrix of real, finite numeric ... doubles.]) elseif length(X) == prod(size(X)) X = X(:);

文档评论(0)

me54545 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档