-
Notifications
You must be signed in to change notification settings - Fork 3
first draft of how pdf and parameters joint structure could look like #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0aec0a
first draft of how pdf and parameters joint structure could look like
comane 832d904
added extra_params and full_param_names as properties
comane f38bb1b
use full_param_names in bayes prior and ultranest modules
comane d03ded3
changed param_names to full_param_names in the entire code
comane 071a813
use generic predictions in when generating theory predictions
comane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,27 @@ class PDFModel(ABC): | |
| @property | ||
| @abstractmethod | ||
| def param_names(self) -> list: | ||
| """This should return a list of names for the fitted parameters of the model. | ||
| """This should return a list of names for the fitted parameters of the PDF model. | ||
| The order of the names is important as it will be assumed to be the order of the parameters | ||
| fed to the model. | ||
| """ | ||
| pass | ||
|
|
||
| @property | ||
| def extra_params(self) -> list: | ||
| """ | ||
| This should return a list of names for parameters that are not used to parametrize the PDF model, | ||
| but are still relevant for the model (e.g. heavy quark masses, SMEFT parameters, etc.). | ||
|
|
||
| Default is an empty list. | ||
| """ | ||
| return [] | ||
|
|
||
| @property | ||
| def full_param_names(self) -> list: | ||
| """Returns a list of all parameter names, including both PDF model parameters and extra parameters.""" | ||
| return self.param_names + self.extra_params | ||
|
|
||
| @abstractmethod | ||
| def grid_values_func(self, xgrid: ArrayLike) -> Callable[[jnp.array], jnp.ndarray]: | ||
| """This function should produce a grid values function, which takes | ||
|
|
@@ -90,3 +105,54 @@ def pred_and_pdf(params, fast_kernel_arrays): | |
| return predictions, pdf | ||
|
|
||
| return pred_and_pdf | ||
|
|
||
| def extra_forward_map(self, predictions, extra_params): | ||
| """ | ||
| NOTE: | ||
| this function here is user specified and can potentially be anything. | ||
| The default forward_map always computes theory predictions from PDFs and FK tables. | ||
|
|
||
| This function can be completed to modify the predictions computed from the PDFs, | ||
| using extra parameters that are not part of the PDF parametrization. | ||
|
|
||
| e.g. (how the function could look like for SMEFT): | ||
| def extra_forward_map(self, predictions, extra_params): | ||
| # extra_params could contain SMEFT Wilson coefficients | ||
| # Modify predictions based on SMEFT contributions | ||
| modified_predictions = predictions + compute_smeft_contributions(predictions, extra_params) | ||
| return modified_predictions | ||
|
|
||
| Parameters | ||
| ---------- | ||
| predictions: jnp.ndarray | ||
| The theory predictions computed from the PDFs. | ||
| extra_params: list | ||
| The extra parameters to modify the predictions. | ||
| """ | ||
| raise NotImplementedError( | ||
| "extra_forward_map is not implemented for this PDFModel." | ||
| ) | ||
|
|
||
| def predictions(self, xgrid, forward_map): | ||
| """ | ||
| The default simply returns self.pred_and_pdf_func when the extra_forward_map is NotImplemented. | ||
|
|
||
| TODO: ... | ||
| """ | ||
| pred_and_pdf = self.pred_and_pdf_func(xgrid, forward_map) | ||
|
|
||
| # Check if extra_forward_map is implemented | ||
| if self.extra_forward_map.__func__ is PDFModel.extra_forward_map: | ||
| return pred_and_pdf | ||
| else: | ||
|
|
||
| def modified_pred_and_pdf(params, fast_kernel_arrays): | ||
| predictions, pdf = pred_and_pdf( | ||
| params[: len(self.param_names)], fast_kernel_arrays | ||
| ) | ||
| modified_predictions = self.extra_forward_map( | ||
| predictions, params[len(self.param_names) :] | ||
| ) | ||
| return modified_predictions, pdf | ||
|
|
||
| return modified_pred_and_pdf | ||
|
Comment on lines
+136
to
+158
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function takes the same inputs of pred_and_pdf_func, so maybe all of this can be implemented directly inside of it? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking more about this, I am not sure how this can be done.
The call function in the likelihood.py module is passed directly to the sampler and requires an array in input.
Do you have some ideas @LucaMantani ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it shouldn't be impossible to modify the call method so that params is not an array. I did that in the batching PR, modifying the batch_idx to a batch dataclass.