-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implementing original qp PDF constructor #150
Conversation
…LSSTDESC/qp into issue/8/original-qp-exploration
…r switching and using constructors in quant_gen.
…ailed due to removing `quant_piecewise`
When I run unit tests locally I see the following tests failing:
|
…or so that unit tests continue to pass.
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## main #150 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 31 +6
Lines 2047 2117 +70
=========================================
+ Hits 2047 2117 +70
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
||
|
||
|
||
class quant_piecewise_gen(Pdf_rows_gen): |
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.
Completely removed this class because it is now superfluous. It was originally created so that an alternative pdf reconstruction algorithm could be implemented. Now that the pdf reconstruction algorithms are separated into their own classes and selectable at run time, we no longer need this class.
@@ -64,6 +72,13 @@ def pad_quantiles(quants, locs): | |||
|
|||
return quants_out, locs_out | |||
|
|||
DEFAULT_PDF_CONSTRUCTOR = 'piecewise_linear' |
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.
Selecting this PDF constructor as the default for now, only because there are unit tests with hard coded quant_gen.pdf() output values that will fail if we use a different constructor.
It would be preferable to use cdf_spline_derivative
, however, I would like to defer that work to be done by (or in collaboration with) a researcher.
@@ -136,12 +144,63 @@ def locs(self): | |||
"""Return the locations at which those quantiles are reached""" | |||
return self._locs | |||
|
|||
@property | |||
def pdf_constructor_name(self): |
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.
This and the following three new methods are the machinery that allow the user to dynamically select pdf constructors at run time.
…onstruction algorithms.
…t around forever.
…tebook into the demo notebook in a "Reference" section at the end.
# ! create an issue (or fix) if the spline fit fails, can fall back to a simpler interpolator ??? | ||
self._interpolation_functions = [ | ||
InterpolatedUnivariateSpline(self._locations[i,:], self._quantiles, k=spline_order, ext=1).derivative() | ||
for i in range(0,number_of_locations) |
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.
Does this line do anything?
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.
Yeah, while it doesn't look like it, it does. Lines 51-54 represent a list comprehension spread out over several lines to try to make it more readable.
Usually list comprehension is a single line like:
output = [do_thing(i) for i in list_of_i_values]
But here, do_thing(i)
is a long line, and I felt like it was more readable if it was split up.
tests/qp/quantile_pdf_constructors/test_cdf_spline_derivative.py
Outdated
Show resolved
Hide resolved
…to dual_spline_average and added a test. Updated the demo notebook.
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.
Someone else should probably check the math, but the structure looks good!
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 things look good, two minor points, though:
If you want to keep the temp_quantile_parameterization_under_the_curve_impl.ipynb
notebook, maybe rename without the "temp" in the notebook name.
In demo.ipynb
it looks like there's a problem with the pdf/cdf/ppf/etc... when the demo creates a single qp.quant_gen
distribution with a single set of quants and locs rather than an ensemble. Calling .pdf .ppf .cdf throws a
TypeError: _parse_args() missing 1 required positional argument: 'row'
error from scipy, i.e. there is no row argument from a single distribution rather than an ensemble ( a qp.quant Ensemble with a single distribution works fine, though). We should fix this or update the demo notebook so that it executes.
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.
Looks good, thanks Drew!
Modified the quantile distribution class to allow users to select from a variety of pdf reconstructors to best support their use case. The pdf construction algorithms include the original qp cdf spline derivative, a new average-of-splines approach, piecewise linear, and piecewise constant.
This branch also includes a new demo notebook with examples of how the quantile distribution class works, how to change pdf constructors, and includes a variety of example input distributions that are approximated by quantile distribution, and reconstructed with each of the different pdf construction algorithms.