question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Covariance matrix is not properly set on Datasets

See original GitHub issue

Gammapy 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: download-1

while:

ds[0].models.covariance = Covariance.from_factor_matrix(
        parameters=ds[0].models.parameters, matrix=factor_matrix
    )
ds[0].models.covariance.plot_correlation()

yields: download-2

But ds.models.covariance.plot_correlation() still plots the incorrect matrix.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
registerriercommented, Oct 21, 2022

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 the DatasetModels on the fly?

0reactions
adonathcommented, Nov 13, 2022

Fixed by #4152.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found