- Notifications
You must be signed in to change notification settings - Fork15
-
Hi, I am new to graphblas. I want to use matrix-matrix multiplication on two matrices A and B with the union of entries from both instead of their intersection. For instance, I need to compute the boolean value of A[i,j] -> B[j,k] for (i,j) in A or (j,k) in B (for all entries in A and B, only A and only B). The "->" means logical implication. The mxm function does not support this since it uses the intersection. My current workaround creates iso matrices with default False values to be added to A and B but this makes them dense and slows computation significantly. I wonder if anyone could suggest a better solution. Thanks a lot! |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 7 comments 7 replies
-
Great question, thanks for asking! You are correct that GraphBLAS or any implementations do not yet support this natively. I asked@DrTimothyAldenDavis a while ago about the feasibility of implementing this, and as I recall he said it would be a non-trivial amount of work, so we would really like to see and understand compelling use cases. pydata/sparse does support a data model where you can set the value of the missing elements and can generally treat its data structures like numpy arrays. We can convert to and from it (see docs), but I don't know many people who have done this or how the performance will be. For this particular problem, since we're only dealing with boolean values, we may be able to find another solution. If I understand correctly, you want to compute this but using union instead of intersection, right? C=gb.semiring.lor_lor(A @B).new() Perhaps this (or something like it) could work: C=gb.semiring.lor_lor(A @B).new()a=A.reduce_rowwise("lor").new()b=B.reduce_columnwise("lor").new()C("lor")<<a.outer(b,"lor") I'm not entirely confident I understand your specific question, so in case I didn't and this above doesn't work, can you provide example inputs and output that we can play around with? Also, what operations would you want to do if mxmdid support union of elements instead of intersection? |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thank you. But I am unsure what the reductions are for. I provided another example in the thread below. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I don't follow your description. Can you be more specific? Like C(i,j) = some formula? Even a brute force triply nested O(n^3) for loop description would be helpful: because I'm confused with your notation of A(i,j), since I like to think of C(i,j) = sum_(k in intersection of A(i,:) and B(:,j)) of A(i,k)*B(k,j), and you're using the indices in a different way. |
BetaWas this translation helpful?Give feedback.
All reactions
-
It might be possible to work on the intersection, and compute the results on the union after that. The output C(i,j) be a tuple that contains (value,count), where value is the result over the intersection and count is the size of the intersection. Then multiplying C on left and right by diagonal matrices (containing the row degree of A and column degree of B) could then be used to compute the result on the union. But I don't yet know what is being computed outside the intersection so I'm unsure. In the sparse matrix A, what are the values of the entries present? What is the implied value of the entry not present? And likewise for B and C? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I need to check if all col elements in B overlap with row elements in A, so B transpose is a subset of A. Each comparison at C[i, j] gives True or False based on C[i,j] = /\ (A[i,j] v B[j,k]) or None if the conjunction has all None. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Thanks for the suggestions@DrTimothyAldenDavis@eriknw. To clarify, consider two matrices A and B (T, F and True and False, E is empty): I am looking for C = gb.semiring.land_lor(A @ B) where lor is applied to the union of elements. Pseudo code description: I have a solution which negated A so I could do A @ B with the intersection and then negated the result back. I used iso to do the negation so the overall time should be less than O(n^2). But I wonder if the negations could be avoided. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I also wonder about the differences between python-graphblas and pygraphblas on computation times. Does python-graphblas give better runtimes in general because it delays the computation and does it all at once? |
BetaWas this translation helpful?Give feedback.
All reactions
-
You have "or = False" in the pseudo code. That becomes c(i,j) so c(i,j) is never empty. But C has empty entries. I'm still confused |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks for spotting this. "or" should be Empty when or_k is Empty. |
BetaWas this translation helpful?Give feedback.
All reactions
-
The computation of or_k is also a bit unclear.
So if both A(i,k) and B(k,j) are empty, then or_k is empty. Otherwise, you do a logical or ... but that doesn't mean anything if one of the inputs is not present. What is "empty OR true"? The operators in GraphBLAS are never given empty inputs. |
BetaWas this translation helpful?Give feedback.
All reactions
-
And I don't think you mean this:
also, your example for A and B just show two kinds of entries: True and Empty. Can they be False? Or are both A and B iso-valued (where all entries present are equal to the same value, True in this case)? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I'm trying to understand what you want to compute so I can suggest an alternative. Matrix-matrix multiply will never be able to work on this set union approach, but there could likely be an alternative method where you use matrix-matrix multiply to operate on the set intersection, and then another step to account for entries outside that intersection. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I will give it another go. My original question was if LAND_LOR semiring in matrix-matrix multiplication can be first applied to the union of elements. Step 1, I want to apply LOR between every row in A and col in B, where at least A[i,k] or B[k,j] is non-empty, I don't care about the rest. A and B have no False values. I am unsure about making them iso matrices since they are sparse. But can I have a sparse iso matrix? Thanks. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have a reaction network which is a hypergraph. Substances are nodes and reactions are edges, where an edge can join any number of nodes. I want to know if target substances can be reached from source substances. I have to check which reactions can fire - do I have the right types of substances for every reaction? There are two matrices, A' and B', which encode the substances that reactions need and produce. I thought LAND_LOR semiring in matrix-matrix multiplication could tell me which reactions can fire. |
BetaWas this translation helpful?Give feedback.