-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support sparse output for sandwich products #17
Comments
From @stanmart in Quantco/glum#543 (comment):
Actually, what might make even more sense is to have a class like In any case, it seems like the very first step would be to make the categorical-categorical operation here use a sparse matrix. This would involve the C++ implementation here: tabmat/src/tabmat/ext/cat_split_helpers-tmpl.cpp Lines 44 to 94 in 2428222
Unfortunately I'm not very familiar with C++. Does SciPy have a C++ API for sparse matrices? |
Creating a matrix class that can be split along both dimensions is a great end goal, but seems very complex. Having the option to return a fully sparse matrix would already be super helpful, and a great first step IMO.
I'm not sure. What should work though is that in scipy, sparse matrices are basically a collection of 1d vectors representing the data. We could construct these vectors in C++ using the numpy API, and then convert those into a sparse matrix in python using regular scipy functions. I think it should be quite performant. First we should figure out which kind of sparse matrix format would be the best fit for a sandwich product. After that, you could look into how those matrices are represented, and try to construct the necessary vectors. Do you think this makes sense? |
Isn't this difficult, because the length of the vectors is not known upfront? What size would we make the numpy arrays? |
Yeah that's a good point. So we will need to make a guess at the density of the sandwich product at some point. |
There are situations where we can expect ahead of time that the output of a sandwich product will be sparse:
(D^2 + 2 DM + M) / (D + M)^2
. IfM >> D
this matrix will be quite sparse. This could happen in an e-commerce pricing context, if features are a categorical product ID that is very high-dimensional and a small number of scalars.x.sandwich(d1)
and now we want to knowx.sandwich(d2)
. The latter will have the same sparsity pattern as the former.The text was updated successfully, but these errors were encountered: