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

MinT needs covariance matrix to be positive definite. #43

Open
brunocarlin opened this issue Nov 7, 2018 · 9 comments
Open

MinT needs covariance matrix to be positive definite. #43

brunocarlin opened this issue Nov 7, 2018 · 9 comments

Comments

@brunocarlin
Copy link

brunocarlin commented Nov 7, 2018

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.

@jnuvenus
Copy link

jnuvenus commented May 6, 2019

@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.

@brunocarlin
Copy link
Author

brunocarlin commented May 6, 2019

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

@yasineahmed
Copy link

Hello,
was anyone able to resolve this issue?
thanks.

@robjhyndman
Copy link
Collaborator

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.

@yasineahmed
Copy link

yasineahmed commented Jul 30, 2019

Ah, works fine now after adding random noise via rnorm()
Thank you for your assistance.

@dclengacher
Copy link

I added noise to both the forecast and residuals and still get this error.

@medoeje
Copy link

medoeje commented Apr 22, 2020

I added noise to both the forecast and residuals and still get this error.

Same here.
When I'm using ets or arima forecasting algorithms it works well (after removing constant columns), but when I use hybridModel I always get the error.

@edoardomichielon
Copy link

Same error here, this time it occurs even if series is not constant, so any of the solution mentioned helps
Thank you for your assistance.

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 info
sessioninfo::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
#> 
#> ──────────────────────────────────────────────────────────────────────────────

@robjhyndman
Copy link
Collaborator

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)

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

7 participants