Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rcpp::sourceCpp("wls.cpp") # could be found at http://pastebin.com/tjQZH4mF
- n <- 3e3
- p <- 250
- X <- matrix(rnorm(n * p), n , p)
- beta <- rnorm(p)
- w <- rgamma(n, 2, 0.8)
- y <- 3 + X %*% beta + rnorm(n)
- library(microbenchmark)
- microbenchmark(
- eigen_llt = eigen_llt(X, w, y),
- eigen_ldlt = eigen_ldlt(X, w, y),
- eigen_fullLU = eigen_fullLU(X, w, y),
- eigen_HHQR = eigen_HHQR(X, w, y),
- eigen_colPivHHQR = eigen_colPivHHQR(X, w, y),
- eigen_colPivHHQR2 = eigen_colPivHHQR2(X, w, y),
- eigen_fullPivHHQR = eigen_fullPivHHQR(X, w, y),
- eigen_chol_llt1 = eigen_chol_llt1(X, w, y),
- eigen_chol_llt2 = eigen_chol_llt2(X, w, y),
- eigen_chol_llt3 = eigen_chol_llt3(X, w, y),
- arma_qr = arma_qr(X, w, y), # can't run if n is too big
- arma_pinv = arma_pinv(X, w, y),
- arma_chol1 = arma_chol1(X, w, y),
- arma_chol2 = arma_chol2(X, w, y),
- arma_direct1 = arma_direct1(X, w, y),
- arma_direct2 = arma_direct2(X, w, y),
- r_lm = coef(lm(y ~ -1 + X, weights = w)),
- times = 30L
- )
- # Unit: milliseconds
- # expr min lq mean median uq max neval
- # eigen_llt 28.110632 28.948258 33.423318 32.54905 36.63961 44.53576 30
- # eigen_ldlt 28.129065 29.282958 32.727667 30.67310 37.51381 40.35114 30
- # eigen_fullLU 34.287646 35.749614 38.889749 38.54658 41.43950 48.89211 30
- # eigen_HHQR 29.888283 30.533398 34.936564 33.15014 38.08900 45.07672 30
- # eigen_colPivHHQR 31.604494 34.140191 37.039249 36.70178 39.98777 45.45033 30
- # eigen_colPivHHQR2 67.172129 69.476696 74.236885 72.72217 77.23037 87.46912 30
- # eigen_fullPivHHQR 35.756635 37.246105 41.402285 39.41492 44.82101 53.20575 30
- # eigen_chol_llt1 33.687293 35.178519 38.268742 36.46802 41.83886 48.73325 30
- # eigen_chol_llt2 33.959968 34.891216 38.718255 37.09338 40.96700 52.62032 30
- # eigen_chol_llt3 34.998003 37.179692 40.527737 39.75825 42.94214 52.67474 30
- # arma_qr 146.104368 175.283463 180.771476 180.86700 188.22000 199.38882 30
- # arma_pinv 20.749592 24.813379 25.908942 26.11721 26.72356 30.74258 30
- # arma_chol1 7.018150 9.342027 10.029506 10.72734 11.05824 11.82184 30
- # arma_chol2 9.392349 12.625824 12.894919 13.20482 14.00002 14.67966 30
- # arma_direct1 24.218292 26.676458 27.761042 27.84439 28.65510 33.66447 30
- # arma_direct2 6.620256 8.104752 9.310235 9.87699 10.57082 11.06409 30
- # r_lm 100.193242 114.279863 152.244977 154.67913 177.74953 262.16949 30
Advertisement
Add Comment
Please, Sign In to add comment