auto-infer locations for predict_dte/pte/ldte/lpte (#68)#114
Merged
Conversation
Make the locations argument optional in predict_dte, predict_pte, predict_ldte, and predict_lpte. When omitted, locations are generated automatically from the observed outcomes using np.linspace with a bin count derived from np.histogram_bin_edges(outcomes, bins='auto'). For the interval-based methods (PTE/LPTE), the left endpoint is shifted just below outcomes.min() so the smallest observation falls inside the first interval. The actual locations array used is stored on estimator.last_locations for plotting and downstream use.
TomeHirata
reviewed
Jun 16, 2026
| # is representable even when the outcome range is zero. | ||
| scale = max(y_max - y_min, abs(y_min), abs(y_max), 1.0) | ||
| eps = scale * 1e-9 | ||
| return np.linspace(y_min - eps, y_max, n_locations) |
Collaborator
There was a problem hiding this comment.
Why do we produce evenly-spaced locations instead of directly using the bins proposed by histogram_bin_edges?
Collaborator
Author
There was a problem hiding this comment.
Thank you for a comment. This is leftover from an earlier design that exposed an n_locations argument, so we extracted the count and rebuilt via linspace. The indirection became redundant when n_locations was dropped. I'll refactor to use the histogram_bin_edges output directly.
Removes the redundant linspace round-trip that was left over after the n_locations argument was dropped during review. The for_intervals path still overrides the leftmost edge so the minimum observation falls inside the first interval.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #68. Make the
locationsargument optional inpredict_dte,predict_pte,predict_ldte, andpredict_lpte. When omitted, locations are generated automatically from the observed outcomes so users no longer need to writenp.linspace(Y.min(), Y.max(), N)themselves.Behavior
locations=None(default) → evenly-spaced locations spanning[Y.min(), Y.max()], with the bin count derived fromnp.histogram_bin_edges(outcomes, bins='auto')(combines Sturges and Freedman-Diaconis rules, scaling with data size and IQR).predict_pte/predict_lpte, the left endpoint is shifted just belowoutcomes.min()so that the smallest observation falls inside the first interval(loc[0], loc[1]].locations=ndarray(existing behavior) → used as-is. Fully backward compatible.estimator.last_locationsfor plotting / downstream use.Example
Test plan
_infer_default_locationsunit tests (tests/test_utils.py).SimpleDistributionEstimator.predict_dte/predict_pte(tests/test_simple_estimator.py).SimpleLocalDistributionEstimator.predict_ldte/predict_lpte(tests/test_local_estimators.py).