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

Inverse / normal-inverse gaussian distributions #954

Merged

Conversation

elaye
Copy link
Contributor

@elaye elaye commented Mar 20, 2020

Discussed in #952 .

assert!(InverseGaussian::new(-1.0, -1.0).is_err());
assert!(InverseGaussian::new(1.0, -1.0).is_err());
assert!(InverseGaussian::new(1.0, 1.0).is_ok());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to have a test for value stability, but I guess that can also be added later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a value stability test by trying to reproduce what was done for the other distributions but I'm not sure of what is to be tested

assert!(NormalInverseGaussian::new(-1.0, -1.0).is_err());
assert!(NormalInverseGaussian::new(1.0, 2.0).is_err());
assert!(NormalInverseGaussian::new(2.0, 1.0).is_ok());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, a value stability test could be added.

@vks
Copy link
Collaborator

vks commented Mar 21, 2020

I did not verify whether the sampling is correct, but the code looks good.

Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

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

Looks like carefully written code, and I was able to check at least that the Inverse Gaussian sampling algorithm matches that on Wikipedia.

rand_distr/src/normal_inverse_gaussian.rs Outdated Show resolved Hide resolved
rand_distr/src/normal_inverse_gaussian.rs Outdated Show resolved Hide resolved
rand_distr/src/normal_inverse_gaussian.rs Outdated Show resolved Hide resolved
rand_distr/src/normal_inverse_gaussian.rs Show resolved Hide resolved
rand_distr/src/normal_inverse_gaussian.rs Show resolved Hide resolved
@elaye
Copy link
Contributor Author

elaye commented Mar 21, 2020

@vks I checked the sampling of the normal-inverse Gaussian distribution manually by generating a bunch of points, fitted them using scipy's norminvgauss function and checked that the parameters were the same.
And since the normal-inverse Gaussian depends on the inverse Gaussian I assumed the inverse Gaussian was ok too.

Copy link
Collaborator

@vks vks left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks a lot!

@dhardy dhardy merged commit d0a584c into rust-random:master Mar 26, 2020
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.

None yet

3 participants