-
Notifications
You must be signed in to change notification settings - Fork 52
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
Instances for Ratio
#75
Comments
It isn't uniform. Let take for sake of simpliciti |
@Shimuuar It is uniform as far as the I understand that with respect to the actual rational numbers over the infinite space, this is not uniform, but the type is not infinite. That means we need to decide. Is |
When it come to numbers uniform usually understood as distributed on number line with uniform density. For Ints & Words we work on uniform grid so notions of uniform density and generate every inhabitant with equal probability coincide. For floats we try to approximate density and abandon every inhabitant with equal probability. But this instance is not uniform in either sense! It generates |
The problem is that |
I see what you mean. So my suggested implementation is bogus. That's fine. Question is can we come up with a sensible implementation(s) for the |
For In my experience |
Also I think that approach "generate every inhabitant with equal probability" is just a giant footgun. I don't think anyone would expect such semantics. |
@Shimuuar What would you expect if someone asked you: Generate a random rational number for me please? |
@Bodigrim I remember helping out a friend with this and he came up with this validation for CC @NorfairKing |
@lehins For the record, this is how
You can probably generate the denominator more easily if you assume |
Well I certainly don't expect such questions. But it's impossible to speak about generating random numbers without specifying distribution first. So we either know what we're talking about or person asking such question deserve some ridicule But then if we have Uniform why nor UniformRange? How UniformRange should work then? It it uses same approach: "generate every inhabitant with equal probability" why then it works differently from Float/Double. They're just a different subset of rationals after all. |
FWIW if I'd ask a library to generate random |
Lol. I am asking you one right now ;) Basically how would you solve it? We need uniform distribution for |
"Don't try to be clever just use doubles". It's question about building unform distributions between two really big numbers (0, maxBound :: Word64) for example. It's very hard problem since it requiring carefully weighting numbers on very uneven grid. I'm not sure it's even possible without excessive lookup tables |
lol. I am already submitting a PR to ghc to remove It is a hard problem, but I don't think it is an unsolvable one. We definitely don't have to decide on it now, so let's think about it and see what we can come up with. |
I'm quite serious BTW. Generating doubles, casting them to Rationals and working with them in case you need to work with them is quite viable approach. Another one is to generate |
On the other hand, if we decide to give a green light to new instances of |
Sounds reasonable.
I like it. |
This would be inappropriate in testing, but there's no reason why |
That sounds as reasonable choice for Random instance. BTW it's not necessary to involve Doubles we can just use: n <- (fromIntegral :: Word64 -> Integer) <$> unform
return $ n % (2^64-1) |
There is currently no instances for
Ratio
data type that can give us random valuesI can see a reasonable
Uniform
instance for integral types, which excludes the zero denominator:An efficient version for
UniformRange
needs some thought.Note that neither
Uniform
, norUniformRange
would be able to generateRational
. This means that we can attempt and cook up such instance forRandom
The text was updated successfully, but these errors were encountered: