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

Error in bl_lin_matrix() for bbs-bl with small number of knots #30

Closed
sbrockhaus opened this issue Mar 9, 2016 · 0 comments
Closed

Error in bl_lin_matrix() for bbs-bl with small number of knots #30

sbrockhaus opened this issue Mar 9, 2016 · 0 comments

Comments

@sbrockhaus
Copy link
Member

@sbrockhaus sbrockhaus commented Mar 9, 2016

The Kronecker product %O% produces an error for bbs with small number of knots, which happens as Cholesky() is called but XtXis not a sparse matrix, see the following MWE

library(mboost)
### kronecker product for matrix-valued responses
data("volcano", package = "datasets")

## estimate mean of image treating image as matrix
image(volcano, main = "data")
x1 <- 1:nrow(volcano)
x2 <- 1:ncol(volcano)
vol <- as.vector(volcano)

## do the model fit with default number of knots 
mod <- mboost(vol ~ bbs(x1, df = 3, knots = 10)%O%
                bbs(x2, df = 3, knots = 10),
              control = boost_control(nu = 0.25))

## do the model fit with very few knots -> model fit gives error 
mod <- mboost(vol ~ bbs(x1, df = 3, knots = 3) %O%
                bbs(x2, df = 3, knots = 3),
              control = boost_control(nu = 0.25))

## error occurs because class(XtX) is "dsyMatrix" (Symmetric Dense Numeric Matrices), 
## usually class(XtX) is "dsCMatrix" (Numeric Symmetric Sparse (column compressed) Matrices)

I think that the problem can be solved by changing line
if (is(XtX, "Matrix") && !extends(class(XtX), "dgeMatrix")) {
https://github.com/boost-R/mboost/blob/master/pkg/mboostPatch/R/bkronecker.R#L80

to
if (is(XtX, "Matrix") && !extends(class(XtX), "dgeMatrix") && !extends(class(XtX), "dsyMatrix")) {

which simply excludes the corresponding Matrix-class.

But I don´t know whether there is a nicer or more general way to fix this.

@hofnerb hofnerb closed this in dfcb42c Mar 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.