Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit zeros get ignored when calculating the overlap matrix. #74

Open
ksiar137 opened this issue Mar 10, 2024 · 0 comments
Open

Explicit zeros get ignored when calculating the overlap matrix. #74

ksiar137 opened this issue Mar 10, 2024 · 0 comments

Comments

@ksiar137
Copy link

In the following line, an overlap matrix is created by converting the coo matrix to boolean, then to integer.

overlap_matrix = coo.astype(bool).astype(int).dot(coo.transpose().astype(bool).astype(int))

However, what this does is that it converts the ratings which are normalized to zero, to false values, which then get ignored in the count.
My proposed solution: create a matrix with ones for every value of the coo matrix:

Example:

print("Coo matrix:\n", coo)
print("coo as bool:\n",coo.astype(bool).astype(int))
ones_data = [1] * len(coo.data)
ones_matrix = coo_matrix((ones_data, (coo.row, coo.col)), shape=coo.shape)
print("ones matrix:\n",ones_matrix)

Output:

Coo matrix:
(0, 0) -0.6666666666666667
(1, 0) 0.33333333333333326
(2, 0) 0.33333333333333326
(1, 1) 0.5
(2, 1) 0.0
(3, 1) -0.5
(1, 2) 0.0
(2, 2) 0.5
(3, 2) -0.5
coo as bool:
(0, 0) 1
(1, 0) 1
(1, 1) 1
(1, 2) 0
(2, 0) 1
(2, 1) 0
(2, 2) 1
(3, 1) 1
(3, 2) 1
ones matrix:
(0, 0) 1
(1, 0) 1
(2, 0) 1
(1, 1) 1
(2, 1) 1
(3, 1) 1
(1, 2) 1
(2, 2) 1
(3, 2) 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant