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

[BUG] Min Trace method="mint_shrink" #92

Closed
AzulGarza opened this issue Oct 24, 2022 · 1 comment · Fixed by #97
Closed

[BUG] Min Trace method="mint_shrink" #92

AzulGarza opened this issue Oct 24, 2022 · 1 comment · Fixed by #97
Assignees

Comments

@AzulGarza
Copy link
Member

AzulGarza commented Oct 24, 2022

Users have reported issues trying to run MinTrace(method=='mint_shrink').

I suspect that it is related to datasets with time series of distinct lengths (in our examples all time series have the same length and the method works fine). In particular, I think that line 441 below is not working correctly. It should ignore the NAS in the residuals matrix generated by the difference in lengths, but perhaps it is not ignoring them.

residuals = (y_insample - y_hat_insample).T
n, _ = residuals.shape
masked_res = np.ma.array(residuals, mask=np.isnan(residuals))
covm = np.ma.cov(masked_res, rowvar=False, allow_masked=True).data
if method == 'wls_var':
W = np.diag(np.diag(covm))
elif method == 'mint_cov':
W = covm
elif method == 'mint_shrink':
tar = np.diag(np.diag(covm))
corm = cov2corr(covm)
xs = np.divide(residuals, np.sqrt(np.diag(covm)))
xs = xs[~np.isnan(xs).any(axis=1), :]
v = (1 / (n * (n - 1))) * (crossprod(xs ** 2) - (1 / n) * (crossprod(xs) ** 2))
np.fill_diagonal(v, 0)
corapn = cov2corr(tar)
d = (corm - corapn) ** 2
lmd = v.sum() / d.sum()
lmd = max(min(lmd, 1), 0)
W = lmd * tar + (1 - lmd) * covm

From Linear-GitHub Sync

@AzulGarza
Copy link
Member Author

According to the docs, it is the most likely reason since allow_masked=True simply propagates the mask but does not remove the nas.

image

@mergenthaler mergenthaler changed the title [BUG] Min Trace method="mint_shrink" [NIX-21] [BUG] Min Trace method="mint_shrink" Oct 25, 2022
@mergenthaler mergenthaler changed the title [NIX-21] [BUG] Min Trace method="mint_shrink" [BUG] Min Trace method="mint_shrink" Oct 25, 2022
@mergenthaler mergenthaler added bug and removed linear labels Oct 25, 2022
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

Successfully merging a pull request may close this issue.

3 participants