function [AD,AT]=combinedsimilarity(B,AD1,AT1,gamad1,gamad2,gamat1,gamat2,m,n)
%calculate the similarity between drugs

AD2=diag(sum(B));

for i=2:m
    for j=1:i-1
k=0;
for t=1:n
    if B(t,i)==B(t,j)&&B(t,j)==1
        k=k+1;
    end
end
AD2(i,j)=k;
    end
end

for i=1:m-1
    for j=i+1:m
       AD2(i,j)=AD2(j,i);
    end
end
%calculate the similarity between targets
AT2=diag(sum(B'));

for i=2:n
    for j=1:i-1
k=0;
for t=1:m
    if B(i,t)==B(j,t)&&B(j,t)==1
        k=k+1;
    end
end
AT2(i,j)=k;
    end
end

for i=1:n-1
    for j=i+1:n
       AT2(i,j)=AT2(j,i);
    end
end
for i=1:n
    if AT2(i,i)==0
        AT2(i,i)=1;
    end
end
for i=1:m
    if AD2(i,i)==0
        AD2(i,i)=1;
    end
end

for i=1:m
    for j=1:m
NAD2(i,j)=AD2(i,j)/sqrt(AD2(i,i))/sqrt(AD2(j,j));
    end
end

for i=1:n
    for j=1:n
NAT2(i,j)=AT2(i,j)/sqrt(AT2(i,i))/sqrt(AT2(j,j));
    end
end

AD=(gamad1.*AD1+gamad2.*NAD2)./(gamad1+gamad2);

AT=(gamat1.*AT1+gamat2.*NAT2)./(gamat1+gamat2);
end
