Skip to content

Commit f915237

Browse files
authored
Merge pull request #2386 from NNPDF/2251-sum-rules-for-hessian-pdfs
2 parents fb8955c + d22231a commit f915237

2 files changed

Lines changed: 21 additions & 14 deletions

File tree

validphys2/src/validphys/sumrules.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,21 @@ def unknown_sum_rules(pdf: PDF, Q: numbers.Real):
206206
return _combine_limits(_sum_rules(UNKNOWN_SUM_RULES, lpdf, Q))
207207

208208

209-
def _simple_description(d):
209+
def _simple_description(data, pdf):
210+
"""Return a table with simple descriptive statistics over the members of the PDF.
211+
The statistics used depend on the type of PDF (MC or Hessian)."""
210212
res = {}
211-
for k, arr in d.items():
212-
res[k] = d = {}
213-
d["mean"] = np.mean(arr)
214-
d["std"] = np.std(arr)
215-
d["min"] = np.min(arr)
216-
d["max"] = np.max(arr)
213+
stats_class = pdf.stats_class
214+
for k, arr in data.items():
215+
res[k] = stats_dict = {}
216+
# Each entry in `data` is expected to be a vector with shape
217+
# (central_member + error_members,), hence we reshape to (-1, 1) before
218+
# passing to the stats class.
219+
stats = stats_class(arr.reshape(-1,1))
220+
stats_dict["mean"] = stats.central_value().item()
221+
stats_dict["std"] = stats.std_error().item()
222+
stats_dict["min"] = np.min(arr)
223+
stats_dict["max"] = np.max(arr)
217224

218225
return pd.DataFrame(res).T
219226

@@ -233,10 +240,10 @@ def _err_mean_table(d, polarized=False):
233240

234241

235242
@table
236-
def sum_rules_table(sum_rules):
243+
def sum_rules_table(sum_rules, pdf):
237244
"""Return a table with the descriptive statistics of the sum rules,
238245
over members of the PDF."""
239-
return _simple_description(sum_rules)
246+
return _simple_description(sum_rules, pdf)
240247

241248

242249
@table

validphys2/src/validphys/tests/regressions/test_sum_rules_hessian.csv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
mean std min max Central value
2-
momentum 1.0000359346945835 3.2490023902345065e-08 1.0000357949386856 1.000036007099919 1.000035943610909
3-
uvalence 1.9997947975241677 3.774745222364767e-05 1.9996255039155293 1.9998795897064394 1.9998052948252174
4-
dvalence 0.9997193904389039 3.913237872100671e-05 0.9995455646219639 0.9998033688013618 0.9997281952294002
5-
svalence 0.00021668009787772745 4.881864767300481e-05 2.8212616664191614e-05 0.00037062725233145966 0.00021200815810076823
6-
cvalence -1.4051604748064229e-05 1.62143392575478e-06 -2.19356537524125e-05 -1.1074824041030964e-05 -1.3850510260556828e-05
2+
momentum 1.000035943610909 2.419447681485291e-07 1.0000357949386858 1.0000360070999197 1.000035943610909
3+
uvalence 1.999805294825203 0.00028135968073985274 1.9996255039155302 1.999879589706442 1.999805294825203
4+
dvalence 0.9997281952293998 0.0002880439907877597 0.9995455646219626 0.9998033688013619 0.9997281952293998
5+
svalence 0.00021200815809931106 0.0003521795410429786 2.821261665280836e-05 0.00037062725233413807 0.00021200815809931106
6+
cvalence -1.385051026082224e-05 1.173309523925793e-05 -2.193565375547429e-05 -1.1074824039685035e-05 -1.385051026082224e-05
77
u momentum fraction 0.2554 0.00025 -1.0 -1.0 -1.0
88
ubar momentum fraction 0.03386 0.0001 -1.0 -1.0 -1.0
99
d momentum fraction 0.1277 0.00029 -1.0 -1.0 -1.0

0 commit comments

Comments
 (0)