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

Reorder sigma and lam parameter in StudentT distribution #5602

Closed
ricardoV94 opened this issue Mar 16, 2022 · 9 comments · Fixed by #5628
Closed

Reorder sigma and lam parameter in StudentT distribution #5602

ricardoV94 opened this issue Mar 16, 2022 · 9 comments · Fixed by #5628

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Mar 16, 2022

It's a bit surprising that lam appears before sigma, when defining a StudentT with positional arguments.

def dist(cls, nu, mu=0, lam=None, sigma=None, sd=None, *args, **kwargs):

The docstrings suggest sigma comes before, and this is actually the case for the HalfStudentT. In the Normal, sigma also shows up before tau. I think we should reverse them so that sigma takes precedence here as well.

This would warrant a user warning about the changed behavior, which would need a dummy new variable like _sigma=None so that we can detect a positional only argument was used.

This emerged recently in discourse: https://discourse.pymc.io/t/pymc3-produces-different-results-than-stan-numpyro/9030/5

@ricardoV94 ricardoV94 changed the title Reorder sigma an lam parameter in StudentT distribution Reorder sigma and lam parameter in StudentT distribution Mar 16, 2022
@cluhmann
Copy link
Member

This seems reasonable to me. Hopefully this will be less of an issue as the docs are updated, but it seems like it should at least be consistent across student, half student, normal, half normal, etc. Are there any other distributions with surprising "defaults" like this?

@ricardoV94
Copy link
Member Author

Are there any other distributions with surprising "defaults" like this?

I didn't look for more. Do you want to have a look?

@twiecki
Copy link
Member

twiecki commented Mar 17, 2022

I agree, the reason is that there used to be only the lam parameter so sigma is the "alternative" parameterization. Nonetheless, that's anachronistic and there are many good reasons to change it as you mention. In addition, it seems to bring us in line with other packages which is also good.

@cluhmann
Copy link
Member

Are there any other distributions with surprising "defaults" like this?

I didn't look for more. Do you want to have a look?

I can poke around and see if I see any other weirdness.

@michaelosthege
Copy link
Member

Instead of changing the order, why don't we require these as explicit kwargs?
That way we still break code that passes them positionally, but at least we don't break it silently.

@cluhmann
Copy link
Member

That is certainly my practice. Not only are there are alternative ways of specifying a given moment (sigma vs. precision), but there are cases in which there are entire specifications (e.g., gamma) and I don't trust myself to remember which one which is the default one. Ultimately, I think this boils down to a tradeoff between verbosity and explicitness (and I know I value the latter).

@cluhmann
Copy link
Member

I went through the continuous and discrete distributions. Normal, HalfNormal, TruncatedNormal, and LogNormal all adhere to the same mu, sigma, tau, sd argument order. SkewNormal and HalfStudentT use this same order but take alpha (SkewNormal) and nu (HalfStudentT) first, before these other parameters.

  • As mentioned above, StudentT deviates from this by taking arguments in the order: nu, mu, lam, sigma, sd.

  • The other oddity is that HalfStudentT defaults to nu=1, whereas StudentT has no default value for nu. I can't see any reason for this difference.

  • The only other thing that jumped out at me was that Laplace takes arguments mu and b, whereas AsymmetricLaplace takes b, kappa, and then mu.

  • In addition, AsymmetricLaplace has a default value of mu=0 (which may be related to why it is last in the signature?) whereas Laplace has no default value for mu.

  • Finally, I guess an argument could be made that AsymmetricLaplace should take kappa as its first argument given the signatures of SkewNormal and [Half]StudentT.

@ricardoV94
Copy link
Member Author

I think those all benefit from being standardized @cluhmann. Would you be interested in opening a PR to fix it?

@cluhmann
Copy link
Member

Messing with such a central part of the package makes me slightly nervous, but sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants