# tests/testthat/test_fast_laplace.R In bcs: Bayesian Compressive Sensing Using Laplace Priors

```context("Testing the main fast Laplace algorithm")

test_that("the output of the fast Laplace algorithm is correct for small signal"
, {
# testing when we round the maximum likelihood to 7 digits
test.e <- FastLaplace(b.for, signal, sd(signal) ^ 2 / 100, 1e-8, TRUE)
expect_equal(sum(test.e[[1]]), -0.142390884766597281)
expect_equal(sum(test.e[[2]]), 4430)
expect_equal(test.e[[3]][1], 0.40479148230739425696)
expect_equal(sum(test.e[[4]]), 0.23274684494650607625)
expect_equal(sum(test.e[[5]]), 1819749.4156093874481)
expect_equal(length(test.e[[1]]), 87)
x.lap <- rep(0, 150)
x.lap[test.e[[2]]] <- test.e[[1]]
expect_equal(FindSparse(b.for, signal, roundit = TRUE), x.lap)
})

# Using the bForEZ for idx==132 for Matlab and idx==126 and for R count==81
# and idx==65 is where the rounding difference is between R and matlab.

# skip_on_cran()
# test_that("the output of the fast Laplace algorithm is correct for large signal"
#           , {
#                                      'bcs_kron/Test_Files_To_Stay_Local/',
#                                      'bFor2.csv',sep=""),
#                                   'bcs_kron/Test_Files_To_Stay_Local/',
#                                   'signal2.csv',sep=""),
#   # testing when we round the maximum likelihood to 7 digits
#   test.e <- FastLaplace(bFor, signal, sd(signal)^2/800, 1e-8, TRUE)
#   expect_equal(sum(test.e[[1]]),0.095116009295516487643)
#   expect_equal(sum(test.e[[2]]),298117)
#   expect_equal(test.e[[3]][1], 0.011482830173325)
#   expect_equal(sum(test.e[[4]]),0.75847148556943433384)
#   expect_equal(sum(test.e[[5]]),18815188.135733500123)
#   expect_equal(length(test.e[[1]]), 551)
# })
```

## Try the bcs package in your browser

Any scripts or data that you put into this service are public.

bcs documentation built on May 29, 2017, 11:58 a.m.