earowang / hts

Hierarchical and Grouped Time Series
http://pkg.earo.me/hts
110 stars 36 forks source link

run QR decomposition if LU decomposition fails #18

Closed cbergmeir closed 8 years ago

cbergmeir commented 8 years ago

I had the following problem various times with fairly big hierarchies:

fc <- forecast(groupedSeries, parallel=TRUE, num.cores=2) Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)

Enter a frame number, or 0 to exit

1: forecast(groupedSeries, parallel = TRUE, num.cores = 2) 2: forecast.gts(groupedSeries, parallel = TRUE, num.cores = 2) 3: Comb(pfcasts, weights = wvec, keep = "bottom", algorithms = alg) 4: hts.R#178: combinef(x, groups = object$groups, ...) 5: LU(fcasts = fcasts, S = smat, weights = weights) 6: solve(lhs.l, rhs.l) 7: solve(lhs.l, rhs.l) 8: .local(a, b, ...) 9: solve(forceCspSymmetric(a, isTri = FALSE), b, tol = tol) 10: solve(forceCspSymmetric(a, isTri = FALSE), b, tol = tol) 11: .local(a, b, ...) 12: solve.dsC.dC(a, b, LDL = LDL, tol = tol) 13: .solve.dgC.lu(as(a, "dgCMatrix"), b = b, tol = tol) 14: LU.dgC(a)

This patch solves this issue by running a QR decomposition if the LU decomposition fails. The QR decomposition takes considerably longer and also takes a lot of memory, but less than other possibilities that I evaluated. Another advantage is that it is directly available in the Matrix package.