-
Notifications
You must be signed in to change notification settings - Fork 51
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
Take into account covariance matrix for daemonflux parameters #766
Changes from 5 commits
a612062
ef2c0e5
c3d7750
3803a82
defc16e
e95ae41
098d603
9abeaf0
b8ec5fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -862,6 +862,33 @@ def __init__(self, *args): | |
# I think because the changed units are cached in the object (Philipp) | ||
self.normalize_values = True | ||
|
||
# store list of daemonflux params names for prior penalty calculation | ||
self._daemon_names = ['K_158G', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure future compatibility it would be good read the daemonflux parameter names from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to replace the names use simple string ops: self._daemon_names = [
p.replace("pi+","pi").replace("pi-","antipi").replace(
"K+","K").replace("K-","antiK")
for p in Flux().params.known_parameters
]``` There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to limit I didn't think about renaming the parameters automatically, that's a good suggestion, thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe another solution which avoids storing the parameter list altogether is to just add a prefix to all daemonflux parameters names, since we have to rename them anyway to remove symbols, then I can just look for that prefix as a condition to skip these parameters... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe I should just do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, not having a hard coded list in param.py would be better |
||
'K_2P', | ||
'K_31G', | ||
'antiK_158G', | ||
'antiK_2P', | ||
'antiK_31G', | ||
'n_158G', | ||
'n_2P', | ||
'p_158G', | ||
'p_2P', | ||
'pi_158G', | ||
'pi_20T', | ||
'pi_2P', | ||
'pi_31G', | ||
'antipi_158G', | ||
'antipi_20T', | ||
'antipi_2P', | ||
'antipi_31G', | ||
'GSF_1', | ||
'GSF_2', | ||
'GSF_3', | ||
'GSF_4', | ||
'GSF_5', | ||
'GSF_6', | ||
] | ||
|
||
@property | ||
def has_derived(self)->bool: | ||
""" | ||
|
@@ -1380,8 +1407,22 @@ def priors_penalty(self, metric): | |
penalty : float sum of all parameters' prior values | ||
|
||
""" | ||
return np.sum([obj.prior_penalty(metric=metric) | ||
for obj in self._params]) | ||
|
||
# if daemonflux stage is not used use std priors penalty | ||
if not "daemon_chi2" in self.names: | ||
priors_sum = np.sum([obj.prior_penalty(metric=metric) | ||
for obj in self._params]) | ||
|
||
# else switch daemon flux params penalty to the one drom daemonflux | ||
# (which takes into account covariance) | ||
else: | ||
# normal (non-correlated) penalty for non-daemonflux params | ||
priors_sum = np.sum([obj.prior_penalty(metric=metric) | ||
for obj in self._params if obj.name not in self._daemon_names]) | ||
# add daemonflux calcualted chi2 penalty | ||
priors_sum += self._by_name["daemon_chi2"].value.m_as("dimensionless") | ||
|
||
return priors_sum | ||
|
||
def priors_penalties(self, metric): | ||
"""Return the prior penalties for each param at their current values. | ||
|
marialiubarska marked this conversation as resolved.
Show resolved
Hide resolved
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this branch, I tried to calculate the pull penalty, and it seems to give a number as expected. However, I have the following observations/concerns:
There are two other functions also
params.priors_chi2
andparams.priors_llh
. I believe their output are supposed be in agreement withparams.priors_penalty(metric='mod_chi2')
. However, those two still give the priors without incorporating the covariance matrix of daemonflux.params.priors_penalty(metric='llh')
gives output same asparams.priors_penalty(metric='mod_chi2')
for modification to daemonflux parameters. If I modify other parameters, let's saydom_eff
thenparams.priors_penalty(metric='llh')
give me a value which is half ofparams.priors_penalty(metric='mod_chi2')
as expected. I think this can cause an issue if someone performs minimization usingllh
as the metric. Therefore, we need introduce a factor of 1/2 if the metric isllh
.If I modify the values of the daemonflux parameters in params then
params.priors_chi2
andparams.priors_llh
give me updated priors immediately. Butparams.priors_penalty(metric='llh')
gives me an updated value only after I runtemplate_maker.get_outputs(return_sum=True)
. Otherwise old value is given. If someone loads a fittedparamset
and tries to calculate theparams.priors_penalty
without generating a template usingget_outputs
then the contribution from daemonflux parameter via covariance matrix will be missing but other parameters will still give a contribution to the prior penalty. This can cause confusion and go unnoticed leading to a wrong prior penalty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JanWeldert Calculation is ok when the metric is chi2 but these inconsistencies mentioned in the previous message can cause confusion and issues. More specifically, if some try to use LLH, then they can get the wrong numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, these are good points.
params.priors_chi2
andparams.priors_llh
in the same way asparams.priors_penalty
, but we could also think about removing the functions completely since they are just calling the prior penalty function of the Param class anyway.params.priors_penalties
will also ignore the correlation, would be good to exclude the daemon params here too.if metric in LLH_METRICS:
and multiply the chi2 value by 0.5 if so. You can also make sure thatmetric in CHI2_METRICS
otherwise.params.priors_penalty
(as they should be) but currently taken into account byparams.priors_chi2
andparams.priors_llh
because they don't know about the correlation (your first point).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anilak41 Thanks for pointing out the issue with LLH conversion, I added a fix for this