tests/testthat/test_dirichlet_hmm.R

context("Hidden Markov Model")

testData <- c(rnorm(50, 1, sqrt(3)), rnorm(50, 3, sqrt(3)), rnorm(50, 5, sqrt(3)))
normMD <- GaussianMixtureCreate()

expNames <- c("data", "n", "mixingDistribution", "states", "uniqueParams", "params", "alpha", "beta")

HMM_dp_test <- function(dp){

  expect_is(dp, c("list", "markov", "dirichetprocess", "normal", "conjugate"))
  expect_is(dp$states, "integer")
  expect_length(dp$states, length(dp$data))
  expect_length(dp$params, length(dp$data))
  expect_length(dp$alpha, 1)
  expect_length(dp$beta, 1)

}

test_that("Create",{

  dp <- DirichletHMMCreate(testData, normMD, 2, 3)

  expectedValues <- expNames
  expect_equal(names(dp), expectedValues)

  HMM_dp_test(dp)
})

test_that("Update States Integration", {

  dp <- DirichletHMMCreate(testData, normMD, 2, 3)

  dp <- UpdateStates(dp)

  expectedValues <- expNames
  expect_equal(names(dp), expectedValues)

  HMM_dp_test(dp)
})

test_that("Update Parameters Integration", {

  dp <- DirichletHMMCreate(testData, normMD, 2, 3)
  dp <- UpdateStates(dp)
  dp <- param_update(dp)

  expectedValues <- expNames
  expect_equal(names(dp), expectedValues)

})

test_that("Fit Inner", {

  dp <- DirichletHMMCreate(testData, normMD, 2, 3)
  dp <- fit_hmm(dp, 10)

  HMM_dp_test(dp)


})

test_that("Fit Dispatch", {

  dp <- DirichletHMMCreate(testData, normMD, 2, 3)
  dp <- Fit(dp, 10)

  HMM_dp_test(dp)

})

Try the dirichletprocess package in your browser

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

dirichletprocess documentation built on Aug. 25, 2023, 5:19 p.m.