https://github.com/augustunderground/cosamp
CoSaMP algorithm in Haskell
https://github.com/augustunderground/cosamp
compressed-sensing cosamp haskell sparse-sampling
Last synced: 8 days ago
JSON representation
CoSaMP algorithm in Haskell
- Host: GitHub
- URL: https://github.com/augustunderground/cosamp
- Owner: AugustUnderground
- License: bsd-3-clause
- Created: 2022-12-29T00:30:49.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-29T00:34:07.000Z (over 3 years ago)
- Last Synced: 2026-05-17T06:03:02.321Z (28 days ago)
- Topics: compressed-sensing, cosamp, haskell, sparse-sampling
- Language: Haskell
- Homepage: https://augustunderground.github.io/cosamp
- Size: 140 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# CoSaMP
CoSaMP algorithm in Haskell.
[Documentation](https://augustunderground.github.io/cosamp)
## Use in Stack Project
Add this to `stack.yaml`:
```yaml
extra-deps:
- github: augustunderground/cosamp
commit: 264f4ec2f6a74d10a7cc484e0bbbe7f24d85d3cc
```
## Example
```haskell
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](http://arxiv.org/abs/0803.2392).
There are also reference implementations available in:
- [MATLAB](https://www.mathworks.com/matlabcentral/fileexchange/32402-cosamp-and-omp-for-sparse-recovery).
- [Python](https://github.com/rfmiotto/CoSaMP) which is based on