Covariance matrix is not properly set on Datasets
See original GitHub issueGammapy version from at least v0.17 to 1.0rc1
Bug description
The covariance matrix is not properly set on Datasets
when Models
contain more than one model. Only the sub-covariances of individual models are properly set. No positive covariance terms between independent model components are set. Thanks @AtreyeeS for noting this.
Expected behavior Correlations between independent model parameters should be non-zero.
To Reproduce
import numpy as np
from gammapy.datasets import Datasets
from gammapy.modeling import Covariance
ds = Datasets.read("$GAMMAPY_DATA/fermi-3fhl-crab/Fermi-LAT-3FHL_datasets.yaml",
filename_models= "$GAMMAPY_DATA/fermi-3fhl-crab/Fermi-LAT-3FHL_models.yaml")
factor_matrix = np.ones((9,9))
ds.models.covariance = Covariance.from_factor_matrix(
parameters=ds.parameters, matrix=factor_matrix
)
ds.models.covariance.plot_correlation()
yields:
while:
ds[0].models.covariance = Covariance.from_factor_matrix(
parameters=ds[0].models.parameters, matrix=factor_matrix
)
ds[0].models.covariance.plot_correlation()
yields:
But ds.models.covariance.plot_correlation()
still plots the incorrect matrix.
Issue Analytics
- State:
- Created a year ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Covariance Matrix and it's dependence on the dataset size
I compute the covariance matrix, I get some values. I break up the data set into half, N/2, N/2. I compute the covariance...
Read more >Understanding the Covariance Matrix | by Marvin Lanhenke
The concept of covariance provides us with the tools to do so, allowing us to measure the variance between two variables.
Read more >Getting a covariance matrix from a dataset including non ...
This code has never calculated a covariance matrix. cov does not have a na.rm argument. Your code works if you replace cov with...
Read more >Why do I keep getting a zero matrix from TFitResult for some ...
The covariance matrix is astonishingly 0 (each entry is very small in terms of machine precision), since the fit errors are not zero....
Read more >Covariance (12 of 17) Covariance Matrix wth 3 Data Sets and ...
Visit http://ilectureonline.com for more math and science lectures!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This must not be the only issue here. For instance
DatasetModels(models).covariance
will only contain the covariance from the individual models. The non-diagonal terms are already dropped on init.All in all the
DatasetModels.covariance
is just the stacking of its individual models covariance. This cannot be correct. No?And why is the
Datasets.models
property recreating theDatasetModels
on the fly?Fixed by #4152.