The similarity of the active user with other users is obtained by the following formulas :
$$dif_{(u_i, j)}=|r_{(u_a, j)}-r_{(u_i, j)}|$$
$$sim_{dif_{(u_i, j)}}=\frac{-dif_{(u_i, j)}}{max_score-min_score}+1$$
$$sim_{(u_a, u_j)}=\frac{\sum_{j=1}^{N_j}sim_{(dif_{(u_i,j)})}}{N_j}$$
j is the row number for the items and i is the column number for the users in the ratings matrix.
\(u_i\) is a ith column user and \(u_a\) is an active user.
\(r_{(u_a, j)}\) is the rating of active user in the jth row and \(r_{(u_i, j)}\) is the rating of the ith user in the jth row.
\(dif_{(u_i, j)}\) is the difference of the rating for the ith user with the active user in the jth row.
\(sim_{dif_{(u_i, j)}}\) is the similarity of the ith user with the active user in the jth row.
\(sim_{(u_a, u_i)}\) is the similarity of the user i, with the active user.
\(N_j\) is the number of common items.
For example, suppose active user ratings are: {2, nan, 3, nan, 5} and one user ratings are: {3, 4, nan, nan, 1} then for ratings between 1 and 5:
dif={1, nan, nan, nan, 4} and
sim(dif)={\(\frac{-1}{5-1}+1\), nan, nan, nan, \(\frac{-4}{5-1}+1\)}={0.75, nan, nan, nan, 0}
and mean of sim(dif) is sim=0.375.