Open davidruegamer opened 8 years ago
Update: The most memory efficient and stable alternative to https://github.com/boost-R/mboost/blob/master/R/bl.R#L1111 seems to be
X <- t( KhatriRao( t(X1), t(X2) ) )
where KhatriRao is the KhatriRao
-function in the Matrix
package (calculating the eponymous matrix product). For smaller models, this function may on average be a bit slower than the original approach, but shows better worst case performance in simulations and -- most important -- does not fail to build the row-wise tensor product for large matrices.
@sbrockhaus
The row tensor product in the
%X%
-operator (https://github.com/boost-R/mboost/blob/master/R/bl.R#L1111) may fail for large matrices due to a stack overflow or "long vectors not supported yet"-error. This is particularly relevant when utilizing mboost for functional regression model estimation with FDboost. I do not know the exact number of rows and columns for each matrix to trigger this problem, but the calculation definitely fails with number of rows in the range of10^5
and at least one matrix with number of columns in the range of10^2
. In my case, for example, the dimension arec(4e5, 500)
andc(4e5, 25)
.An alternative approach, which does not crash for matrices of this size, could be
or
I have run some benchmarks to compare those with the original implementation. Both alternatives are not as fast as the original row tensor product in the case of sparse matrices for
X1
andX2
(the results for 1000 rows and 500 / 20 columns are, for example,) but seem to be (often much) faster for all non-sparse cases. Additionally the apply-versions do not fail for very large matrices and may even be parallalized (yielding a multiple faster computation in the order of number of used cores). Using the data.table-package one may further speed up the calculations by replacing
do.call("rbind",...)
withrbindlist
.Another more complicated solution could be a new Matrix-like class specifically for the representation of row tensor products, working and operating without the explicit calculation of the product itself.