GithubHelp home page GithubHelp logo

alexpghayes / cppirlba Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ltla/cppirlba

0.0 1.0 0.0 848 KB

A C++ port of the IRLBA algorithm, based on the C code in the R package.

CMake 1.95% C++ 96.04% Shell 0.53% R 1.48%

cppirlba's Introduction

C++ library for IRLBA

Unit tests Documentation Irlba comparison Codecov

Overview

This repository contains a header-only C++ library implementing the Augmented Implicitly Restarted Lanczos Bidiagonalization Algorithm (IRLBA) from Baglama and Lothar (2005). IRLBA is a fast and memory-efficient method for truncated singular value decomposition, and is particularly useful for approximate principal components analysis of large matrices. The code here is derived from the C code in the irlba R package, refactored to use the Eigen library for matrix algebra.

Quick start

Using this library is as simple as including the header file in your source code:

#include "irlba/irlba.hpp"

irlba::Irlba runner;

// optional; specify the number of singular vectors, workspace, etc.
runner.set_number(5).set_work(20);

auto result = runner.run(mat, false, false, U, V, S);
result.U; // left singular vectors
result.V; // right singular vectors
result.S; // singular values

To perform a PCA:

auto res = runner.run(mat, true, false);
Eigen::MatrixXd components = res.U;
components *= res.S.asDiagonal();

See the reference documentation for more details.

Building projects

If you're using CMake, you just need to add something like this to your CMakeLists.txt:

include(FetchContent)

FetchContent_Declare(
  irlba 
  GIT_REPOSITORY https://github.com/LTLA/CppIrlba
  GIT_TAG master # or any version of interest
)

FetchContent_MakeAvailable(irlba)

Then you can link to irlba to make the headers available during compilation:

# For executables:
target_link_libraries(myexe irlba)

# For libaries
target_link_libraries(mylib INTERFACE irlba)

If you're not using CMake, the simple approach is to just copy the files - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I. Note that this requires manual management of a few dependencies:

  • Eigen, for matrix manipulations.
  • aarand, for system-agnostic random distribution functions.

References

Baglama, James, and Lothar Reichel (2005). Augmented implicitly restarted Lanczos bidiagonalization methods. SIAM J. Sci. Comput., 27(1), 19-42.

cppirlba's People

Contributors

ltla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.