Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate covariance matrix to the spatial and spectral nodel in SkyM…
…odel
- Loading branch information
Showing
3 changed files
with
12 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,11 +152,19 @@ def __init__(self, spatial_model, spectral_model, name="SkyModel"): | |
@property | ||
def spatial_model(self): | ||
"""`~gammapy.image.models.SkySpatialModel`""" | ||
# propagate sub-covariance | ||
if self.parameters.covariance is not None: | ||
idx = len(self._spatial_model.parameters.parameters) | ||
self._spatial_model.parameters.covariance = self.parameters.covariance[:idx, :idx] | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
adonath
Author
Member
|
||
return self._spatial_model | ||
|
||
@property | ||
def spectral_model(self): | ||
"""`~gammapy.spectrum.models.SpectralModel`""" | ||
# propagate sub-covariance | ||
if self.parameters.covariance is not None: | ||
idx = len(self._spatial_model.parameters.parameters) | ||
self._spectral_model.parameters.covariance = self.parameters.covariance[idx:, idx:] | ||
return self._spectral_model | ||
|
||
@property | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@adonath - I'm not sure if this is a good idea.
It is very uncommon in Python to have a property access change internal state.
I think users will be confused to sometimes have covar set on the spatial and spectral part, depending on whether they accessed that model component directly or from the total sky model.
(and even to have the sub-model state change just becomes somewhere someone did a property access on the total model).
I can see how it is desirable to have this back propagation, but I doubt this is the way to go.