inst/tinytest/test_const_cost.R

test_const_cost <- function() {
  y <- c(1, 2, 1, -1, 4, 5, 10)
  w <- 1 + numeric(length(y))
  c1 <- const_cost(y, w, 1, 0, length(y)-1)
  
  out_est <- (sum(y*w) - y*w)/(sum(w) - w)
  c2 <- sum(w*(y-out_est)^2)
  
  expect_true(abs(c1-c2)<=1e-5)

  invisible(NULL)
}
  
test_const_cost()

Try the RcppDynProg package in your browser

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

RcppDynProg documentation built on Aug. 20, 2023, 9:07 a.m.