From 0fdfcc385f2f277e88206c6cff0cf3b6600225e1 Mon Sep 17 00:00:00 2001 From: Giordon Stark Date: Sun, 21 Oct 2018 11:57:15 -0700 Subject: [PATCH] fix up indexing of summed_mask in shapesys, staterror (#333) 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. --- pyhf/modifiers/shapesys.py | 6 +----- pyhf/modifiers/staterror.py | 8 ++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyhf/modifiers/shapesys.py b/pyhf/modifiers/shapesys.py index 1ad62485bf..43e2c9d44b 100644 --- a/pyhf/modifiers/shapesys.py +++ b/pyhf/modifiers/shapesys.py @@ -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) diff --git a/pyhf/modifiers/staterror.py b/pyhf/modifiers/staterror.py index 5c1ba74d0e..8408c0b378 100644 --- a/pyhf/modifiers/staterror.py +++ b/pyhf/modifiers/staterror.py @@ -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)