celestialgod

test least square algorithm (R)

Dec 30th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.60 KB | None | 0 0
  1. Rcpp::sourceCpp("wls.cpp") # could be found at http://pastebin.com/tjQZH4mF
  2. n <- 3e3
  3. p <- 250
  4. X <- matrix(rnorm(n * p), n , p)
  5. beta <- rnorm(p)
  6. w <- rgamma(n, 2, 0.8)
  7. y <- 3 + X %*% beta + rnorm(n)
  8.  
  9. library(microbenchmark)
  10. microbenchmark(
  11.   eigen_llt = eigen_llt(X, w, y),
  12.   eigen_ldlt = eigen_ldlt(X, w, y),
  13.   eigen_fullLU = eigen_fullLU(X, w, y),
  14.   eigen_HHQR = eigen_HHQR(X, w, y),
  15.   eigen_colPivHHQR = eigen_colPivHHQR(X, w, y),
  16.   eigen_colPivHHQR2 = eigen_colPivHHQR2(X, w, y),
  17.   eigen_fullPivHHQR = eigen_fullPivHHQR(X, w, y),
  18.   eigen_chol_llt1 = eigen_chol_llt1(X, w, y),
  19.   eigen_chol_llt2 = eigen_chol_llt2(X, w, y),
  20.   eigen_chol_llt3 = eigen_chol_llt3(X, w, y),
  21.   arma_qr = arma_qr(X, w, y), # can't run if n is too big
  22.   arma_pinv = arma_pinv(X, w, y),
  23.   arma_chol1 = arma_chol1(X, w, y),
  24.   arma_chol2 = arma_chol2(X, w, y),
  25.   arma_direct1 = arma_direct1(X, w, y),
  26.   arma_direct2 = arma_direct2(X, w, y),
  27.   r_lm = coef(lm(y ~ -1 + X, weights = w)),
  28.   times = 30L
  29. )
  30. # Unit: milliseconds
  31. #               expr        min         lq       mean    median        uq       max neval
  32. #          eigen_llt  28.110632  28.948258  33.423318  32.54905  36.63961  44.53576    30
  33. #         eigen_ldlt  28.129065  29.282958  32.727667  30.67310  37.51381  40.35114    30
  34. #       eigen_fullLU  34.287646  35.749614  38.889749  38.54658  41.43950  48.89211    30
  35. #         eigen_HHQR  29.888283  30.533398  34.936564  33.15014  38.08900  45.07672    30
  36. #   eigen_colPivHHQR  31.604494  34.140191  37.039249  36.70178  39.98777  45.45033    30
  37. #  eigen_colPivHHQR2  67.172129  69.476696  74.236885  72.72217  77.23037  87.46912    30
  38. #  eigen_fullPivHHQR  35.756635  37.246105  41.402285  39.41492  44.82101  53.20575    30
  39. #    eigen_chol_llt1  33.687293  35.178519  38.268742  36.46802  41.83886  48.73325    30
  40. #    eigen_chol_llt2  33.959968  34.891216  38.718255  37.09338  40.96700  52.62032    30
  41. #    eigen_chol_llt3  34.998003  37.179692  40.527737  39.75825  42.94214  52.67474    30
  42. #            arma_qr 146.104368 175.283463 180.771476 180.86700 188.22000 199.38882    30
  43. #          arma_pinv  20.749592  24.813379  25.908942  26.11721  26.72356  30.74258    30
  44. #         arma_chol1   7.018150   9.342027  10.029506  10.72734  11.05824  11.82184    30
  45. #         arma_chol2   9.392349  12.625824  12.894919  13.20482  14.00002  14.67966    30
  46. #       arma_direct1  24.218292  26.676458  27.761042  27.84439  28.65510  33.66447    30
  47. #       arma_direct2   6.620256   8.104752   9.310235   9.87699  10.57082  11.06409    30
  48. #               r_lm 100.193242 114.279863 152.244977 154.67913 177.74953 262.16949    30
Advertisement
Add Comment
Please, Sign In to add comment