Skip to content

Implement Hyndman's fix for non conforming forecast #45

@brunocarlin

Description

@brunocarlin
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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions