Concordance index loop optimization

조회 수: 1 (최근 30일)
Andre
Andre 2014년 6월 6일
답변: Julio Chirinos 2018년 8월 14일
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