Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Hyndman's fix for non conforming forecast #45

Open
brunocarlin opened this issue Nov 16, 2018 · 0 comments
Open

Implement Hyndman's fix for non conforming forecast #45

brunocarlin opened this issue Nov 16, 2018 · 0 comments

Comments

@brunocarlin
Copy link

sensible_forecasts <-
  function(forecasts,
           force_signal = c("positive", "negative"),
           max_iterations = 1000,
           threshold = 0,
           nodes,
           groups,
           weights = NULL,
           algorithms = c("lu", "cg","chol", "recursive", "slm"),
           prose = FALSE)
  {
counter = 1
if (force_signal == "positve") {
  comparisson = `>=`
  rounding_function = ceiling
} else {
  comparisson = `<=`
  rounding_function = floor
}

transformation <- function(x)  ifelse(comparisson(x,0),x,0) 


repeat {
forecasts <- transformation(forecasts)  
y_f <- combinef(forecasts,nodes,groups,weights,algorithms)
forecasts <- aggts(y_f) %>% rounding_function()
counter = counter + 1
if (all(comparisson(forecasts,threshold)) | counter == max_iterations ) {
  forecasts <- transformation(forecasts)
  if (prose == TRUE) {print(paste0("Number of attempts", counter)) }
  break
  }
}
return(forecasts)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant