{"id":14067093,"url":"https://github.com/bwlewis/irlba","last_synced_at":"2025-04-13T14:47:17.318Z","repository":{"id":35771121,"uuid":"40050755","full_name":"bwlewis/irlba","owner":"bwlewis","description":"Fast truncated singular value decompositions","archived":false,"fork":false,"pushed_at":"2024-02-22T19:46:15.000Z","size":2759,"stargazers_count":127,"open_issues_count":34,"forks_count":17,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-25T07:29:27.556Z","etag":null,"topics":["pca","principal-component-analysis","singular-value-decomposition","sparse-principal-components","svd"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bwlewis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-01T15:25:48.000Z","updated_at":"2024-10-01T01:56:52.000Z","dependencies_parsed_at":"2023-02-16T12:45:56.247Z","dependency_job_id":"693d3a98-06f5-441f-81b5-939cba1ec168","html_url":"https://github.com/bwlewis/irlba","commit_stats":{"total_commits":297,"total_committers":4,"mean_commits":74.25,"dds":0.02020202020202022,"last_synced_commit":"bb71306fc3c17e4325b8e80aa627ee60c8edde01"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwlewis%2Firlba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwlewis%2Firlba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwlewis%2Firlba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwlewis%2Firlba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwlewis","download_url":"https://codeload.github.com/bwlewis/irlba/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732409,"owners_count":21152849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pca","principal-component-analysis","singular-value-decomposition","sparse-principal-components","svd"],"created_at":"2024-08-13T07:05:25.816Z","updated_at":"2025-04-13T14:47:17.277Z","avatar_url":"https://github.com/bwlewis.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# irlba\n\nImplicitly-restarted Lanczos methods for fast truncated singular value\ndecomposition of sparse and dense matrices (also referred to as partial SVD).\nIRLBA stands for Augmented, \u003cb\u003eI\u003c/b\u003emplicitly \u003cb\u003eR\u003c/b\u003eestarted \u003cb\u003eL\u003c/b\u003eanczos\n\u003cb\u003eB\u003c/b\u003eidiagonalization \u003cb\u003eA\u003c/b\u003elgorithm. The package provides the following\nfunctions (see help on each for details and examples).\n\n* `irlba()` partial SVD function\n* `ssvd()` l1-penalized matrix decompoisition for sparse PCA (based on Shen and Huang's algorithm)\n* `prcomp_irlba()`  principal components function similar to the `prcomp` function in stats package for computing the first few principal components of large matrices\n* `svdr()` alternate partial SVD function based on randomized SVD (see also the [rsvd](https://cran.r-project.org/package=rsvd) package by N. Benjamin Erichson for an alternative implementation)\n* `partial_eigen()` a very limited partial eigenvalue decomposition for symmetric matrices (see the [RSpectra](https://cran.r-project.org/package=RSpectra) package for more comprehensive truncated eigenvalue decomposition)\n\nHelp documentation for each function includes extensive documentation and\nexamples. Also see the package vignette, `vignette(\"irlba\", package=\"irlba\")`.\n\nAn overview web page is here: https://bwlewis.github.io/irlba/.\n\n## New in 2.3.2\n\n- Fixed a regression in `prcomp_irlba()` discovered by Xiaojie Qiu, see https://github.com/bwlewis/irlba/issues/25, and other related problems reported in https://github.com/bwlewis/irlba/issues/32.\n- Added rchk testing to pre-CRAN submission tests.\n- Fixed a sign bug in `ssvd()` found by Alex Poliakov.\n\n## What's new in Version 2.3.1?\n\n- Fixed an `irlba()` bug associated with centering (PCA), see https://github.com/bwlewis/irlba/issues/21.\n- Fixed `irlba()` scaling to conform to `scale`, see https://github.com/bwlewis/irlba/issues/22.\n- Improved `prcomp_irlba()` from a suggestion by N. Benjamin Erichson, see https://github.com/bwlewis/irlba/issues/23.\n- Significanty changed/improved `svdr()` convergence criterion.\n- Added a version of Shen and Huang's Sparse PCA/SVD L1-penalized matrix decomposition (`ssvd()`).\n- Fixed valgrind errors.\n\n\n## Deprecated features\n\nI will remove `partial_eigen()` in a future version. As its documentation\nstates, users are better off using the RSpectra package for eigenvalue\ncomputations (although not generally for singular value computations).\n\nThe `mult` argument is deprecated and will be removed in a future version. We\nnow recommend simply defining a custom class with a custom multiplcation\noperator.  The example below illustrates the old and new approaches.\n\n```{r}\nlibrary(irlba)\nset.seed(1)\nA \u003c- matrix(rnorm(100), 10)\n\n# ------------------ old way ----------------------------------------------\n# A custom matrix multiplication function that scales the columns of A\n# (cf the scale option). This function scales the columns of A to unit norm.\ncol_scale \u003c- sqrt(apply(A, 2, crossprod))\nmult \u003c- function(x, y)\n        {\n          # check if x is a  vector\n          if (is.vector(x))\n          {\n            return((x %*% y) / col_scale)\n          }\n          # else x is the matrix\n          x %*% (y / col_scale)\n        }\nirlba(A, 3, mult=mult)$d\n## [1] 1.820227 1.622988 1.067185\n\n# Compare with:\nirlba(A, 3, scale=col_scale)$d\n## [1] 1.820227 1.622988 1.067185\n\n# Compare with:\nsvd(sweep(A, 2, col_scale, FUN=`/`))$d[1:3]\n## [1] 1.820227 1.622988 1.067185\n\n# ------------------ new way ----------------------------------------------\nsetClass(\"scaled_matrix\", contains=\"matrix\", slots=c(scale=\"numeric\"))\nsetMethod(\"%*%\", signature(x=\"scaled_matrix\", y=\"numeric\"), function(x ,y) x@.Data %*% (y / x@scale))\nsetMethod(\"%*%\", signature(x=\"numeric\", y=\"scaled_matrix\"), function(x ,y) (x %*% y@.Data) / y@scale)\na \u003c- new(\"scaled_matrix\", A, scale=col_scale)\n\nirlba(a, 3)$d\n## [1] 1.820227 1.622988 1.067185\n```\n\nWe have learned that using R's existing S4 system is simpler, easier, and more\nflexible than using custom arguments with idiosyncratic syntax and behavior.\nWe've even used the new approach to implement distributed parallel matrix\nproducts for very large problems with amazingly little code.\n\n## Wishlist / help wanted...\n\n- More Matrix classes supported in the fast code path\n- Help improving the solver for singular values in tricky cases (basically, for ill-conditioned problems and especially for the smallest singular values); in general this may require a combination of more careful convergence criteria and use of harmonic Ritz values; Dmitriy Selivanov has proposed alternative convergence criteria in https://github.com/bwlewis/irlba/issues/29 for example.\n\n## References\n\n* Baglama, James, and Lothar Reichel. \"Augmented implicitly restarted Lanczos bidiagonalization methods.\" SIAM Journal on Scientific Computing 27.1 (2005): 19-42.\n* Halko, Nathan, Per-Gunnar Martinsson, and Joel A. Tropp. \"Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions.\" (2009).\n* Shen, Haipeng, and Jianhua Z. Huang. \"Sparse principal component analysis via regularized low rank matrix approximation.\" Journal of multivariate analysis 99.6 (2008): 1015-1034.\n* Witten, Daniela M., Robert Tibshirani, and Trevor Hastie. \"A penalized matrix decomposition, with applications to sparse principal components and canonical correlation analysis.\" Biostatistics 10.3 (2009): 515-534.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwlewis%2Firlba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwlewis%2Firlba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwlewis%2Firlba/lists"}