function gm = geometric_median(X)
% 
% Calculate geometric median
%
% Input:
%   X: d x n data matrix
%
% Output:
%   gm: the geometric median
%
% Written by Detang Zhong (detang.zhong@canada.ca).
%
% Demo:
%  X = [ 1.1079,  0.5763,  0.3072,  1.2205,  0.8596, -1.5082,  2.5955,  2.8251,  1.5908,  0.4575;
%        1.555 ,  1.7903,  1.213 ,  1.1285,  0.0461, -0.4929, -0.1158,  0.5879,  1.5807,  0.5828;
%        2.1583,  3.4429,  0.4166,  1.0192,  0.8308, -0.1468,  2.6329,  2.2239,  0.2168,  0.8783;
%        0.7382,  1.9453,  0.567 ,  0.6797,  1.1654, -0.1556,  0.9934,  0.1857,  1.369 ,  2.1855;
%        0.1727,  0.0835,  0.5416,  1.4416,  1.6921,  1.6636,  1.6421,  1.0687,  0.6075, -0.0301;
%        2.6654,  1.6741,  1.1568,  1.3092,  1.6944,  0.2574,  2.8604,  1.6102,  0.4301, -0.3876];
%    
% gm = geometric_median(X)
% 
% gm =
% 
%             1.073252740111
%          0.897423504908394
%           1.19348836841726
%          0.912224563354612
%          0.997516404893268
%           1.34216520444616
% 

u = @(m)trace((m'*m).^.5); 
f=@(m)fminsearch(@(y)u(bsxfun(@minus,m,y)),m(:,1));
gm = f(X);

end


