context("Test hamiltonian")
library(hamwrapper)
test_that("createHamiltonianSystem single variable", {
testModelFile = system.file("extdata", "test_normal.stan", package = "hamwrapper")
ham = createHamiltonianSystem(testModelFile, list(N = 1))
expect_equal(ham$M[1, 1], 1)
expect_equal(ham$data$N, 1)
expect_equal(ham$U(3), 4.5)
expect_equal(ham$H(3, 1), 5)
expect_equal(ham$gradU(3), 3)
expect_equal(ham$hessU(3)[1, 1], 1)
expect_equal(ham$hessUVecProd(3, c(2))[1, 1], 2)
expect_equal(nrow(ham$sampleMomentum()), 1)
expect_equal(ncol(ham$sampleMomentum()), 1)
})
test_that("createHamiltonianSystem two variables", {
testModelFile = system.file("extdata", "test_normal.stan", package = "hamwrapper")
ham = createHamiltonianSystem(testModelFile, list(N = 2))
expect_equal(ham$data$N, 2)
expect_equal(ham$U(c(3, 1)), 5)
expect_equal(ham$H(c(3, 1), c(1, 2)), 7.5)
expect_equal(ham$gradU(c(3, 1))[1], 3)
expect_equal(ham$gradU(c(3, 1))[2], 1)
expect_equal(ham$hessU(c(3, 1))[1, 1], 1)
expect_equal(ham$hessU(c(3, 1))[1, 2], 0)
expect_equal(ham$hessU(c(3, 1))[2, 1], 0)
expect_equal(ham$hessU(c(3, 1))[2, 2], 1)
expect_equal(ham$hessUVecProd(c(3, 1), c(4, 5))[1], 4)
expect_equal(ham$hessUVecProd(c(3, 1), c(4, 5))[2], 5)
expect_equal(nrow(ham$sampleMomentum()), 2)
expect_equal(ncol(ham$sampleMomentum()), 1)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.