Skip to content

Commit

Permalink
fix up indexing of summed_mask in shapesys, staterror (#333)
Browse files Browse the repository at this point in the history
The main difficulty with shapesys/staterror as it affects multiple (non-consecutive) bins is the way we do masking. For situations where we need to figure out whether to enable the mask or not, it was filling in -1 when the parameter index was 0 which is not good. Additionally, tensorflow.gather() is not happy with -1.
  • Loading branch information
kratsg authored Oct 21, 2018
1 parent ea52590 commit 0fdfcc3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 1 addition & 5 deletions pyhf/modifiers/shapesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ def __init__(self,shapesys_mods,pdfconfig,mega_mods):
zero_mask = summed_mask == 0
# then apply the mask
summed_mask[positive_mask] = inds
summed_mask[zero_mask] = -1
# nb: old code above was
# summed_mask[summed_mask > 0] = inds
# summed_mask[summed_mask == 0] = -1
# This code broke when the `inds` included a '0' because it would replace that value with -1.
summed_mask[zero_mask] = 0
access_rows.append(summed_mask.tolist())
self._factor_access_indices = default_backend.tolist(default_backend.stack(access_rows))
self.finalize(pdfconfig)
Expand Down
8 changes: 6 additions & 2 deletions pyhf/modifiers/staterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ def __init__(self,staterr_mods,pdfconfig,mega_mods):
for mask,inds in zip(staterror_mask, self._staterror_indices):
summed_mask = default_backend.sum(mask[:,0,:],axis=0)
assert default_backend.shape(summed_mask[summed_mask > 0]) == default_backend.shape(default_backend.astensor(inds))
summed_mask[summed_mask > 0] = inds
summed_mask[summed_mask == 0] = -1
# make masks of > 0 and == 0
positive_mask = summed_mask > 0
zero_mask = summed_mask == 0
# then apply the mask
summed_mask[positive_mask] = inds
summed_mask[zero_mask] = 0
access_rows.append(summed_mask.tolist())
self._factor_access_indices = default_backend.tolist(default_backend.stack(access_rows))
self.finalize(pdfconfig)
Expand Down

0 comments on commit 0fdfcc3

Please sign in to comment.