Re: Re: bug in RandomChoice if weight is zero?
- To: mathgroup at smc.vnet.net
- Subject: [mg106056] Re: [mg106027] Re: [mg105976] bug in RandomChoice if weight is zero?
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Thu, 31 Dec 2009 03:17:45 -0500 (EST)
- References: <200912290617.BAA02582@smc.vnet.net>
Nothing, but as I said, issuing diagnostic message for this particular case seems to me like a point solution, given that there may be extremely small non-zero weights expressed analytically (as a rational for example). I may be wrong of course. On Wed, Dec 30, 2009 at 8:29 AM, DrMajorBob <btreat1 at austin.rr.com> wrote: > Generally, what you ask for should be possible once you give a specific >> interpretation of what you mean by zero >> > > What's ambiguous about the Integer 0? > > Bobby > > > On Wed, 30 Dec 2009 03:17:21 -0600, Leonid Shifrin <lshifr at gmail.com> > wrote: > > Hi Matthias, >> >> presumably this is because RandomSample never samples any given element >> more >> than once - in that case it has no other choice, regardless of the weight. >> Perhaps, the error message might be added for exact symbolic zero >> appearing >> somewhere in the wieights for the case where the size of the desired >> sample >> is larger than the number of non-zero weights (non-zero means >> UnsameQ[weight,0]). It is not clear however whether it is worth it given >> the overhead of such an analysis. Besides, this will be a point solution >> anyway, since some expressions that might be used for weights may be in >> fact >> identically equal to zero but just not simplified to zero - these cases >> would not be caught by such an analysis. >> >> OTOH, it is hard to make a formal (not based on syntax) distinction >> between >> zero and some very small weight close to zero (which may be expressed not >> necessarily with machine precision). This of course depends on the >> implementation of the underlying algorithm used to do the sampling - >> whether >> or not it treats weights smaller than machine epsilon as zero. From the >> point of view of the abstract interface of RandomSample, there is no >> reason >> why it should do that, even if such events are highly unlikely to be >> sampled. >> >> Generally, what you ask for should be possible once you give a specific >> interpretation of what you mean by zero, but arguably this would add more >> ambiguities/restrictions than it is worth for a kind of a general-purpose >> function that RandomSample is. After all, you can always wrap RandomSample >> in your own wrapper function which will implement this functionality in >> the >> way you want it (consistent with your definition of zero), while >> preserving >> the syntax of the original RandomSample. >> >> Regards, >> Leonid >> >> >> >> >> >> On Tue, Dec 29, 2009 at 9:17 AM, Matthias Greiff <greiff at mac.com> wrote: >> >> If I use RandomChoice with weights of zero the corresponding elements >>> will >>> never be selected. >>> >>> In[62]:= RandomChoice[{0, 0, 3} -> {3, 2, 1}, 5] >>> Out[62]= {1, 1, 1, 1, 1} >>> >>> Why is it not the same if I use RandomSample? >>> The following command >>> >>> RandomSample[{1, 2, 0} -> Range[3], 2] >>> >>> returns either {1,2} or {2,1}. But when I change the command to sample >>> size >>> 3 I get the following. >>> >>> In[60]:= RandomSample[{1, 2, 0} -> Range[3], 3] >>> Out[60]= {2, 1, 3} >>> >>> Why is the third element selected? Shouldn't Mathematica return an error >>> message because the sample size is larger than the population size? >>> >>> Appreciate your answers. >>> >>> Merry Christmas! >>> >>> Matthias >>> >>> >>> > > -- > DrMajorBob at yahoo.com >
- References:
- bug in RandomChoice if weight is zero?
- From: Matthias Greiff <greiff@mac.com>
- bug in RandomChoice if weight is zero?