tests/testthat/test-utils-Numerics.R

context("Utils Numerics work")

skip_on_cran()

test_that("logSumExp", {
  
  x = rep(log(1),10)
  expect_equal(exp(BayesianTools:::logSumExp(x)), 10)
  expect_equal(exp(BayesianTools:::logSumExp(x,mean = T)), 1)  
  
  x = c(rep(log(1),9), -Inf)  
  expect_equal(exp(BayesianTools:::logSumExp(x)), 9)
  expect_equal(exp(BayesianTools:::logSumExp(x, mean = T)), 9/10)

  x = rep(-100, 100) 
  expect_equal(log(sum(exp(x))),   logSumExp(x))

  x = rep(-10000, 100) 
  expect(logSumExp(x))
  
})

Try the BayesianTools package in your browser

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

BayesianTools documentation built on Dec. 10, 2019, 1:08 a.m.