Skip to content

Commit 2ba5ec8

Browse files
authored
feat: Update required_parset to pass in sample data and modifier data (#774)
* Modify required_parset API to allow sample data and modifier data to be passed through
1 parent d0069fb commit 2ba5ec8

File tree

11 files changed

+33
-33
lines changed

11 files changed

+33
-33
lines changed

src/pyhf/cli/spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def inspect(workspace, output_file, measurement):
4343
(
4444
parname,
4545
modifiers.registry[result['modifiers'][parname]]
46-
.required_parset(0)['paramset_type']
46+
.required_parset([], [])['paramset_type']
4747
.__name__,
4848
)
4949
for parname in ws.parameters

src/pyhf/modifiers/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,38 +90,38 @@ def modifier(*args, **kwargs):
9090
# >>> @modifiers.modifier
9191
# >>> ... class myCustomModifier(object):
9292
# >>> ... @classmethod
93-
# >>> ... def required_parset(cls, npars): pass
93+
# >>> ... def required_parset(cls, sample_data, modifier_data): pass
9494
#
9595
# >>> @modifiers.modifier(name='myCustomNamer')
9696
# >>> ... class myCustomModifier(object):
9797
# >>> ... @classmethod
98-
# >>> ... def required_parset(cls, npars): pass
98+
# >>> ... def required_parset(cls, sample_data, modifier_data): pass
9999
#
100100
# >>> @modifiers.modifier(constrained=False)
101101
# >>> ... class myUnconstrainedModifier(object):
102102
# >>> ... @classmethod
103-
# >>> ... def required_parset(cls, npars): pass
103+
# >>> ... def required_parset(cls, sample_data, modifier_data): pass
104104
# >>> ...
105105
# >>> myUnconstrainedModifier.pdf_type
106106
# None
107107
#
108108
# >>> @modifiers.modifier(constrained=True, pdf_type='poisson')
109109
# >>> ... class myConstrainedCustomPoissonModifier(object):
110110
# >>> ... @classmethod
111-
# >>> ... def required_parset(cls, npars): pass
111+
# >>> ... def required_parset(cls, sample_data, modifier_data): pass
112112
# >>> ...
113113
# >>> myConstrainedCustomGaussianModifier.pdf_type
114114
# 'poisson'
115115
#
116116
# >>> @modifiers.modifier(constrained=True)
117117
# >>> ... class myCustomModifier(object):
118118
# >>> ... @classmethod
119-
# >>> ... def required_parset(cls, npars): pass
119+
# >>> ... def required_parset(cls, sample_data, modifier_data): pass
120120
#
121121
# >>> @modifiers.modifier(op_code='multiplication')
122122
# >>> ... class myMultiplierModifier(object):
123123
# >>> ... @classmethod
124-
# >>> ... def required_parset(cls, npars): pass
124+
# >>> ... def required_parset(cls, sample_data, modifier_data): pass
125125
# >>> ...
126126
# >>> myMultiplierModifier.op_code
127127
# 'multiplication'

src/pyhf/modifiers/histosys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@modifier(name='histosys', constrained=True, op_code='addition')
1212
class histosys(object):
1313
@classmethod
14-
def required_parset(cls, n_parameters):
14+
def required_parset(cls, sample_data, modifier_data):
1515
return {
1616
'paramset_type': constrained_by_normal,
1717
'n_parameters': 1,

src/pyhf/modifiers/lumi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@modifier(name='lumi', constrained=True, pdf_type='normal', op_code='multiplication')
1111
class lumi(object):
1212
@classmethod
13-
def required_parset(cls, n_parameters):
13+
def required_parset(cls, sample_data, modifier_data):
1414
return {
1515
'paramset_type': constrained_by_normal,
1616
'n_parameters': 1,

src/pyhf/modifiers/normfactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@modifier(name='normfactor', op_code='multiplication')
1111
class normfactor(object):
1212
@classmethod
13-
def required_parset(cls, n_parameters):
13+
def required_parset(cls, sample_data, modifier_data):
1414
return {
1515
'paramset_type': unconstrained,
1616
'n_parameters': 1,

src/pyhf/modifiers/normsys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@modifier(name='normsys', constrained=True, op_code='multiplication')
1212
class normsys(object):
1313
@classmethod
14-
def required_parset(cls, n_parameters):
14+
def required_parset(cls, sample_data, modifier_data):
1515
return {
1616
'paramset_type': constrained_by_normal,
1717
'n_parameters': 1,

src/pyhf/modifiers/shapefactor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
@modifier(name='shapefactor', op_code='multiplication')
1111
class shapefactor(object):
1212
@classmethod
13-
def required_parset(cls, n_parameters):
13+
def required_parset(cls, sample_data, modifier_data):
1414
return {
1515
'paramset_type': unconstrained,
16-
'n_parameters': n_parameters,
16+
'n_parameters': len(sample_data),
1717
'modifier': cls.__name__,
1818
'is_constrained': cls.is_constrained,
1919
'is_shared': True,
20-
'inits': (1.0,) * n_parameters,
21-
'bounds': ((0.0, 10.0),) * n_parameters,
20+
'inits': (1.0,) * len(sample_data),
21+
'bounds': ((0.0, 10.0),) * len(sample_data),
2222
}
2323

2424

src/pyhf/modifiers/shapesys.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
)
1313
class shapesys(object):
1414
@classmethod
15-
def required_parset(cls, n_parameters):
15+
def required_parset(cls, sample_data, modifier_data):
1616
return {
1717
'paramset_type': constrained_by_poisson,
18-
'n_parameters': n_parameters,
18+
'n_parameters': len(sample_data),
1919
'modifier': cls.__name__,
2020
'is_constrained': cls.is_constrained,
2121
'is_shared': False,
22-
'inits': (1.0,) * n_parameters,
23-
'bounds': ((1e-10, 10.0),) * n_parameters,
22+
'inits': (1.0,) * len(sample_data),
23+
'bounds': ((1e-10, 10.0),) * len(sample_data),
2424
# nb: auxdata/factors set by finalize. Set to non-numeric to crash
2525
# if we fail to set auxdata/factors correctly
26-
'auxdata': (None,) * n_parameters,
27-
'factors': (None,) * n_parameters,
26+
'auxdata': (None,) * len(sample_data),
27+
'factors': (None,) * len(sample_data),
2828
}
2929

3030

src/pyhf/modifiers/staterror.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
@modifier(name='staterror', constrained=True, op_code='multiplication')
1111
class staterror(object):
1212
@classmethod
13-
def required_parset(cls, n_parameters):
13+
def required_parset(cls, sample_data, modifier_data):
1414
return {
1515
'paramset_type': constrained_by_normal,
16-
'n_parameters': n_parameters,
16+
'n_parameters': len(sample_data),
1717
'modifier': cls.__name__,
1818
'is_constrained': cls.is_constrained,
1919
'is_shared': True,
20-
'inits': (1.0,) * n_parameters,
21-
'bounds': ((1e-10, 10.0),) * n_parameters,
22-
'auxdata': (1.0,) * n_parameters,
20+
'inits': (1.0,) * len(sample_data),
21+
'bounds': ((1e-10, 10.0),) * len(sample_data),
22+
'auxdata': (1.0,) * len(sample_data),
2323
}
2424

2525

src/pyhf/pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _paramset_requirements_from_channelspec(spec, channel_nbins):
3939
try:
4040
paramset_requirements = modifiers.registry[
4141
modifier_def['type']
42-
].required_parset(len(sample['data']))
42+
].required_parset(sample['data'], modifier_def['data'])
4343
except KeyError:
4444
log.exception(
4545
'Modifier not implemented yet (processing {0:s}). Available modifiers: {1}'.format(

0 commit comments

Comments
 (0)