-
Notifications
You must be signed in to change notification settings - Fork 36
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
MinT needs covariance matrix to be positive definite. #43
Comments
@brunocarlin Hello, I ran into the same problem, have you solved this problem yet? I rounded both the residuals and replaced any 0s with 0.1s or 1s, but still got this error. |
I think our problem was the series full of zeros or some other number, try adding random noise, I will be honest , in my final version I stuck with hts because Mint was too advanced for me |
Hello, |
This occurs when you have a constant column in your data set. It is impossible to estimate covariances when one of the series is constant. Add some small random noise to the constant column and it should be ok. |
Ah, works fine now after adding random noise via rnorm() |
I added noise to both the forecast and residuals and still get this error. |
Same here. |
Same error here, this time it occurs even if series is not constant, so any of the solution mentioned helps library(dplyr , quietly = TRUE)
library(tsibble, quietly = TRUE)
library(fable , quietly = TRUE)
tsibble::tourism %>%
filter(State == 'ACT') %>%
aggregate_key(State / Region, Trips = sum(Trips)) %>%
model(base = fable::SNAIVE(Trips)) %>%
reconcile(mint_cov = min_trace(base, method = "mint_cov")) %>%
forecast(h = 1)
#> Error in `mutate()`:
#> ! Problem while computing `mint_cov = (function (object, ...) ...`.
#> Caused by error:
#> ! min_trace needs covariance matrix to be positive definite. Created on 2022-05-26 by the reprex package (v2.0.1) Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.3 (2022-03-10)
#> os Ubuntu 20.04.4 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz Etc/UTC
#> date 2022-05-26
#> pandoc 2.11.4 @ /usr/lib/rstudio-server/bin/pandoc/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> anytime 0.3.9 2020-08-27 [2] CRAN (R 4.0.4)
#> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.4)
#> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.3)
#> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.2)
#> crayon 1.5.0 2022-02-14 [2] CRAN (R 4.1.2)
#> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.2)
#> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.2)
#> distributional 0.3.0 2022-01-05 [2] CRAN (R 4.1.2)
#> dplyr * 1.0.8 2022-02-08 [2] CRAN (R 4.1.2)
#> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1)
#> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.2)
#> fable * 0.3.1 2021-05-16 [2] CRAN (R 4.1.1)
#> fabletools * 0.3.2.9000 2022-03-16 [2] Github (tidyverts/fabletools@3003027)
#> fansi 1.0.2 2022-01-14 [2] CRAN (R 4.1.2)
#> farver 2.1.0 2021-02-28 [2] CRAN (R 4.0.4)
#> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.0.4)
#> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.2)
#> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.2)
#> ggplot2 3.3.5 2021-06-25 [2] CRAN (R 4.1.1)
#> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.2)
#> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.4)
#> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1)
#> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1)
#> knitr 1.37 2021-12-16 [2] CRAN (R 4.1.2)
#> lattice 0.20-45 2021-09-22 [4] CRAN (R 4.1.1)
#> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.2)
#> lubridate 1.8.0 2021-10-07 [2] CRAN (R 4.1.2)
#> magrittr 2.0.2 2022-01-26 [2] CRAN (R 4.1.2)
#> Matrix 1.4-1 2022-03-23 [4] CRAN (R 4.1.3)
#> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.4)
#> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.2)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.4)
#> progressr 0.10.0 2021-12-19 [2] CRAN (R 4.1.2)
#> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.4)
#> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1)
#> Rcpp 1.0.8.2 2022-03-11 [2] CRAN (R 4.1.2)
#> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1)
#> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.2)
#> rmarkdown 2.13 2022-03-10 [2] CRAN (R 4.1.2)
#> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.4)
#> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.4)
#> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.2)
#> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.2)
#> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.4)
#> tibble 3.1.6 2021-11-07 [2] CRAN (R 4.1.2)
#> tidyr 1.2.0 2022-02-01 [2] CRAN (R 4.1.2)
#> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.2)
#> tsibble * 1.1.1 2021-12-03 [2] CRAN (R 4.1.2)
#> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1)
#> vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.1.1)
#> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.2)
#> xfun 0.30 2022-03-02 [2] CRAN (R 4.1.2)
#> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.2)
#>
#> [1] /home/edoardo/R/x86_64-pc-linux-gnu-library/4.1
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ────────────────────────────────────────────────────────────────────────────── |
First, this has nothing to do with the hts package. You are using the forecast reconcilation procedures in the fabletools package. Second, your example consists of a single time series (the ACT), so the reconciliation is degenerate. Third, SNAIVE is already reconciled since the forecasts are equal to the last year of data, so the reconciliation is degenerate. That said, we should improve fabletools to prevent the error. @mitchelloharawild To see it working on a small non-degenerate example, try this: library(dplyr , quietly = TRUE)
library(tsibble, quietly = TRUE)
library(fable , quietly = TRUE)
tsibble::tourism %>%
filter(State == 'ACT') %>%
aggregate_key(State / Region, Trips = sum(Trips)) %>%
model(base = fable::SNAIVE(Trips)) %>%
reconcile(mint_cov = min_trace(base, method = "mint_cov")) %>%
forecast(h = 1) |
Is there a way to enforce positive definite?
I also ran earlier into the same problem as #42 so I rounded both the forecasts and the residuals and replaced any 0s with 1s.
The text was updated successfully, but these errors were encountered: