Concordance index loop optimization

1 次查看(过去 30 天)
Hello, I'm implementing de concordance index measure (<http://biomet.oxfordjournals.org/content/92/4/965.abstract>) to compare a regression model with tru labels, and I attempted to do a loop based implementation that is currently very slow (see below). Does anybody know a good implementation of this measure, or how to optimize this code?
Thanks in advance
CODE:
function [ci] = acan_concordance_index(targets, predicts)
[~,i] = sort(targets,'descend');
predicts = predicts(i);
n = length(targets);
total = 0;
norm_z = 0;
for j=1:n
for k=j:n
if j ~= k
h = step_function(predicts(j) - predicts(k));
total = total + h;
norm_z = norm_z + 1;
end
end
end
ci = total / norm_z;
end
function h = step_function(diff)
if diff > 0
h = 1;
elseif diff == 0
h = 0.5;
else
h = 0;
end
end
  2 个评论
Geoff Hayes
Geoff Hayes 2014-6-6
In the above code, the outer for loop is iterating over j and the inner for loop is iterating over k. Yet h is being calculated as
h = step_function(predicts(i) - predicts(j));
Do you mean to be using i which is a vector returned from the sort function?
Andre
Andre 2014-6-7
Yes Geoff, I misstyped it, and already edited. I also changed the inner loop to begin with j, as the list is already ordered. I found a nice definition of the c-index here: https://stat.ethz.ch/pipermail/r-help/2008-December/182565.html The code seems to match mine, but it is also non optimized.
Thanks for the reply.

请先登录,再进行评论。

回答(1 个)

Julio Chirinos
Julio Chirinos 2018-8-14
does anybody have a function to compute the Harrel c index in Matlab? I have reached out to the Mathworks to no avail. Any help would be greatly appreciated. Alternatively, in the function above, what is targets and predicts? how do I go from the output of coxphfit to these 2 arguments in order to use the function? Thank you!

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by