Giter Club home page Giter Club logo

kryburycompress.jl's Introduction

KryburyCompress

The purpose of this package is to enable the compression of possibly high dimensional covariance matrices that are well represented by low-rank approximations. In general, when covariances in data are large, one must store either an N x N covariance matrix or, one makes the gross approximation that the covariance matrix is diagonal. This package allows interpolation between those two limits, finding a fast, low rank approximation to the covariance matrix which is exported as a type with fast matrix-vector multiplication. We provide read/write methods to store this object in a FITS file, to allow multilingual compatability.

Installation

Currently, installation is directly from the GitHub

import Pkg
Pkg.add(url="https://github.com/andrew-saydjari/KryburyCompress.jl")

Compression

Given a matrix $M$, we find an approximation $M \approxeq A + V * V'$ where $A$ is Diagonal and $V$ is a skinny matrix, containing the largest eigenvectors of $M$. The largest eigenvectors are found in-practice using Krylov methods from KrylovKit.jl. Then, $A$ is simply the residual diagonal between $M$ and $V * V'$. This compression can be massively accelerated when $M$ is itself composed of products of low-rank matrices represented via LowRankOps.jl.

Example Usage:

We use a LowRankMultMat and LowRankDiagMat here to speed up the compression. In this example, $M = (U * U') - (U * U') * D * (U * U')$ and we want to find a low-rank approximation to $M$.

using KryburyCompress
using LinearAlgebra, KrylovKit, FITSIO, LowRankOps
using Random: seed!

seed!(123)
n_big = 100
n_lit = 2

D = 1e-4*abs.(randn(n_big))
U = randn(n_big,n_lit)

function Cii_precomp_mult(matList)
    return []
end

function Cii_fxn_mult(matList,precompList,x)
    Ctotinv = matList[1]
    Vi = matList[2]
    arg2 = Vi*(Vi'*x)
    return arg2 - Vi*(Vi'*(Ctotinv*arg2))
end

function Cii_precomp_diag(matList)
    Ctotinv = matList[1]
    Vi = matList[2]
    return [Vi'*(Ctotinv*Vi)]
end

function Cii_diag_map(matList,precompList)
    Vi = matList[2]
    arg1 = precompList[1]
    return dropdims(sum(Vi.^2,dims=2),dims=2).-dropdims(sum(Vi'.*(arg1*Vi'),dims=1),dims=1)
end

BMat = LowRankMultMat([Diagonal(D),U],Cii_precomp_mult,Cii_fxn_mult);
BMatDiag = LowRankDiagMat([Diagonal(D),U],Cii_precomp_diag,Cii_diag_map);

W = kryburyCompress(BMat,BMatDiag,n_big)

I/O

The DiagWoodbury object resulting from the compression can be written and read to a FITS file using

fname = "example.fits"
save(W,fname)
W = read_krybury(fname)

Each of the fields from the DiagWoodbury object are saved as different extensions in the FITS file.

kryburycompress.jl's People

Contributors

andrew-saydjari avatar

Stargazers

 avatar

Watchers

 avatar

kryburycompress.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

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.