Concordance index loop optimization

1 vue (au cours des 30 derniers jours)
Andre
Andre le 6 Juin 2014
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 commentaires
Geoff Hayes
Geoff Hayes le 6 Juin 2014
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 le 7 Juin 2014
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.

Connectez-vous pour commenter.

Réponses (1)

Julio Chirinos
Julio Chirinos le 14 Août 2018
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!

Catégories

En savoir plus sur Problem-Based Optimization Setup dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by