You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(i'm amidst revisiting / generalizing the sampler api, though that wont happen for the next release, i presume you want every tuple value, not an "interval/range"?
@cartazio I didn't really have any idea about what intervals should mean - but I guess between (a,b) and (c,d) should probably be equivalent to the first member in the range a-c and the second in b-d.
@ndmitchell proposed above that "between (a,b) and (c,d) should probably be equivalent to the first member in the range a-c and the second in b-d". Under this interpretation we can define UniformRange, but I'm not quite convinced that this is a right and unambiguous thing to do. (That's basically what I meant to ask in the comment above)
I think we can define such instance if we treat a and b completely independent of each other. For example this could work:
instance (UniformRangea, UniformRangeb) =>UniformRange (a, b) where
uniformRM ((al, bl), (ah, bh)) g =do
a <- uniformRM (al, ah) g
b <- uniformRM (bl, bh) g
pure (a, b)
If we think of the tuples as some related value such complex numbers or something then it definitely doesn't make sense, but above instance (and similar one for Random) I believe could be pretty useful. @Shimuuar What's your take on this?
That would be easy to implement. And in some sense it is uniform. But it's wrong is we use interpretation: "sample uniformly every value between a and b". I think it's better to avoid defining weird instances from get-go
In that case, I think it would be ok to add such instance for Random, but not for UniformRange, since former already does not promise uniformity as with types like Float and Integer.
Defining more instances of Random than of UniformRange will motivate users to use the former and block its eventual deprecation. If we think that this is a handy instance, let's add it to UniformRange as well with a proper comment/clarification.
I certainly disagree with Random being deprecated, even over time! After over two decades of people using it, this would be a wrong move. Moreover, many programming languages have a concept like "Random", that produces some standard distribution that does not have a mathematical backing but is useful for programmers. Tuples here is a perfect example.
Users can choose themselves which instance they want to use. One says Uniform and it promises the uniform distribution, another one is Random, which makes it open to interpretation. Many of the types do coincide and that is fine, IMHO.
--| Takes a range /(lo,hi)/ and a pseudo-random number generator
-- /g/, and returns a pseudo-random value uniformly distributed over the
-- closed interval /[lo,hi]/, together with a new generator. It is unspecified
I do not particularly mind lifting this guarantee for Random, but I think that in future with a wider adoption of UniformRange people would ask for UniformRange for tuples as well. I would rather define either both, or none.
@Bodigrim the whole point of the Uniform and UniformRange classes coming into existence was for them to be different from Random type class. So when "people do ask", I'll be happy to tell them such instance cannot exist, but for now let's not worry about what "people might ask".
I am on the same page with @ndmitchell and @Shimuuar seems to support this idea as well.
So, let's remove the "uniform" promise from Random class, because it is already a lie and add some tuple instances for Random, but not UniformRange.
Which Random instances do not produce uniform distributions?
Integer, Float and Double. Calling random function for these types will produce values distributed uniformly in a subrange, instead of full range, because as you know full range is infinite
Activity
cartazio commentedon Apr 23, 2015
That sounds super reasonable. I'll talk about it with Dominic when we next
catchup.
I assume we probably don't need more Than size 6 or 10 tuples? :)
On Thursday, April 23, 2015, Neil Mitchell [email protected] wrote:
ndmitchell commentedon Apr 23, 2015
My particular use case was for 4 tuples - specifically, I wanted to call
seedTFGenwith a randomly chosen seed. Agreed, 6 seems sufficient.add Random tuple instances
cartazio commentedon Feb 25, 2018
@ndmitchell this is a good feature, i'll make it happen, see what i can do...
how would you specify/what to talk about generating samples / intervals?
cartazio commentedon Feb 25, 2018
(i'm amidst revisiting / generalizing the sampler api, though that wont happen for the next release, i presume you want every tuple value, not an "interval/range"?
ndmitchell commentedon Feb 26, 2018
@cartazio I didn't really have any idea about what intervals should mean - but I guess between
(a,b)and(c,d)should probably be equivalent to the first member in the rangea-cand the second inb-d.samuelpilz commentedon Apr 17, 2018
What is the status on this issue? Is there a chance that the pull-request will be merged and an update is published?
cartazio commentedon Apr 17, 2018
L-TChen commentedon Jan 25, 2019
Will this be happening soon? I am really looking forward to this feature. :-)
parent cfdfe6f
parent cfdfe6f
Fix quality and performance issues, add monadic API
Fix quality and performance issues, add monadic API
Fix quality and performance issues, add monadic API
Fix quality and performance issues, add monadic API
9 remaining items
Bodigrim commentedon Jun 24, 2020
@ndmitchell proposed above that "between (a,b) and (c,d) should probably be equivalent to the first member in the range a-c and the second in b-d". Under this interpretation we can define
UniformRange, but I'm not quite convinced that this is a right and unambiguous thing to do. (That's basically what I meant to ask in the comment above)lehins commentedon Jun 24, 2020
I think we can define such instance if we treat
aandbcompletely independent of each other. For example this could work:If we think of the tuples as some related value such complex numbers or something then it definitely doesn't make sense, but above instance (and similar one for
Random) I believe could be pretty useful. @Shimuuar What's your take on this?Shimuuar commentedon Jun 24, 2020
That would be easy to implement. And in some sense it is uniform. But it's wrong is we use interpretation: "sample uniformly every value between
aandb". I think it's better to avoid defining weird instances from get-golehins commentedon Jun 24, 2020
In that case, I think it would be ok to add such instance for
Random, but not forUniformRange, since former already does not promise uniformity as with types likeFloatandInteger.Bodigrim commentedon Jun 24, 2020
Defining more instances of
Randomthan ofUniformRangewill motivate users to use the former and block its eventual deprecation. If we think that this is a handy instance, let's add it toUniformRangeas well with a proper comment/clarification.lehins commentedon Jun 24, 2020
I certainly disagree with
Randombeing deprecated, even over time! After over two decades of people using it, this would be a wrong move. Moreover, many programming languages have a concept like "Random", that produces some standard distribution that does not have a mathematical backing but is useful for programmers. Tuples here is a perfect example.Users can choose themselves which instance they want to use. One says
Uniformand it promises the uniform distribution, another one isRandom, which makes it open to interpretation. Many of the types do coincide and that is fine, IMHO.Bodigrim commentedon Jun 24, 2020
The problem is that currently
RandomandrandomRare not open to intepretation: they do claim uniformity.random/src/System/Random.hs
Lines 189 to 190 in 11464aa
random/src/System/Random.hs
Lines 197 to 199 in 11464aa
I do not particularly mind lifting this guarantee for
Random, but I think that in future with a wider adoption ofUniformRangepeople would ask forUniformRangefor tuples as well. I would rather define either both, or none.ndmitchell commentedon Jun 24, 2020
FWIW, I have no particular desire for a uniform range in 99%+ of cases. I've wanted random tuples a handful of times. I'm perfectly happy with Random.
lehins commentedon Jun 24, 2020
@Bodigrim the whole point of the
UniformandUniformRangeclasses coming into existence was for them to be different fromRandomtype class. So when "people do ask", I'll be happy to tell them such instance cannot exist, but for now let's not worry about what "people might ask".I am on the same page with @ndmitchell and @Shimuuar seems to support this idea as well.
So, let's remove the "uniform" promise from
Randomclass, because it is already a lie and add some tuple instances forRandom, but notUniformRange.Bodigrim commentedon Jun 24, 2020
If we communicate the difference between
RandomandUniformclearly and unambiguously, then I'm on board as well.curiousleo commentedon Jun 25, 2020
@lehins wrote:
I'm on board with this conclusion.
I don't understand this premise. Which
Randominstances do not produce uniform distributions?lehins commentedon Jun 25, 2020
Integer,FloatandDouble. Callingrandomfunction for these types will produce values distributed uniformly in a subrange, instead of full range, because as you know full range is infinitelehins commentedon Jun 29, 2020
There is implementation for this ticket in #72 if anyone feels like giving it a review.
lehins commentedon Sep 19, 2021
Finally this is implemented and is merged into master. These instances will be soon released with
random-1.2.1