estimate_best_threshold.m 1.81 KB
Newer Older
Raghvendra Mall's avatar
Raghvendra Mall committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
function final_confidence_threshold_value = estimate_best_threshold(copylabels,best_level_hierarchy,confidence_best_level,A,mink,maxk,Q_prev,intervals)

%% Estimate the best connectivity threshold to use based on conductane/(connectivity*(n^2))
disp('Estimate best threshold for final selection of module using conductance and connectivity vs modularity');
max_noc = max(copylabels(:,best_level_hierarchy));
cids = unique(copylabels(:,best_level_hierarchy));
confidence_threshold_values = linspace(max(confidence_best_level),min(confidence_best_level),intervals);
Q_values = zeros(1,length(confidence_threshold_values));
for j=1:length(confidence_threshold_values)
    final_set_indices = [];
    threshold = confidence_threshold_values(j);
    for i=1:max_noc
        cid = cids(i);
        size_cid = length(copylabels(copylabels(:,best_level_hierarchy)==cid,best_level_hierarchy));
        if (confidence_best_level(cid)<=threshold && size_cid>=mink && size_cid <=maxk)
            final_set_indices = [final_set_indices; find(copylabels(:,best_level_hierarchy)==cid)];
        end
    end
    mod_score = modularity2(A(final_set_indices,final_set_indices),copylabels(final_set_indices,best_level_hierarchy));
    Q_values(j) = mod_score;
end
clear mod_score cond_score
plot(confidence_threshold_values,'ro');
hold on;
plot(Q_values,'b*-');
hold on
hline = refline([0 Q_prev]);
hline.Color = 'k';
legend('Inverse Confidence Threshold','Modularity','Previous Best Modularity');
xlabel('Inverse Confidence Threshold Intervals');
hold off
[~,idx] = min(abs(Q_values-Q_prev));
if (idx>=(intervals-2))
    idx = intervals-2;
end
final_confidence_threshold_value = confidence_threshold_values(idx);
clear confidence_best_level confidence_threshold_values Q_values Delta val final_set_indices cid size_cid idx winning_indices;
clear CC_prev Q prev_max_noc;