-
Notifications
You must be signed in to change notification settings - Fork 85
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
feat: Configurable constraints per-modifier #1829
base: main
Are you sure you want to change the base?
Conversation
For debugging purposes, here are likelihood scans: import numpy as np
import pyhf
import matplotlib as mpl
import matplotlib.pyplot as plt
spec = {
"channels": [
{
"name": "ch",
"samples": [
{
"data": [1000.0],
"modifiers": [
{"data": None, "name": "mu_sig", "type": "normfactor"},
{"data": [150.0], "name": "staterror_ch", "type": "staterror"},
],
"name": "signal",
}
],
}
],
"measurements": [{"config": {"parameters": [], "poi": "mu_sig"}, "name": "meas"}],
"observations": [{"data": [1000], "name": "ch"}],
"version": "1.0.0",
}
model_gaussian = pyhf.Workspace(spec).model()
print(pyhf.Workspace(spec).data(model_gaussian))
spec["channels"][0]["samples"][0]["modifiers"][1].update({"constraint": "poisson"})
model_poisson = pyhf.Workspace(spec).model()
print(pyhf.Workspace(spec).data(model_poisson))
spec["channels"][0]["samples"][0]["modifiers"][1] = {
"data": [150.0],
"name": "shapesys",
"type": "shapesys",
}
model_shapesys = pyhf.Workspace(spec).model()
print(pyhf.Workspace(spec).data(model_shapesys))
par_range = np.linspace(0.1, 1.9, 19)
ll_gaussian = []
ll_poisson = []
ll_shapesys = []
for par in par_range:
auxdata_stat = pyhf.tensorlib.astensor([1.0])
auxdata_shape = pyhf.tensorlib.astensor([(1000 / 150) ** 2])
parameters = pyhf.tensorlib.astensor([1.0, par])
ll_gaussian.append(model_gaussian.constraint_logpdf(auxdata_stat, parameters))
ll_poisson.append(model_poisson.constraint_logpdf(auxdata_stat, parameters))
ll_shapesys.append(model_shapesys.constraint_logpdf(auxdata_shape, parameters))
mpl.style.use("fivethirtyeight")
plt.plot(par_range, ll_gaussian, label="staterror (Gaussian)")
plt.plot(par_range, ll_poisson, label="staterror (Poisson)")
plt.plot(par_range, ll_shapesys, label="shapesys (Poisson)")
plt.legend()
plt.xlabel("parameter value")
plt.ylabel("log likelihood")
plt.tight_layout()
plt.savefig("scan.pdf") I am unsure about what the auxdata for |
The maximum for the Poisson |
Looking what actually goes into the final Poisson call in the backend: for a |
0f1aa22
to
fad6b76
Compare
Description
I only added functionality for staterror right now, but this lets you define a modifier with a
constraint
parameter like sowhich should get picked up correctly. Should also allow for an unconstrained option in the future too (to turn off the constraint).
#760 is kinda related.
Checklist Before Requesting Reviewer
Before Merging
For the PR Assignees: