-
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
precomputes all modifications at once #269
Conversation
this is passing tests. the decrease in coverage is because this refactoring exposed that the
method is not tested separately (it was only traversed as part of the other tests). so it should
maybe you guys can already have a look. I added some comments inline |
to summarize this PR refactors the
|
pyhf/pdf.py
Outdated
factors += basefactor | ||
|
||
return tensorlib.product(tensorlib.stack(tensorlib.simple_broadcast(*factors)), axis=0) | ||
|
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.
this just implements how the modifications get combined with the nominal data. Up to now we have 2 types of modifications factors, and shifts (deltas)
first we sum all deltas with the nominal and then apply all factors on that sum
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.
I don't follow your explanation here. "factor" is a very vague term. Are factors nominal*delta
and deltas nominal + delta
? In both cases, we still call them delta...
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.
what this does is compute
summands = [delta1,delta2,... nominal]
basefactor = np.sum(summands)
factors = [f1,f2,f3...,basefactor]
np.product(factors)
but in a follow up PR this entire function will be removed and expected_actualdata
will look like this
all_modifications = self._all_modifications(pars)
delta_field = np.zeros(self.cube.shape)
factor_field = np.ones(self.cube.shape)
for cname,smods in all_modifications.items():
for sname,(factors,deltas) in smods.items():
ind = self.hm[cname][sname]['index']
for f in factors:
factor_field[ind] = factor_field[ind] * f
for d in deltas:
delta_field[ind] = delta_field[ind] + d
combined = factor_field * (delta_field + self.cube)
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.
Hrmm, the way the code is currently written is verrrrry opaque to me. It looks like you sum up a bunch of summands, and then multiply those summand results together. Especially because you do factors += basefactor
. Can you do sum and products separately, and return the combination of them rather than doing internal bookkeeping?
cd3d8fe
to
c8bbad2
Compare
rebased |
this is ready for review I think |
the next PR on top of this is then something along the lines of #273 |
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.
It would be great to have all of these comments in the code itself.
pyhf/pdf.py
Outdated
factors += basefactor | ||
|
||
return tensorlib.product(tensorlib.stack(tensorlib.simple_broadcast(*factors)), axis=0) | ||
|
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.
I don't follow your explanation here. "factor" is a very vague term. Are factors nominal*delta
and deltas nominal + delta
? In both cases, we still call them delta...
Reviewing this quickly I think that I agree with everything that @kratsg put down. So if those requests get resolved then I think this looks great. I'll review this again in more depth, but thanks very much for taking time to put in review comments in advance @lukasheinrich — they were quite nice. |
@kratsg PTAL |
920459f
to
d7aa4d5
Compare
rebased |
d7aa4d5
to
695555c
Compare
Description
This PR refactors the pdf to compute all modifications needed in one go. This should be possible independent of #231 #251 but help with the overall refactoring by collecting all necessary computations in a single function that can then be optimized
Checklist Before Requesting Approver