Skip to content

Hessian PDF Covariance Matrix for theory predictions#1743

Merged
comane merged 6 commits into
masterfrom
hessian_pdf_covmat_for_theory_predictions
Jun 9, 2023
Merged

Hessian PDF Covariance Matrix for theory predictions#1743
comane merged 6 commits into
masterfrom
hessian_pdf_covmat_for_theory_predictions

Conversation

@comane
Copy link
Copy Markdown
Member

@comane comane commented May 25, 2023

The idea of this PR is to have the covmats.pdferr_plus_covmat function to take into account for the case in which the PDF has error_type = 'symmhessian'

@comane comane requested review from Zaharid and scarlehoff May 25, 2023 14:41
Copy link
Copy Markdown
Member

@scarlehoff scarlehoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test, an equivalent of

return API.groups_covmat_no_table(use_pdferr=True, **data_internal_cuts_config)
?

Also, could you run black on your code? (now it should be completely safe to do so :D)

return mat


@check_pdf_is_montecarlo
Copy link
Copy Markdown
Contributor

@Zaharid Zaharid May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should still be some check, for the error member types we don't support.

Comment thread validphys2/src/validphys/covmats.py Outdated
X = hessian_eigenvectors - central_predictions.reshape((central_predictions.shape[0],1))
# need to rescale the Hessian eigenvectors in case the eigenvector confidence interval is not 68%
X = X / rescale_fac
pdf_cov = np.einsum("ij,kj->ik",X, X)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be X@X.T which is clearer, if less efficient.

Comment thread validphys2/src/validphys/covmats.py Outdated

# need to subtract the central set which is not the same as the average of the
# Hessian eigenvectors.
X = hessian_eigenvectors - central_predictions.reshape((central_predictions.shape[0],1))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be something like central_prediction[:, np.newaxis] (or central_prediction[:, None])

@comane
Copy link
Copy Markdown
Member Author

comane commented Jun 7, 2023

Hi @Zaharid , @scarlehoff not sure of why test_regressions.test_replicachi2data is failing the test.
It is passing the test on my Mac.

@scarlehoff
Copy link
Copy Markdown
Member

You need to rebase / merge master. I think it is due to numpy 1.24.X, you probably have a different (older) version in your computer.

@comane comane force-pushed the hessian_pdf_covmat_for_theory_predictions branch from 0dd394b to 7efa7fd Compare June 8, 2023 18:10
@comane comane requested review from Zaharid and scarlehoff June 9, 2023 09:58
Copy link
Copy Markdown
Contributor

@Zaharid Zaharid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good afaict.

Comment thread validphys2/src/validphys/checks.py Outdated
raise CheckError(f"Error type of PDF {pdf} must be 'replicas' and not {etype}")


@make_check
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be using make_argcheck afaict.

Comment thread validphys2/src/validphys/checks.py Outdated
def check_pdf_is_montecarlo_or_symmhessian(ns, **kwargs):
pdf = ns['pdf']
etype = pdf.error_type
if (etype != 'replicas') and (etype != 'symmhessian'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be check(etype in {'replicas', 'symhessian'}, f"Error type of PDF {pdf} must be either 'replicas' or 'symmhessian' and not {etype}")

@Zaharid
Copy link
Copy Markdown
Contributor

Zaharid commented Jun 9, 2023

I wonder if it makes sense to move this kind of functionality to the stats classes themselves (clue being that we are using plenty of internal methods). Would be a different pr anyway.

@comane comane merged commit 077a0f3 into master Jun 9, 2023
@comane comane deleted the hessian_pdf_covmat_for_theory_predictions branch June 9, 2023 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants