/cosamp

CoSaMP algorithm in Haskell

Primary LanguageHaskellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

CoSaMP

CoSaMP algorithm in Haskell.

Documentation

Use in Stack Project

Add this to stack.yaml:

extra-deps:
 - github: augustunderground/cosamp
   commit: 264f4ec2f6a74d10a7cc484e0bbbe7f24d85d3cc

Example

import CoSaMP
import Numeric.LinearAlgebra
import Graphics.Plot

main :: IO ()
main      = mplot [t, s] >> mplot [tWin, xWin, xWin']
  where 
    n     = 4096 :: Int
    t     = linspace n (0.0, 1.0 :: Double)
    x     = sin ( 91 * 2 * pi * t ) + sin ( 412 * 2 * pi * t )
    p     = 128 :: Int
    aquis = cmap floor 
          $ scale (realToFrac n - 1) (randomVector 666 Uniform p) :: Vector I
    y     = flatten $ asRow x ?? (All, Pos aquis)
    φ     = dctOrtho (ident n :: Matrix Double)
    cφ    = φ ?? (Pos aquis, All)
    s     = cosamp cφ y 10 100 1.0e-10
    x'    = idctOrtho s
    wIdx  = idxs $ find (\i -> i >= 0.4 && i <= 0.5) t
    tWin  = flatten $ asRow t ?? (All, Pos wIdx)
    xWin  = flatten $ asRow x ?? (All, Pos wIdx)
    xWin' = flatten $ asRow x' ?? (All, Pos wIdx)

Build From Source

$ git clone https://github.com/augustunderground/cosamp
$ cd cosamp
$ stack build
$ stack install
$ stack run

References and Resources

This is a Haskell implementation of the Compressive Sampling Matched Pursuit (CoSaMP) algorithm as presented in Needell and Tropp's 2008 paper.

There are also reference implementations available in: