Skip to content
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

Add flag for the derivative of thePDF #1605

Merged
merged 14 commits into from
Oct 19, 2022
Merged

Conversation

scarlehoff
Copy link
Member

@scarlehoff scarlehoff commented Sep 23, 2022

This PR adds the derivative flag to validphys which can be used to get derivatives of the xplotting_grids (so it will be used automatically by any PDF plotting routine).

Example: https://vp.nnpdf.science/Tj8jTeWhSki5ObB17nV1BQ==/#pdf-bands-2

@RoyStegeman
Copy link
Member

I think eps needs to be scaled as well in case of logs?

@Zaharid
Copy link
Contributor

Zaharid commented Sep 23, 2022

Not clear to me what do we want to plot here. Is it f(x)? xf(x)? Some logs somewhere?

@RoyStegeman
Copy link
Member

RoyStegeman commented Sep 23, 2022

Arc length on a log scale. Though in that case I guess we especially don't want to scale eps since that would leave the result unchanged

@scarlehoff
Copy link
Member Author

Yes. This is what I think people has asked for.

But in all honesty it is not 100% clear to me whether I'm understanding it correctly, that's why I wanted some feedback before showing any plots...

@RoyStegeman
Copy link
Member

Well what they really wanted is the derivative itself instead of the integral I think, in which cate we would need a plot per PDF

@scarlehoff
Copy link
Member Author

That was yet a different thing, right?

And again, not super clear, they want the derivative of the PDF so basically a plot of d(xf(x))/dx ? or xd(f(x))/dx or d(xf(x))/dlogx?

(that I will just do a simple plot using lhapdf though, unless it turns out to be super important)

@ldd69
Copy link
Contributor

ldd69 commented Sep 23, 2022 via email

@scarlehoff
Copy link
Member Author

Hi @ldd69, could you resend that email? I've recently changed e-mails and I cannot find it now so maybe it slipped between the cracks. Thanks.

In any case, when you say f do you mean f(x) or xf(x) (we are always plotting xf(x))?

@ldd69
Copy link
Contributor

ldd69 commented Sep 23, 2022 via email

@scarlehoff
Copy link
Member Author

Our convention is that f_j is xf(x).

@scarlehoff
Copy link
Member Author

I've done the derivative for f_j = xf(x), the result is:

(log scale in both x and y)
test

For representation purposes I've also done d/dlog(x) so that I could use a linear scale in y:
derivative

Not sure which is better. In any case, I'm a bit worried that the results are not very different between CT and NNPDF (below the gluon with a log scale as well for comparison)
standard_gluon

I'll do it using vp so that people can audit the code to make sure I didn't made any mistakes. And to facilitate as well plotting the 1-sigma bands for NNPDF instead of raw replicas.

For completeness, the output of the arclength using an xgrid
plot_arc_lengths

with respect to using the normal one:
plot_arc_lengths

The arclength one I will remove (since as @RoyStegeman said above, it would be inconsistent) and I will add instead the possibility of plotting the derivative with vp as @ldd69 requested then we can play with it as we see fit.

@RoyStegeman
Copy link
Member

The arclength one I will remove (since as @RoyStegeman said above, it would be inconsistent)

Not inconsistent per se I think; we're just not calculating the arclength of the PDFs themselves (according to its common definition), but rather of an object that combines the PDFs with a logarithmic scaling of x. It is still an arclength-like feature of the PDF so perhaps it's useful(?)

In particular the first plot is a bit spoiled by numerical issues, but could it be that the second derivative of the NNPDF replicas are pretty much flat, while that of the CT pdfs is not? On the other hand, after the bump between x=1e-5 and 1e-4, also the CT central value seems to have a rather constant second derivative.

@scarlehoff
Copy link
Member Author

I've added a derivative: bool flag which gets read by xplotting_grid so any derived (heh) quantity will receive actually the derivative of the PDF (for instance the PDF plots).

Example report with the df / dlogx for NNPDF and CT with band plots and replica plots:
https://vp.nnpdf.science/jM9wSap9RlyRDRkgbr4Ezg==/

I'm using np.gradient with the plotting x-grid of the PDF and letting vp deal with the rest. I've opted for d/dlog(x) since it worked best with vp (otherwise I would have to deal with the y-scale, maybe differently per-flavour).

Things to-do: the y-axis label needs to depend not only on the PDF flavour but has to allow for some extra information. I'll see how to do that without too much hacking, but it is relatively minor point.

@scarlehoff
Copy link
Member Author

scarlehoff commented Sep 26, 2022

Taking further derivatives is simply a question of changing the flag from a bool to an int:* https://vp.nnpdf.science/hrCzYH0cRJG2N0mT16Xo4w==
but let's first make sure that I didn't make any mistakes in the first one :P

(the changes to vp are actually very minimal at this point so it should be easy on whoever wants to review it!)

*in this report I also removed the central value for ct from the replicas which is misleading, but this needs atm a bit of ugly patching

@Zaharid
Copy link
Contributor

Zaharid commented Sep 26, 2022

@enocera @scarlehoff how does np.gradient compare with the thing in here #1581 (comment)?

@enocera
Copy link
Contributor

enocera commented Sep 26, 2022

@enocera @scarlehoff how does np.gradient compare with the thing in here #1581 (comment)?

@Zaharid That's an interesting question - I guess that your suggestion would be: if np.gradient does the same thing as in #1581 (comment), why not using np.gradient also in #1581?

@Zaharid
Copy link
Contributor

Zaharid commented Sep 26, 2022

Yes, that was my thought.

@enocera
Copy link
Contributor

enocera commented Sep 26, 2022

OK. So let me check if I can adapt np.gradient in #1581.

@Zaharid
Copy link
Contributor

Zaharid commented Sep 26, 2022

I think I'd prefer a separate provider for the derivative grid (and subsequent stuff). For one if you set derivative: True all the labels in all the plots (minus the one being looked at here) become wrong. That smells like it would be handled better by separate code paths.

We do something similar for the distances.

@scarlehoff
Copy link
Member Author

minus the one being looked at here

What do you mean? They should all be wrong.

@Zaharid
Copy link
Contributor

Zaharid commented Sep 26, 2022

I had this bit in mind

    scl_txt = "" if xscale == "linear" else "log-"

but indeed that is something else.

@scarlehoff
Copy link
Member Author

Ah, yes. I guess the title of the PR is now misleading. I haven't changed the labels, only added the possibility of generating plots with the derivatives.

@scarlehoff scarlehoff changed the title [WIP] Kinetic arclength [WIP] Added the derivative of the PDF & log arclength Sep 26, 2022
@scarlehoff
Copy link
Member Author

Since there are no complains, I think I will hack together something for the labels and then send an updated version of https://vp.nnpdf.science/hrCzYH0cRJG2N0mT16Xo4w==/ to the mailing list.

@RoyStegeman
Copy link
Member

Maybe it's also worth including the log-scaled arclength? At least there you can see a bit of a difference between ct an nnpdf40 (though it's not so clear ot me if it's coming from outside the data region or instead just corresponds to the behavior we see between 1e-2 and 1e-4)

@scarlehoff
Copy link
Member Author

it's also not clear to me and honestly woudn't know how to justify it at all... if some insight can be obtained from the derivatives I would prefer that since at least I understand it.

@RoyStegeman
Copy link
Member

Fair enough

@scarlehoff
Copy link
Member Author

It is actually not so hacky, kudos to the PDFPlotter + Xplottinggrids thing, it's much more flexible and accommodating than I thought.

https://vp.nnpdf.science/Tj8jTeWhSki5ObB17nV1BQ==/#pdf-bands-2

@scarlehoff scarlehoff changed the title [WIP] Added the derivative of the PDF & log arclength Add flag for the derivative of thePDF Sep 29, 2022
@scarlehoff scarlehoff marked this pull request as ready for review September 29, 2022 10:08
@scarlehoff
Copy link
Member Author

I've removed the changes to arclength and left only the possibility of having the derivative of plots. Please review when possible.

@ldd69
Copy link
Contributor

ldd69 commented Oct 11, 2022 via email

@ldd69
Copy link
Contributor

ldd69 commented Oct 11, 2022 via email

Copy link
Member

@RoyStegeman RoyStegeman left a comment

Choose a reason for hiding this comment

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

Logic seems fine, just needs the one change.

validphys2/src/validphys/pdfplots.py Outdated Show resolved Hide resolved
scarlehoff and others added 2 commits October 18, 2022 14:52
Co-authored-by: Roy Stegeman <roystegeman@live.nl>
@scarlehoff
Copy link
Member Author

I'll merge this once the test is done. Thanks for the review @RoyStegeman

@scarlehoff scarlehoff merged commit 94b80c3 into master Oct 19, 2022
@scarlehoff scarlehoff deleted the use_a_loggrid_for_arclength branch October 19, 2022 08:46
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.

5 participants