Reputation: 435
I have a function that performs the HodgesLehmann robust mean over a vector x[m,n]. n is the batch index of data, m is the number of samples.
function HLe = HodgesLehmann(x)
% Obtain dimensions
[m,n] = size(x);
% Create xi and xj values with the i <= j restriction enforced
q = logical(triu(ones(m,m),0));
i = uint32((1:m)'*ones(1,m));
xi = x(i(q),:);
j = uint32(ones(m,1)*(1:m));
xj = x(j(q),:);
% Calculate pairwise means (Walsh averages)
W = (xi+xj)./2;
% Calculate ordinary median of Walsh averages
HLe = median(W);
I am looking for a way to accelerate this function, it does not scale well for large dimensions of x. Any way of accelerating this is also welcome.
Many thanks.
Upvotes: 1
Views: 62
Reputation: 221564
Inspired by this solution
, here's a possible (not tested for performance) improvement -
%// Calculate pairwise means (Walsh averages)
[I,J] = find(bsxfun(@le,[1:m]',[1:m])); %//'
W = (x(J,:) + x(I,:))./2;
%// Calculate ordinary median of Walsh averages
HLe = median(W);
Upvotes: 1