Giter Club home page Giter Club logo

powerit's Introduction

Power iterations in C++

Unit tests Documentation Codecov

Overview

Not much to say here, this repository just contains a header-only C++ library to perform power iterations. It's a quick-and-dirty method of getting the first eigenvector from a diagonalizable matrix - most typically from a covariance matrix, to get the first principal component. Well, maybe it's not so quick, but it doesn't add any dependencies and it'll get the job done. And sometimes that's enough.

Quick start

This is a header-only library, so usage is pretty simple:

#include "powerit/PowerIterations.hpp"
#include <random>

// Fill up the input matrix.
size_t ndim = 10;
std::vector<double> matrix(ndim * ndim);

// Compute the power iterations.
powerit::PowerIterations runner;
std::vector<double> eigenvector(ndim);
std::mt19937_64 rng(10);
runner.run(order, matrix.data(), eigenvector.data(), rng);

Building projects

CMake with FetchContent

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

include(FetchContent)

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

FetchContent_MakeAvailable(powerit)

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

# For executables:
target_link_libraries(myexe ltla::powerit)

# For libaries
target_link_libraries(mylib INTERFACE ltla::powerit)

CMake with find_package()

find_package(ltla_powerit CONFIG REQUIRED)
target_link_libraries(mylib INTERFACE ltla::powerit)

To install the library, use:

mkdir build && cd build
cmake .. -DPOWERIT_TESTS=OFF
cmake --build . --target install

By default, this will use FetchContent to fetch all external dependencies. If you want to install them manually, use -DPOWERIT_FETCH_EXTERN=OFF. See the commit hashes in extern/CMakeLists.txt to find compatible versions of each dependency.

Manual

If you're not using CMake, the simple approach is to just copy the files in include/ - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I. This requires the external dependencies listed in extern/CMakeLists.txt, which also need to be made available during compilation.

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.