Repository navigation
Add df to the params of the T distributions - #440
Open
alejandroschuler wants to merge 1 commit into
Open
alejandroschuler wants to merge 1 commit into
alejandroschuler wants to merge 1 commit into
Conversation
The params property of T, TFixedDf and TFixedDfFixedVar returned only loc and scale, although each of these distributions has a df. So scipy.stats.t(**dist.params) raised a TypeError, and any tool that reads params could not see the degrees of freedom. The example notebook read dists.df directly to work around this. params now includes df for all three classes. Cauchy and CauchyFixedVar inherit the change, with df equal to 1. The existing keys and their values do not change. The example notebook now passes dists[i].params to scipy.stats.t.pdf. Found while assessing #168. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Found while assessing #168.
The
paramsproperty ofT,TFixedDfandTFixedDfFixedVarreturned onlylocandscale, although each of these distributions has adf. Soscipy.stats.t(**dist.params)raised aTypeError, and any tool that readsparamscould not see the degrees of freedom.notebooks/example_t.ipynbreaddists.dfdirectly to work around this.This PR adds
dftoparamsfor all three classes.CauchyandCauchyFixedVarinherit fromTFixedDfandTFixedDfFixedVar, so they now reportdfequal to 1. The existing keys and their values do not change. The diff is three one-line edits inngboost/distns/t.py, kept away from the__getattr__methods that #433 edits. A trial merge of this branch with #433 has no conflicts.Example
dist.paramsscipy.stats.t(**dist.params){'loc': ..., 'scale': ...}TypeError: _parse_args() missing 1 required positional argument: 'df'{'loc': array([0., 1.]), 'scale': array([1., 1.]), 'df': array([3., 3.])}logpdfis[-1.161, -1.576], equal todist.logpdfTests
test_t_family_params_match_scipyruns forT,TFixedDf,TFixedDfFixedVar,CauchyandCauchyFixedVar. For each class it checks thatparamshas the keysloc,scaleanddf, thatlocanddfkeep their values, thatdfis 3 or 1 for the fixed-df classes, and thatscipy.stats.t(**dist.params)gives the samelogpdfandppfas the distribution. All 5 cases fail on master.black,isort,flake8andpylintare clean on the changed Python files, with the options from.pre-commit-config.yaml.notebooks/example_t.ipynbhas one code line changed, so that the density plot uses**dists[i].params. The stored outputs in the notebook are unchanged, and I did not run it again.🤖 Generated with Claude Code