11"""
2- MC Dropout inference for NNPDF dropout fits - (fit on central value)
2+ MC Dropout inference for NNPDF dropout fits
33======================================================================
44
55Loads the trained weights of one replica, runs N stochastic forward passes
66with dropout kept active (training=True), and computes the mean PDF over
7- those passes. The result is written as a numpy archive (.npz) containing :
7+ those passes. The result contains :
88
99 - ``x`` : x-grid, shape (n_x,)
1010 - ``mean`` : mean PDF, shape (n_x, 14)
1111 - ``std`` : std PDF, shape (n_x, 14)
1212 - ``samples`` : all N samples, shape (N, n_x, 14)
1313 - ``flavours`` : LHAPDF PID list, shape (14,)
1414
15- Usage (from the project root, inside environment_nnpdf) :
15+ Usage :
1616 python -m n3fit.mc_dropout_inference \\
1717 --fit-dir nnpdf40-like-dropout-cluster \\
1818 --replica 1 \\
2525 nnfit/replica_<N>/weights.weights.h5 - saved Keras weights
2626 filter.yml or n3fit runcard - architecture parameters
2727
28- The architecture is hardcoded from the runcard below and must match the
29- saved weights. If you change the runcard parameters, update the defaults.
28+ Warning: The architecture parameters are read from the n3fit runcard, not from the saved model.
3029"""
3130
3231import argparse
@@ -63,10 +62,7 @@ def _get_xgrid():
6362 from n3fit .io .writer import XGRID # noqa - re-raise if truly missing
6463 return XGRID
6564
66-
67- # ---------------------------------------------------------------------------
68- # ARCHITECTURE DEFAULTS : must match what was used during training
69- # ---------------------------------------------------------------------------
65+ # Loading the architecture parameters from the fit runcard
7066DEFAULT_RUNCARD = (
7167 Path (__file__ ).resolve ().parent .parent .parent # n3fit/src/../.. : n3fit
7268 / "runcards" / "examples" / "nnpdf40-like-dropout-cluster.yml"
@@ -83,13 +79,13 @@ def _load_architecture(runcard_path):
8379 fitbasis = rc ["fitting" ]["fitbasis" ]
8480
8581 return dict (
86- nodes = params ["nodes_per_layer" ], # [25, 20, 8]
87- activations = params ["activation_per_layer" ], # ['tanh','tanh','linear']
88- initializer = params ["initializer" ], # 'glorot_normal'
89- architecture = params ["layer_type" ], # 'dense'
90- dropout_rate = params .get ("dropout" , 0.0 ), # 0.1
82+ nodes = params ["nodes_per_layer" ],
83+ activations = params ["activation_per_layer" ],
84+ initializer = params ["initializer" ],
85+ architecture = params ["layer_type" ],
86+ dropout_rate = params .get ("dropout" , 0.0 ),
9187 flav_info = basis ,
92- fitbasis = fitbasis , # 'EVOL'
88+ fitbasis = fitbasis ,
9389 )
9490
9591
0 commit comments