思路
为最终比较划分好测试集和不存在边集【全集1-train-test-对角元】,根据集合中非零元【即边的数目】构建比较矩阵test_rd【比较n次,随机生成n个值右取整作为抽取的要比较的边】,下一步对test的邻接矩阵赋值,相似性指标给予一个分值存入test_pre,然后依据判断条件【test==1】只取其中非零边【为什么?降低内存?】,对应位置的test_pre存入test_data,再把最初的test_rd构建成稀疏矩阵【?为什么不直接比】,最后test_rd 和 non_rd比大小,分别给n',n''计算AUC
AUC计算方法
triu
triu Extract upper triangular part.提取上三角
function [ auc ] = CalcAUC( train, test, sim, n )
%% 计算AUC,输入计算的相似度矩阵
sim = triu(sim - sim.*train);%只保留上三角,因为同一条边取一次就足够了
对于CN来说





% 只保留测试集和不存在边集合中的边的相似度(自环除外)
non = 1 - train - test - eye(max(size(train,1),size(train,2)));

%1代表全集,全连通图,减去边集,减去对角元,剩下的为不存在边集

test = triu(test);

non = triu(non);

% 分别取测试集和不存在边集合的上三角矩阵,用以取出他们对应的相似度分值??【点乘sim,即后边的test_pre = sim .* test】
test_num = nnz(test);
non_num = nnz(non);

test_rd = ceil( test_num * rand( 1, n));



% ceil是取大于等于的最小整数,n为抽样比较的次数
non_rd = ceil( non_num * rand( 1, n));

这里开始不太懂
test_pre = sim .* test;%具体某条边乘他的相似性作为预测分值

non_pre = sim .* non;%具体某条不存在边乘他的相似性作为预测分值

这里不懂
test_data = test_pre( test == 1 )'; %????【将test中非零元对应位置的test_pre值取出存入test_data】
% 行向量,test 集合存在的边的预测值

non_data = non_pre( non == 1 )';

% 行向量,nonexist集合存在的边的预测值

test_rd = test_data( test_rd );

non_rd = non_data( non_rd );

clear test_data non_data;
n1 = length( find(test_rd > non_rd) );
n2 = length( find(test_rd == non_rd));

auc = ( n1 + 0.5*n2 ) / n;
end

网友评论