๐ API Reference¶
Welcome to the full API reference for the NN_fit package. Below youโll find organized documentation for all modules in the codebase, including classes, functions, and docstrings.
๐ง Core Fitting Modules¶
perform_fit_comb.py¶
perform_fit(pred, num_reps, range_alpha, range_beta, range_gamma, lr, wd, patience, x_alphas, fk_tables, binwidths, cov_matrix, extended_loss, activation_function, num_input_layers, num_output_layers, hidden_layers, x_vals, preproc, validation_split, max_epochs, max_chi_sq, lag_mult_pos, lag_mult_int, x_int)
¶
Performs repeated training of neural networks to fit pseudo-data predictions using a physics-constrained loss function and neural PDF parameterization.
Each replica (num_reps) of the prediction is fitted using a randomly initialized
neural network (based on PreprocessedMLP), and the corresponding predictions and losses
are recorded. Optionally uses a validation split.
Parameters¶
pred : list of np.ndarray
List of length num_reps, each containing the pseudo-data event predictions.
num_reps : int
Number of replicas (i.e., independent fits with random initialization).
range_alpha : float
Upper bound for uniform sampling of alpha preprocessing parameter.
range_beta : float
Upper bound for uniform sampling of beta preprocessing parameter.
range_gamma : float
Upper bound for uniform sampling of gamma preprocessing parameter.
lr : float
Learning rate for the Adam optimizer.
wd : float
Weight decay (L2 regularization) for the optimizer.
patience : int
Early stopping patience (currently unused but declared).
x_alphas : torch.Tensor
Input x-values used to evaluate PDF predictions for data loss.
fk_tables : torch.Tensor
FastKernel tables to convert PDFs into observable space.
binwidths : torch.Tensor
Widths of each bin used in rebinning the predictions.
cov_matrix : np.ndarray
Covariance matrix used for weighted loss calculation.
extended_loss : bool
If True, uses extended loss with constraints (e.g., normalization, positivity).
activation_function : str
Activation function used in the neural network (e.g., 'relu', 'tanh').
num_input_layers : int
Number of input layers before hidden layers.
num_output_layers : int
Number of output layers after hidden layers.
hidden_layers : list of int
Number of neurons in each hidden layer.
x_vals : np.ndarray
x-values used to store final fitted PDFs.
preproc : str
Type of preprocessing function (e.g., 'powerlaw', 'exp') applied to PDFs.
validation_split : float
Fraction of data used for validation (between 0 and 1).
max_epochs : int
Maximum number of training epochs.
max_chi_sq : float
Maximum allowed chi-squared for a fit to be accepted.
lag_mult_pos : float
Lagrange multiplier for positivity constraint.
lag_mult_int : float
Lagrange multiplier for integral constraint.
x_int : np.ndarray
x-values used for computing integral constraints.
Returns¶
chi_squares : list of float Training loss (chi-squared) values saved periodically during training. N_event_pred : list of np.ndarray Predicted event yields after applying the FastKernel convolution. neutrino_pdfs : list of np.ndarray Final predicted PDFs (postprocessed) from successful fits. model : PreprocessedMLP Final trained model (from last accepted fit). chi_square_for_postfit : list of float Final chi-squared values for each accepted fit (for post-fit evaluation). train_indices : np.ndarray Indices used for training set in the last run (if validation was used). val_indices : np.ndarray Indices used for validation set in the last run (if validation was used). training_length : int Number of training steps run in the final (last) model.
Notes¶
- Only models with
loss < max_chi_sqare retained in the final output. - The PDFs are preprocessed using a parameterized function with random ฮฑ, ฮฒ, ฮณ values.
- Assumes the model class
PreprocessedMLPand loss classCustomLossare defined externally. - Model and predictions use PyTorch; inputs must be tensors where appropriate.
- Currently no explicit early stopping logic is implemented (but patience is reserved).
Source code in NN_fit/perform_fit_comb.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
perform_fit_nu_nub.py¶
perform_fit(pred, num_reps, range_alpha, range_beta, range_gamma, lr, wd, patience, x_alphas, fk_tables_mu, fk_tables_mub, binwidths_mu, binwidths_mub, cov_matrix, extended_loss, activation_function, num_input_layers, num_output_layers, hidden_layers, x_vals, preproc, validation_split, max_epochs, max_chi_sq, fit_faser_data, lag_mult_pos, lag_mult_int, x_int)
¶
Performs repeated training of neural networks to fit pseudo-data predictions using a physics-constrained loss function and neural PDF parameterization.
Each replica (num_reps) of the prediction is fitted using a randomly initialized
neural network (based on PreprocessedMLP), and the corresponding predictions and losses
are recorded. Optionally uses a validation split.
Parameters¶
pred : list of np.ndarray
List of length num_reps, each containing the pseudo-data event predictions.
num_reps : int
Number of replicas (i.e., independent fits with random initialization).
range_alpha : float
Upper bound for uniform sampling of alpha preprocessing parameter.
range_beta : float
Upper bound for uniform sampling of beta preprocessing parameter.
range_gamma : float
Upper bound for uniform sampling of gamma preprocessing parameter.
lr : float
Learning rate for the Adam optimizer.
wd : float
Weight decay (L2 regularization) for the optimizer.
patience : int
Early stopping patience (currently unused but declared).
x_alphas : torch.Tensor
Input x-values used to evaluate PDF predictions for data loss.
fk_tables : torch.Tensor
FastKernel tables to convert PDFs into observable space.
binwidths : torch.Tensor
Widths of each bin used in rebinning the predictions.
cov_matrix : np.ndarray
Covariance matrix used for weighted loss calculation.
extended_loss : bool
If True, uses extended loss with constraints (e.g., normalization, positivity).
activation_function : str
Activation function used in the neural network (e.g., 'relu', 'tanh').
num_input_layers : int
Number of input layers before hidden layers.
num_output_layers : int
Number of output layers after hidden layers.
hidden_layers : list of int
Number of neurons in each hidden layer.
x_vals : np.ndarray
x-values used to store final fitted PDFs.
preproc : str
Type of preprocessing function (e.g., 'powerlaw', 'exp') applied to PDFs.
validation_split : float
Fraction of data used for validation (between 0 and 1).
max_epochs : int
Maximum number of training epochs.
max_chi_sq : float
Maximum allowed chi-squared for a fit to be accepted.
lag_mult_pos : float
Lagrange multiplier for positivity constraint.
lag_mult_int : float
Lagrange multiplier for integral constraint.
x_int : np.ndarray
x-values used for computing integral constraints.
Returns¶
chi_squares : list of float Training loss (chi-squared) values saved periodically during training. N_event_pred : list of np.ndarray Predicted event yields after applying the FastKernel convolution. neutrino_pdfs : list of np.ndarray Final predicted PDFs (postprocessed) from successful fits. model : PreprocessedMLP Final trained model (from last accepted fit). chi_square_for_postfit : list of float Final chi-squared values for each accepted fit (for post-fit evaluation). train_indices : np.ndarray Indices used for training set in the last run (if validation was used). val_indices : np.ndarray Indices used for validation set in the last run (if validation was used). training_length : int Number of training steps run in the final (last) model.
Notes¶
- Only models with
loss < max_chi_sqare retained in the final output. - The PDFs are preprocessed using a parameterized function with random ฮฑ, ฮฒ, ฮณ values.
- Assumes the model class
PreprocessedMLPand loss classCustomLossare defined externally. - Model and predictions use PyTorch; inputs must be tensors where appropriate.
- Currently no explicit early stopping logic is implemented (but patience is reserved).
Source code in NN_fit/perform_fit_nu_nub.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
execute_fit.py¶
execute_postfit.py¶
postfit_execution(postfit_criteria, validation_split, data, cov_matrix, num_output_layers, chi_square_for_postfit, neutrino_pdfs_mu, neutrino_pdfs_mub, neutrino_pdfs, postfit_measures, train_indices, val_indices, level1, N_event_pred, pred, dir_for_data, filename_postfit, diff_lev_1, fit_level, x_alphas, pdf, pdf_set, particle_id_nu, particle_id_nub, lr, wd, max_epochs, patience, chi_squares, neutrino_pdf_fit_name_lhapdf, x_vals, produce_plot, training_lengths, stat_error, sys_error, low_bin, high_bin, N_event_pred_nu, N_event_pred_nub, low_bin_mu, high_bin_mu, low_bin_mub, high_bin_mub, val_losses, lhapdf_path)
¶
Execute post-fit processing after a PDF (Parton Distribution Function) neural fit.
This function performs various operations following a neural network-based PDF fit: - Applies post-fit criteria to PDFs and predictions. - Calculates post-fit measures (e.g., delta chi-squared, phi, bias-to-variance). - Logs results and configuration to file. - Writes PDF replicas and uncertainties to LHAPDF-compatible grid files. - Optionally generates plots of the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postfit_criteria
|
bool
|
Whether to apply post-fit criteria to the predictions and PDFs. |
required |
validation_split
|
float
|
Fraction of data used for validation. If 0, no validation is used. |
required |
data
|
ndarray
|
Measured experimental data. |
required |
cov_matrix
|
ndarray
|
Covariance matrix of the data. |
required |
num_output_layers
|
int
|
Number of neural network outputs (1 for single PDF, 2 for neutrino/antineutrino PDFs). |
required |
chi_square_for_postfit
|
ndarray
|
Chi-square values for the post-fit predictions. |
required |
neutrino_pdfs_mu
|
ndarray
|
Neutrino PDFs for muon neutrino (only if |
required |
neutrino_pdfs_mub
|
ndarray
|
Neutrino PDFs for anti-muon neutrino (only if |
required |
neutrino_pdfs
|
ndarray
|
Neutrino PDFs for the single-output model. |
required |
postfit_measures
|
bool
|
Whether to compute post-fit performance metrics. |
required |
train_indices
|
ndarray
|
Training sample indices. |
required |
val_indices
|
ndarray
|
Validation sample indices. |
required |
level1
|
ndarray
|
Level-1 shifts or corrections. |
required |
N_event_pred
|
ndarray
|
Predicted number of events from the model. |
required |
pred
|
ndarray
|
Model predictions. |
required |
dir_for_data
|
str
|
Directory to save results and intermediate files. |
required |
filename_postfit
|
str
|
Name of the post-fit report file. |
required |
diff_lev_1
|
str / int
|
Identifier for the level-1 difference, used in LHAPDF naming. |
required |
fit_level
|
int
|
Level of fit used; affects which postfit measures are computed. |
required |
x_alphas
|
Tensor
|
Neural network output alphas (PDF coefficients). |
required |
pdf
|
object
|
Reference PDF used during fitting. |
required |
pdf_set
|
str
|
Name of the PDF set used as baseline. |
required |
particle_id_nu
|
int
|
PDG ID for the neutrino used. |
required |
particle_id_nub
|
int
|
PDG ID for the anti-neutrino used. |
required |
lr
|
float
|
Learning rate used in the training. |
required |
wd
|
float
|
Weight decay used during training. |
required |
max_epochs
|
int
|
Maximum number of training epochs. |
required |
patience
|
int
|
Early stopping patience. |
required |
chi_squares
|
ndarray
|
Chi-square values for the fit. |
required |
neutrino_pdf_fit_name_lhapdf
|
str
|
Name to use for the LHAPDF set. |
required |
x_vals
|
ndarray
|
X-values (momentum fraction) for PDF grids. |
required |
produce_plot
|
bool
|
Whether to produce summary plots of fit results. |
required |
training_lengths
|
ndarray
|
Number of epochs run for each replica. |
required |
stat_error
|
ndarray
|
Statistical error on the data. |
required |
sys_error
|
ndarray
|
Systematic error on the data. |
required |
low_bin
|
int
|
Lower bound for binning (single PDF). |
required |
high_bin
|
int
|
Upper bound for binning (single PDF). |
required |
N_event_pred_nu
|
ndarray
|
Event predictions for muon neutrino (two-output case). |
required |
N_event_pred_nub
|
ndarray
|
Event predictions for anti-muon neutrino (two-output case). |
required |
low_bin_mu
|
int
|
Lower bin index for muon neutrino. |
required |
high_bin_mu
|
int
|
Upper bin index for muon neutrino. |
required |
low_bin_mub
|
int
|
Lower bin index for anti-muon neutrino. |
required |
high_bin_mub
|
int
|
Upper bin index for anti-muon neutrino. |
required |
lhapdf_path
|
str
|
Path to LHAPDF neutrino PDFs |
required |
Outputs
- Writes various
.txtfiles with statistical and fit information. - Creates LHAPDF-compatible grid files with the fitted PDFs.
- Optionally generates plots summarizing the fit quality and predictions.
Notes
- Assumes presence of
Postfit,Measures, and LHAPDF writing utilities. - Assumes external plotting utilities (
plot_comb_pdf_cl,plot_nu_nub_cl) are available. - Handles both single-output (combined neutrino) and two-output (neutrino/antineutrino) models.
Source code in NN_fit/execute_postfit.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
๐ฏ Hyperparameter optimization¶
perform_hyperopt.py¶
hyperopt_comb.py¶
perform_fit(pred, range_alpha, range_beta, range_gamma, lr, wd, patience, x_alphas, fk_tables, binwidths, cov_matrix, extended_loss, activation_function, num_input_layers, num_output_layers, hidden_layers, x_vals, preproc, max_epochs, lag_mult_pos, lag_mult_int, x_int, num_folds)
¶
Trains a neural network model to fit pseudo-data for electron neutrino event predictions using K-fold cross-validation and physics-informed constraints.
This function fits a parameterized neural network (PreprocessedMLP) using a custom loss function that incorporates statistical and physical constraints such as positivity and normalization. K-fold cross-validation is used to evaluate the model's generalization performance across different data splits. Random initialization of the preprocessing parameters (alpha, beta, gamma) enables exploration of a hyperparameter space.
Parameters¶
pred : List[np.ndarray] List containing prediction arrays (pseudo-data) for electron neutrino event counts. range_alpha : float Maximum value for randomly sampling the alpha preprocessing parameter. range_beta : float Maximum value for randomly sampling the beta preprocessing parameter. range_gamma : float Maximum value for randomly sampling the gamma preprocessing parameter. lr : float Learning rate for the Adam optimizer. wd : float Weight decay (L2 regularization) used during optimization. patience : int Early stopping patience threshold (number of epochs without improvement before stopping). x_alphas : torch.Tensor Input tensor used to evaluate the model's predicted PDFs. fk_tables : torch.Tensor Forward-folding kernel that maps PDF space to observable event space. binwidths : torch.Tensor Bin widths used to scale the convolved predictions. cov_matrix : np.ndarray Covariance matrix of the pseudo-data, used for uncertainty-aware loss computation. extended_loss : bool Whether to include extended physics constraints (e.g., positivity, integrals) in the loss. activation_function : str Name of the activation function to be used in the MLP (e.g., 'relu', 'tanh'). num_input_layers : int Number of input neurons to the network (typically 1 for univariate PDFs). num_output_layers : int Number of output neurons (typically 1 for electron neutrinos). hidden_layers : List[int] List of hidden layer sizes (e.g., [50, 50] for a 2-layer MLP with 50 neurons each). x_vals : np.ndarray Input values over which the final PDF predictions will be evaluated. preproc : str Type of preprocessing function used on the PDFs (e.g., 'log', 'powerlaw'). max_epochs : int Maximum number of training epochs per fold. lag_mult_pos : float Lagrange multiplier for the positivity constraint in the loss. lag_mult_int : float Lagrange multiplier for the integral (normalization) constraint in the loss. x_int : np.ndarray Input values used for evaluating the integral constraints on the PDF.
Returns¶
chi_squares : List[float] History of chi-squared values during training (saved periodically). N_event_pred : List[np.ndarray] Placeholder for predicted event counts (not currently populated in this version). neutrino_pdfs : List[np.ndarray] Placeholder for final PDF outputs (not currently populated in this version). model : PreprocessedMLP Trained neural network model from the final fold. chi_square_for_postfit : List[float] Final loss value (chi-squared) for each fold. train_indices : np.ndarray Indices of the training samples used in the final fold. val_indices : np.ndarray Indices of the validation samples used in the final fold. training_length : int Number of epochs completed during the final fold training. num_folds: int number of k-folds
Notes¶
- The function uses 3-fold cross-validation to evaluate generalization.
- Preprocessing parameters (alpha, beta, gamma) are randomized for each fold.
- This implementation supports only one prediction channel and assumes symmetric treatment of integrals and positivity constraints.
N_event_predandneutrino_pdfsare currently not returned meaningfully.
Source code in NN_fit/hyperopt_comb.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
hyperopt_nu_nub.py¶
perform_fit(pred, range_alpha, range_beta, range_gamma, lr, wd, patience, x_alphas, fk_tables_mu, fk_tables_mub, binwidths_mu, binwidths_mub, cov_matrix, extended_loss, activation_function, num_input_layers, num_output_layers, hidden_layers, x_vals, preproc, max_epochs, lag_mult_pos, lag_mult_int, x_int, num_folds)
¶
Performs k-fold cross-validation training and evaluation of a neural network for muon neutrino flux prediction using Bayesian-inspired randomized hyperparameters.
This function trains a PreprocessedMLP model to predict neutrino and antineutrino
event distributions, optimizing a custom loss function that incorporates physical
constraints and covariance information. It performs training with early stopping
based on validation loss, and evaluates generalization via a held-out fold.
Parameters:¶
pred : List[np.ndarray] List containing ground truth predicted neutrino events for training and evaluation. range_alpha : float Upper bound for random initialization of the alpha hyperparameter. range_beta : float Upper bound for random initialization of the beta hyperparameter. range_gamma : float Upper bound for random initialization of the gamma hyperparameter. lr : float Learning rate for the optimizer. wd : float Weight decay (L2 regularization) for the optimizer. patience : int Number of epochs to wait without validation improvement before early stopping. x_alphas : torch.Tensor Input tensor used for prediction by the model. fk_tables_mu : torch.Tensor Forward-folding kernel table for muon neutrinos. fk_tables_mub : torch.Tensor Forward-folding kernel table for anti-muon neutrinos. binwidths_mu : torch.Tensor Bin widths used for muon neutrino predictions. binwidths_mub : torch.Tensor Bin widths used for anti-muon neutrino predictions. cov_matrix : np.ndarray Covariance matrix for uncertainty propagation in loss computation. extended_loss : bool Whether to include extended regularization terms in the custom loss. activation_function : str Activation function to use in the model (e.g., "relu", "tanh"). num_input_layers : int Number of input features/layers for the model. num_output_layers : int Number of outputs (e.g., neutrino types). hidden_layers : List[int] Sizes of hidden layers in the MLP. x_vals : np.ndarray Input data values used for training and evaluation. preproc : str Type of input preprocessing to apply (e.g., "standard", "log"). max_epochs : int Maximum number of training epochs per fold. lag_mult_pos : float Lagrange multiplier weight for positivity constraint in the loss. lag_mult_int : float Lagrange multiplier weight for integral constraint in the loss. x_int : np.ndarray Points at which the integrals for regularization are evaluated. num_folds: int Number of k-folds
Returns:¶
Tuple[ List[float], # chi_squares over training List[np.ndarray], # Predicted neutrino event counts List[np.ndarray], # Predicted neutrino PDFs PreprocessedMLP, # Trained model instance List[float], # Chi-square values for post-fit analysis np.ndarray, # Training indices from final fold np.ndarray, # Validation indices from final fold int # Total number of training iterations in last fold ]
Source code in NN_fit/hyperopt_nu_nub.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
๐ง Model Architecture¶
structure_NN.py¶
CustomLoss
¶
Bases: Module
Custom loss function wrapper supporting multiple modes: raw chi-squared, or extended with constraints.
Parameters¶
extended_loss : bool If True, uses extended loss with positivity and normalization constraints. num_output_layers : int Determines loss mode: 1 for combined ฮฝ+ฮฝฬ, 2 for separate ฮฝ and ฮฝฬ losses.
Methods¶
forward(pred, data, cov_matrix, small_x_point1, small_x_point2, model, x_int, lag_mult_pos, lag_mult_int) Computes the loss.
Source code in NN_fit/structure_NN.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
forward(pred, data, cov_matrix, small_x_point1, small_x_point2, model, x_int, lag_mult_pos, lag_mult_int)
¶
Computes the loss function.
Parameters¶
pred : torch.Tensor Model prediction. data : torch.Tensor Target data (pseudo-data). cov_matrix : np.ndarray or torch.Tensor Covariance matrix for data. small_x_point1 : torch.Tensor Neural prediction before preprocessing (ฮฝ or combined). small_x_point2 : torch.Tensor Neural prediction before preprocessing (ฮฝฬ, if using two outputs). model : torch.nn.Module Reference to the model (used for constraints). x_int : torch.Tensor x-points for integral constraint. lag_mult_pos : float Lagrange multiplier for positivity. lag_mult_int : float Lagrange multiplier for integral constraint.
Returns¶
torch.Tensor Final loss scalar.
Source code in NN_fit/structure_NN.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
CustomPreprocessing
¶
Bases: Module
Applies a parameterized functional preprocessing to the input based on power-law forms.
The form is
f(x) = ฮณ * (1 - x)^ฮฒ * x^(1 - ฮฑ)
Parameters¶
alpha : float Initial value for ฮฑ parameter. beta : float Initial value for ฮฒ parameter. gamma : float Initial value for ฮณ parameter. preproc : bool If True, alpha, beta, and gamma are learnable parameters. Otherwise, they are fixed.
Notes¶
- Input values are clamped between [1e-6, 1 - 1e-6] for numerical stability.
Source code in NN_fit/structure_NN.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
forward(x)
¶
Applies the preprocessing function.
Parameters¶
x : torch.Tensor Input tensor of shape (N, 1).
Returns¶
torch.Tensor Preprocessed output of same shape.
Source code in NN_fit/structure_NN.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
PreprocessedMLP
¶
Bases: Module
A neural network combining a preprocessing layer with an MLP.
Parameters¶
alpha, beta, gamma : float Parameters for the preprocessing function. activation_function : list of str Activation functions for the MLP. hidden_layers : list of int Sizes of hidden layers. num_input_layers : int Number of input features. num_output_layers : int Number of output features. preproc : bool Whether to use preprocessing.
Attributes¶
preprocessing : CustomPreprocessing The preprocessing module applied before the MLP. mlp : SimplePerceptron The neural network model applied to the preprocessed inputs.
Methods¶
forward(x) Applies preprocessing (if enabled) followed by the MLP. neuralnet(x) Returns raw MLP output (no preprocessing). preproces(x) Returns the preprocessing factor only.
Source code in NN_fit/structure_NN.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
forward(x)
¶
Full forward pass through preprocessing and MLP.
Parameters¶
x : torch.Tensor Input tensor.
Returns¶
torch.Tensor Output of the combined preprocessing and MLP.
Source code in NN_fit/structure_NN.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
neuralnet(x)
¶
Forward pass through only the MLP (no preprocessing).
Parameters¶
x : torch.Tensor
Returns¶
torch.Tensor
Source code in NN_fit/structure_NN.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
preproces(x)
¶
Returns the preprocessing term ฮณ * (1 - x)^ฮฒ * x^(1 - ฮฑ)
Parameters¶
x : torch.Tensor
Returns¶
torch.Tensor
Source code in NN_fit/structure_NN.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
SimplePerceptron
¶
Bases: Module
A feedforward multilayer perceptron (MLP) with configurable activation functions and layer sizes.
Parameters¶
act_functions : list of str List of activation function names (e.g., ['relu', 'relu', 'softplus']) for each layer. num_input_layers : int Number of input features. hidden_layers : list of int List of integers specifying the number of units in each hidden layer. num_output_layers : int Number of output features.
Attributes¶
layers : nn.Sequential Composed list of linear and activation layers forming the MLP.
Notes¶
- Supported activation functions: 'relu', 'softplus'.
- The last activation is applied after the final output layer.
Source code in NN_fit/structure_NN.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
forward(x)
¶
Forward pass through the MLP.
Parameters¶
x : torch.Tensor Input tensor of shape (batch_size, num_input_layers)
Returns¶
torch.Tensor Output tensor of shape (batch_size, num_output_layers)
Source code in NN_fit/structure_NN.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
๐ Plotting and Visualization¶
plot_comb_pdf_cl.py¶
plot_diff_level1_comb.py¶
plot_for_diff_level_1_shifts_nu_nub.py¶
plot_nu_nub_cl.py¶
๐ฆ PDF Output¶
write_all_pdfs_to_lhapdf.py¶
customize_info_file(template_path, output_path, set_index, flavor, num_members)
¶
Creates a customized LHAPDF .info file from a template by replacing placeholders.
Parameters:¶
template_path : str
Path to the .info template file containing placeholders (e.g., SETINDEX, FLAVOR).
output_path : str
Path to the output .info file to be generated.
set_index : int
Unique identifier for the PDF set (used to replace "SETINDEX" in the template).
flavor : str
Flavor content to be listed in the info file (used to replace "FLAVOR").
Can be a single PDG ID (e.g., "12") or a comma-separated list (e.g., "14, -14").
num_members : int
Number of PDF members or replicas (used to replace the "NumMembers" field).
Notes:¶
- The function assumes the template has default "NumMembers: 1000" and replaces that value.
- All replaced content is written to the specified output path.
Source code in NN_fit/write_all_pdfs_to_lhapdf.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
write_lhapdf_grid(xgrid, pdf_dict, path)
¶
Writes a set of neutrino PDFs to a file in LHAPDF grid format (lhagrid1).
This function formats and saves PDF data into a file readable by LHAPDF tools, using the specified x-grid and dictionary of parton distribution functions.
Parameters:¶
xgrid : array-like
Array of Bjorken-x values at which PDFs are evaluated.
pdf_dict : dict
Dictionary mapping particle IDs (PDG codes) to arrays of PDF values.
Each value should be an array of length equal to the length of xgrid.
path : str
Path to the output .dat file where the grid will be written.
Notes:¶
- The output format follows LHAPDF's
lhagrid1specification. - Each PDF line is duplicated, as required by the LHAPDF grid format.
- The order of flavors is sorted by PDG code.
Source code in NN_fit/write_all_pdfs_to_lhapdf.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
๐งช Data and Reading¶
MC_data_reps.py¶
generate_MC_replicas(REPLICAS, data, sig_sys, sig_stat, seed, fit_level)
¶
Generate level 2 data MC replicas for the NN fit by adding a level 1 and then a level 2 gaussian noise to the data
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple[List[Tensor], List[Tensor], List[Tensor]]
|
level 0,1 and 2 data |
Source code in NN_fit/MC_data_reps.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
read_faserv_pdf.py¶
read_pdf(pdf, x_vals, particle, set)
¶
Reads the parton distribution function (PDF) values for a given particle at specified momentum fractions and energy scale using LHAPDF.
Parameters¶
pdf : str Name of the PDF set to load. x_vals : np.ndarray Array of momentum fraction values (x) at which to evaluate the PDF. particle : int Particle ID (PDG code) for which the PDF is evaluated. set : int Specific member or set number within the PDF.
Returns¶
Tuple[np.ndarray, np.ndarray] A tuple containing: - pdf_vals: np.ndarray of PDF values normalized by x_vals. - x_vals: The input array of momentum fractions.
Source code in NN_fit/read_faserv_pdf.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
read_fk_table.py¶
get_fk_table(filename, parent_dir)
¶
Loads a FastKernel (FK) table and corresponding x_alpha nodes from text files, converts them to PyTorch tensors, and reshapes x_alpha to a column vector.
Parameters¶
filename : str Name of the FK table file to load (relative to parent_dir). parent_dir : str Path to the directory containing the FK table file and relative location of the x_alpha file.
Returns¶
Tuple[torch.Tensor, torch.Tensor] - x_alpha: Tensor of shape (N, 1) containing x_alpha grid nodes. - fk_table: Tensor containing the FK table data.
Source code in NN_fit/read_fk_table.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
help_read_files.py¶
๐ Post-Fit Analysis¶
postfit_criteria.py¶
Postfit
¶
Source code in NN_fit/postfit_criteria.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
apply_postfit_criteria(chi_squares, N_event_pred, neutrino_pdfs, pred)
¶
Applies post-fit criteria to filter out replicas with chi-squared values that deviate significantly from the mean (more than 4 standard deviations).
Parameters¶
chi_squares : List[float] List of chi-squared values for each replica. N_event_pred : np.ndarray Array of predicted event yields for each replica. neutrino_pdfs : np.ndarray Array of predicted neutrino PDFs for each replica. pred : np.ndarray Array of original pseudo-data predictions for each replica.
Returns¶
Tuple[np.ndarray, np.ndarray, np.ndarray] Filtered arrays of neutrino_pdfs, N_event_pred, and pred with outlier replicas removed.
Notes¶
Replicas whose chi-squared differ from the mean by more than 4 standard deviations are considered outliers and removed.
Source code in NN_fit/postfit_criteria.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
postfit_measures.py¶
Measures
¶
Source code in NN_fit/postfit_measures.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
N_event_pred = N_event_pred
instance-attribute
¶
Initialize Measures class with covariance matrix, PDF, and predicted events.
Parameters¶
cov_matrix : torch.Tensor Covariance matrix used in chi-squared calculations. pdf : np.ndarray Reference PDF array. N_event_pred : np.ndarray Predicted event yields array, shape (num_replicas, num_bins).
compute_accuracy(x_alphas, neutrino_pdf, pdf, n, pdf_set, pid)
¶
Compute the accuracy metric as the fraction of bins where the predicted neutrino PDF agrees with the reference PDF within n standard deviations.
Parameters¶
x_alphas : np.ndarray Input x-values (not used directly in this function). neutrino_pdf : np.ndarray Array of predicted neutrino PDFs (shape: replicas x bins). pdf : str Path or identifier for the reference PDF file. n : float Number of standard deviations for the acceptance criterion. pdf_set : str Identifier of the PDF set. pid : int Particle ID for PDF retrieval.
Returns¶
float Fraction of bins where predicted PDF agrees within n std deviations.
Source code in NN_fit/postfit_measures.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
compute_bias_to_variance(level0, level2, N_event_pred, REPLICAS)
¶
Compute the ratio of bias to variance in the PDF fits.
Parameters¶
level0 : Union[np.ndarray, torch.Tensor] Baseline theory prediction. level2 : np.ndarray Array of predictions at level 2, shape (REPLICAS, num_bins). N_event_pred : np.ndarray Predicted events for all replicas. REPLICAS : int Number of replicas.
Returns¶
torch.Tensor Ratio of bias to variance.
Source code in NN_fit/postfit_measures.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
compute_delta_chi(level0, N_event_pred, data_level1, x_vals)
¶
Compute the relative change in chi-squared between a baseline theory prediction and the fit prediction.
Parameters¶
level0 : Union[np.ndarray, torch.Tensor] Baseline theory prediction. N_event_pred : np.ndarray Predicted events for all replicas. data_level1 : torch.Tensor Observed data level 1 tensor, shape (num_bins, 1). x_vals : Union[np.ndarray, torch.Tensor] x-values (unused in this function).
Returns¶
torch.Tensor Relative change in chi-squared (delta chi).
Source code in NN_fit/postfit_measures.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
compute_phi(data, chi_squares)
¶
Compute the phi metric as the difference between average chi-square over replicas and chi-square of the mean prediction.
Parameters¶
data : Union[np.ndarray, torch.Tensor] Observed data points. chi_squares : List[float] List of chi-square losses per replica.
Returns¶
float The phi metric.
Source code in NN_fit/postfit_measures.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
pull.py¶
compute_pull(mean_pdf1, mean_pdf2, error_pdf1, error_pdf2)
¶
Computes pull between pdfs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean_pdf1
|
np array
|
neutrino pdf 1 |
required |
mean_pdf2
|
np array
|
neutrino pdf 2 |
required |
error_pdf1
|
np array
|
std neutrino pdf 1 |
required |
error_pdf2
|
np array
|
std neutrino pdf 2 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
pull |
Source code in NN_fit/pull.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
๐งฌ Miscellaneous Modules¶
form_loss_fct.py¶
complete_loss_fct_comb(pred, data, cov_matrix, f, int_point_nu, x_int, lag_mult_pos, lag_mult_int)
¶
Extended chi-squared loss for combined neutrino + antineutrino prediction, with constraints.
Parameters¶
pred : torch.Tensor Model predictions (shape: N). data : torch.Tensor Observed pseudo-data (shape: N). cov_matrix : torch.Tensor Covariance matrix for the data (shape: N x N). f : torch.Tensor Raw NN output without preprocessing (shape: N). int_point_nu : torch.Tensor Integral constraint vector (shape: N). x_int : torch.Tensor x-values for integral constraint (shape: N). lag_mult_pos : float Lagrange multiplier for positivity constraint. lag_mult_int : float Lagrange multiplier for integral normalization.
Returns¶
torch.Tensor Total loss.
Source code in NN_fit/form_loss_fct.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
complete_loss_fct_nu_nub(pred, data, cov_matrix, f, int_point_nu, int_point_nub, x_int, lag_mult_pos, lag_mult_int)
¶
Extended chi-squared loss for separate neutrino and antineutrino predictions, with constraints.
Parameters¶
pred : torch.Tensor Model predictions for observed data (shape: N). data : torch.Tensor Observed pseudo-data (shape: N). cov_matrix : torch.Tensor Covariance matrix for the data (shape: N x N). f : torch.Tensor Raw (non-preprocessed) neural network outputs (shape: N x 2), with: - f[:, 0]: neutrino component (ฮฝ) - f[:, 1]: antineutrino component (ฮฝฬ) int_point_nu : torch.Tensor Integral constraint values for ฮฝ (shape: N). int_point_nub : torch.Tensor Integral constraint values for ฮฝฬ (shape: N). x_int : torch.Tensor x-values for integral evaluation (shape: N). lag_mult_pos : float Lagrange multiplier for enforcing positivity. lag_mult_int : float Lagrange multiplier for enforcing normalization via integral.
Returns¶
torch.Tensor Total loss including chi-squared term, positivity penalty, and integral constraint.
Source code in NN_fit/form_loss_fct.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
raw_loss_fct(pred, data, cov_matrix)
¶
Standard chi-squared loss without any constraints.
Parameters¶
pred : torch.Tensor Model predictions (shape: N). data : torch.Tensor Observed pseudo-data (shape: N). cov_matrix : torch.Tensor Covariance matrix (shape: N x N).
Returns¶
torch.Tensor Chi-squared loss.
Source code in NN_fit/form_loss_fct.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
generate_data.py¶
aggregate_entries_with_indices(fk_tables, data, binwidths, low_bin, high_bin, threshold)
¶
Aggregates FK table rows and data bins until a minimum threshold of events is reached.
This function rebins cross section data, corresponding FK table rows, and bin widths such that each new bin has at least a specified number of events (threshold). This is often necessary for achieving meaningful statistical analysis in low-statistics bins.
Parameters¶
fk_tables : torch.Tensor The FastKernel table with shape (n_bins, n_x). data : np.ndarray Event data per bin (e.g., cross section bin width). binwidths : np.ndarray Width of each original bin. low_bin : np.ndarray Lower edges of the original bins. high_bin : np.ndarray Upper edges of the original bins. threshold : float Minimum number of events required to form a new rebinned bin.
Returns¶
rebin_data : list of float Aggregated event counts after rebinning. rebin_fk_table_mu : torch.Tensor Rebinned FK table rows (shape: new_n_bins n_x). rebin_binwidhts : np.ndarray Bin widths corresponding to rebinned bins. rebin_low_bin : np.ndarray Lower edges of the rebinned bins. rebin_high_bin : np.ndarray Upper edges of the rebinned bins.
Notes¶
- Remaining data after the last full threshold bin is added to the final bin.
- Bin widths are recomputed using weighted averages to ensure consistency.
Source code in NN_fit/generate_data.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
compute_pseudo_data(filename_fk_mub_n, filename_fk_mub_p, filename_fk_mu_n, filename_fk_mu_p, filename_binsize, pid, pdf_name, pdf_set)
¶
Computes pseudo-data for neutrino and anti-neutrino scattering using FK tables and PDFs.
This function processes FK tables (FastKernel weight tables) and convolves them with parton distribution functions (PDFs) to produce synthetic ("pseudo") data for both neutrinos (mu) and anti-neutrinos (mub). It also calculates associated statistical errors.
Parameters¶
filename_fk_mub_n : str Filename for the anti-neutrino FK table (neutron target). filename_fk_mub_p : str Filename for the anti-neutrino FK table (proton target). filename_fk_mu_n : str Filename for the neutrino FK table (neutron target). filename_fk_mu_p : str Filename for the neutrino FK table (proton target). filename_binsize : str Filename containing binning information (low, high bin edges, and widths). pid : int PDG ID of the relevant parton (e.g., 12, 14, 16 for neutrino flavors). pdf_name : str Name of the PDF set (e.g., "CT18", "NNPDF4.0"). pdf_set : int Index of the replica or member within the PDF set.
Returns¶
data_mu : np.ndarray
Pseudo-data for neutrino cross sections, binned.
data_mub : np.ndarray
Pseudo-data for anti-neutrino cross sections, binned.
error_mu : np.ndarray
Statistical uncertainty (sqrt(N)) for neutrino data.
error_mub : np.ndarray
Statistical uncertainty (sqrt(N)) for anti-neutrino data.
fk_tables_mu : torch.Tensor
Final combined FK table for neutrinos.
fk_tables_mub : torch.Tensor
Final combined FK table for anti-neutrinos.
low_bin : np.ndarray
Lower bin edges of the energy bins.
high_bin : np.ndarray
Upper bin edges of the energy bins.
binwidths_mu : np.ndarray
Widths of bins used for neutrino integration.
binwidths_mub : np.ndarray
Widths of bins used for anti-neutrino integration (same as binwidths_mu).
Notes¶
- This function uses hard-coded weights: 59.56% neutron and 40.44% proton contributions.
- Any negative or zero values in the pseudo-data are replaced with small positive values (0.1) to avoid numerical issues.
- Requires FK tables and bin sizes to be precomputed and available as text files.
Source code in NN_fit/generate_data.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
write_data(filename_fk_mub_n, filename_fk_mub_p, filename_fk_mu_n, filename_fk_mu_p, filename_binsize, pid, pdf_name, pdf_set, filename_to_store_events, filename_to_store_stat_error, filename_to_store_sys_error, filename_to_store_cov_matrix, min_num_events, observable, combine_nu_nub_data, multiplication_factor_sys_error)
¶
Computes pseudo-data from FK tables and PDFs, optionally rebins them, and writes the results to disk.
This function is the main pipeline to produce and store pseudo-experimental data, its statistical and systematic uncertainties, covariance matrix, binning information, and FastKernel tables, all ready for use in PDF fits or phenomenology studies.
Parameters¶
filename_fk_mub_n : str FK table for anti-neutrino interactions on neutrons. filename_fk_mub_p : str FK table for anti-neutrino interactions on protons. filename_fk_mu_n : str FK table for neutrino interactions on neutrons. filename_fk_mu_p : str FK table for neutrino interactions on protons. filename_binsize : str Filename for bin edges and widths (low, high, width). pid : int PDG ID of the target parton species. pdf_name : str Name of the LHAPDF set to use. pdf_set : int Index of the PDF replica or member. filename_to_store_events : str Base filename for storing rebinned event data. filename_to_store_stat_error : str Base filename for storing statistical uncertainties. filename_to_store_sys_error : str Base filename for storing systematic uncertainties. filename_to_store_cov_matrix : str Base filename for storing the inverse of the covariance matrix. min_num_events : int Minimum number of events per bin in the rebinned dataset. observable : str Observable label (e.g., "energy", "pt") used in output filenames. combine_nu_nub_data : bool If True, neutrino and anti-neutrino data are summed into one dataset. multiplication_factor_sys_error : float Factor to multiply event counts for estimating systematic uncertainties.
Returns¶
None Writes output files directly to disk.
Output Files¶
../../../Data/data/: - Re-binned event counts (combined, mu, mub)
../../../Data/uncertainties/: - Statistical and systematic uncertainties - Covariance matrix (inverted, diagonal only)
../../../Data/binning/: - Re-binned bin edges and widths (mu, mub, or combined)
../../../Data/fastkernel/: - Re-binned FK tables
Notes¶
- Assumes FK and bin files are already precomputed and exist in the expected format.
- The covariance matrix is stored in inverted form (1/ฯยฒ on the diagonal).
- Output filenames are automatically labeled with PID and threshold settings.
- Handles both the case where ฮฝ and ฮฝฬ data are stored separately or combined.
Source code in NN_fit/generate_data.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |
data.yaml, fit_settings.yaml, aall_fits/, runcards/, etc.¶
These files are config/data files and are not included here directly. You can describe them in a separate "Configuration Guide" if needed.
๐ All modules are automatically documented from Python docstrings using mkdocstrings. Type hints, function signatures, and class hierarchies are included where available.