A thin wrapper around RSpectra::svds(), please see more detailed documentation there. In particular, this function leverages the function interface.

# S3 method for sparseLRMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)

Arguments

A

Matrix to decompose.

k

Number of singular values to estimate.

nu

Number of left singular vectors to estimate.

nv

Number of right singular vectors to estimate.

opts

Passed to RSpectra::svds().

...

Passed to RSpectra::svds().

Value

A list with the following components:

d

A vector of the computed singular values.

u

An m by nu matrix whose columns contain the left singular vectors. If nu == 0, NULL will be returned.

v

An n by nv matrix whose columns contain the right singular vectors. If nv == 0, NULL will be returned.

nconv

Number of converged singular values.

niter

Number of iterations used.

nops

Number of matrix-vector multiplications used.

Examples

set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) X <- sparseLRMatrix(sparse = A, U = U, V = V) svds(X, 5)
#> $d #> [1] 64.419474 53.661569 43.567067 4.897897 4.176723 #> #> $u #> [,1] [,2] [,3] [,4] [,5] #> [1,] -0.135358576 0.011291330 0.108822337 0.0315439403 -0.002161246 #> [2,] 0.038002541 -0.054175907 0.136004409 -0.1054616689 -0.197775438 #> [3,] 0.025789539 0.196646465 0.081887282 -0.1065840100 -0.040676236 #> [4,] -0.009868219 -0.157807772 0.069816995 -0.3548566034 0.061703429 #> [5,] -0.015008176 -0.096480207 0.080746393 -0.0068696870 -0.005131836 #> [6,] -0.028064305 0.089168673 0.064757383 0.0124955899 0.028240459 #> [7,] 0.077422387 -0.173300447 0.007685578 -0.0356147011 0.002922649 #> [8,] 0.042291755 -0.035967529 -0.037978859 -0.0109265067 -0.014403929 #> [9,] 0.098474152 -0.101777781 0.165097038 -0.0704555541 0.001948247 #> [10,] -0.067552382 0.155481801 0.111609238 0.0099217410 -0.027725938 #> [11,] 0.121502142 -0.158625311 0.094853102 0.0085302544 -0.008382187 #> [12,] 0.022608517 -0.119407444 -0.092323103 0.4048968963 0.041203534 #> [13,] -0.214424167 0.230771209 0.118653679 0.0321146995 -0.099912279 #> [14,] -0.214765147 -0.038140430 0.161278557 0.3286319996 0.163887316 #> [15,] 0.091092831 -0.242661450 -0.091029080 -0.0116927424 -0.536961827 #> [16,] -0.281191839 0.092875893 -0.209836614 0.0367699592 0.043282744 #> [17,] -0.207591558 0.129474018 0.067901805 -0.0239862632 -0.011938275 #> [18,] -0.068311886 0.001165072 0.195223831 -0.0191610472 -0.093238907 #> [19,] 0.010919969 -0.088519286 0.121377157 -0.0139229421 0.011314844 #> [20,] 0.212524064 0.132319586 0.081923085 0.0012488923 0.032674930 #> [21,] -0.054918286 0.068489942 -0.104364967 0.0273083327 0.003213491 #> [22,] -0.358044377 -0.358075405 -0.191781053 0.0199312233 -0.043627606 #> [23,] 0.188506302 0.036898674 -0.056704312 -0.0421610821 0.030680370 #> [24,] -0.061029520 0.094912699 -0.115152242 0.0067414957 -0.029244705 #> [25,] 0.067410041 -0.094747665 -0.126221709 -0.0142510450 0.021808070 #> [26,] 0.163542340 -0.215265231 0.002077983 -0.0274002026 0.197867307 #> [27,] -0.239573167 -0.254989044 0.089963115 -0.0237572251 -0.049642923 #> [28,] 0.007577876 -0.228117483 -0.035914378 -0.0249758989 0.024898652 #> [29,] 0.006183136 0.039030377 -0.087337918 -0.0116109006 0.080485018 #> [30,] 0.197158999 0.083841174 -0.352567318 -0.0272686797 0.087277333 #> [31,] -0.075517281 -0.002866712 0.080256277 -0.0063739497 0.199264940 #> [32,] -0.159717022 0.065590392 0.028297165 0.0270762912 -0.004926960 #> [33,] 0.168469704 -0.208468087 0.013328119 -0.0522409137 0.021803082 #> [34,] -0.043098816 0.233038561 0.037884045 0.0184075033 -0.003538748 #> [35,] 0.166685734 0.065880612 0.144796426 -0.0070764597 -0.370074950 #> [36,] 0.019611304 -0.062003165 -0.183763932 0.0133584772 0.023631167 #> [37,] -0.178708365 -0.139025405 0.165540328 0.0111693110 -0.074275968 #> [38,] -0.006749842 -0.060171739 -0.187517316 0.0021867620 0.068910585 #> [39,] -0.165337262 -0.101174603 0.046419291 -0.0230194517 0.014152609 #> [40,] -0.079385242 0.006732197 0.229846932 -0.2858093802 0.319474375 #> [41,] 0.081301029 -0.181393787 0.003134183 0.4128972135 -0.024425917 #> [42,] -0.120217288 0.076614238 -0.216858551 0.0878694446 -0.316665239 #> [43,] 0.081118240 0.093022466 -0.433990203 -0.0158397937 0.071029716 #> [44,] -0.204910331 0.117378176 -0.069723348 0.0403616807 -0.003570621 #> [45,] 0.127050277 0.093104403 -0.004614622 -0.0361704248 -0.060400424 #> [46,] 0.148409425 0.263468305 0.053547089 -0.0459725260 -0.151001216 #> [47,] -0.130250379 -0.013839292 -0.060979963 0.0005080913 -0.038713743 #> [48,] 0.225301297 0.044193522 0.268226928 0.5215497401 0.060106953 #> [49,] 0.116847619 -0.020055414 -0.070799595 0.0465389167 0.353978939 #> [50,] -0.161506269 0.192260629 -0.075541805 0.1348494841 0.034502490 #> #> $v #> [,1] [,2] [,3] [,4] [,5] #> [1,] 0.011089554 -0.09835645 0.294859809 -0.079763809 0.0479603525 #> [2,] 0.128265533 -0.12448324 0.100799271 0.211672790 -0.0077497607 #> [3,] -0.152115820 0.11713069 0.254785935 -0.045620372 0.1023495524 #> [4,] -0.222215803 0.02120074 -0.161109491 -0.057304271 0.0985117155 #> [5,] 0.020743023 -0.40123207 0.039684261 0.022576814 0.0271095191 #> [6,] -0.077837077 0.05943323 0.000920890 -0.109514216 0.0061463328 #> [7,] -0.077414134 -0.14276040 0.084352109 -0.057569925 0.1479227224 #> [8,] -0.082358353 0.21619032 0.002670480 -0.043816487 -0.1342073533 #> [9,] 0.191491734 0.16955758 -0.114806161 -0.138745868 0.4434406473 #> [10,] 0.116924308 0.25769815 0.390924956 -0.009046152 0.3121906759 #> [11,] 0.116991253 -0.09067204 -0.160210627 0.027321321 -0.0266746609 #> [12,] 0.231023739 0.07194577 0.006082103 0.077050191 0.1833136902 #> [13,] -0.319872673 -0.26420833 0.129866273 -0.034415803 0.1865018504 #> [14,] 0.145662623 0.08308154 -0.111953262 0.023901697 -0.0707675982 #> [15,] -0.088856737 -0.08294422 0.025264117 0.020427148 0.0221372098 #> [16,] -0.057410064 0.09205483 -0.260171291 0.058000356 0.5088328963 #> [17,] 0.054512909 -0.11887341 0.058097140 -0.023289821 0.0004599574 #> [18,] 0.022442178 0.22118491 0.032057534 -0.011905508 -0.0205465812 #> [19,] 0.109628781 0.09466139 -0.105437336 -0.067876549 -0.0466029134 #> [20,] 0.010131867 0.04632185 -0.121509896 0.135725479 -0.0155096234 #> [21,] -0.031637390 -0.21454762 0.176450561 0.009698268 0.0020092798 #> [22,] 0.098643393 -0.17488029 -0.188959787 -0.061317973 -0.0324524660 #> [23,] 0.242908086 -0.29488637 0.001034275 0.078457063 0.2773883360 #> [24,] 0.076707719 -0.02726419 0.063183954 -0.859715667 -0.0136101360 #> [25,] 0.407249611 -0.09774790 -0.080288835 -0.114901623 0.2094806751 #> [26,] -0.094810377 0.16940874 -0.183305586 -0.031037967 0.1003278498 #> [27,] 0.108765542 -0.01088415 -0.211970627 0.025380964 -0.0452392438 #> [28,] 0.016806824 0.10239655 0.178311985 -0.014279076 0.0021476050 #> [29,] -0.075589395 -0.01516730 0.170957621 -0.017029801 0.0103134748 #> [30,] -0.093192698 -0.25417636 -0.190782357 0.005553381 0.0289627715 #> [31,] -0.047982908 -0.10614357 0.054840882 0.061414711 0.3288020988 #> [32,] 0.218492301 0.06101382 0.091419965 0.022182250 -0.0703493594 #> [33,] -0.052348678 -0.22668000 -0.051610514 -0.186243782 -0.0721426102 #> [34,] -0.015649129 0.13449015 0.061737863 0.022542937 0.0193006691 #> [35,] -0.415045293 0.07434542 -0.245123377 -0.052420699 0.1573703428 #> [36,] 0.306313266 0.10609267 -0.078860569 0.048626033 -0.1337740888 #> [37,] -0.025332229 -0.03502685 -0.321859610 -0.001813748 0.0094838222 #> [38,] -0.053026414 -0.06240710 0.203639148 0.231022735 0.0843669077 #> [39,] 0.156034704 -0.23903278 -0.024446008 -0.003380742 -0.0480567229 #> [40,] -0.005330896 -0.11284673 0.023911843 -0.089734485 -0.0200879877 #> #> $niter #> [1] 2 #> #> $nops #> [1] 67 #>