# Tag Info

12

Good news! Version 10.2 of Mathematica has this built-in with the function RandomPoint[]. From the documentation: RandomPoint can generate random points for any RegionQ region that is also ConstantRegionQ. RandomPoint will generate points uniformly in the region reg. The first example given is a simple disk, but there are a whole host of ...

11

To be able to answer this question, we need to agree what "random" means precisely. To me, the most reasonable interpretation is to require a uniform distribution on the $\sum_i x_i = a$ simplex. This will be satisfied by Praan's solution once we filter tuples containing negative numbers. Let's illustrate using $a=1$ and $n=3$. Praan's method: pts = ...

11

The trick is to place some random non-overlapping Disks in your square area, then use the DistanceTransform to find a point in your square area that is the farthest from its nearest disk. (Such a point will be equidistant from at least two disks--generally three or more disks.) Place a new disk centered at this point, with its radius equal to the distance ...

8

The immediate improvement you wanted was the following, but of course it uses large amounts of memory: NN = 10^9; Total@Table[Length[Split[ Sort[RandomSample[Range[12], 7], Less], #1 - #2 == -1 &]], {i, 1, NN}] // AbsoluteTiming That is, using Table and Total (but it consumes all the memory of my 16GB RAM machine). However, there are only 792 ...

6

Body of Manipulate is wrapped by Dynamic and Dynamic doesn't know what's inside inner Dynamics, that's how we can screen a variable to not prompt the very outer Dynamic to evaluate: Manipulate[ e = RandomVariate[NormalDistribution[0, sigma], n]; {Dynamic@a, e}, {{n, 3}, 1, 5, 1, Appearance -> "Labeled"}, {{sigma, 1}, 1, 2, Appearance -> ...

5

There appears to be a bug in RandomPoint, as can be seen by plotting both region1 and region2, the latter defined by region2 = ImplicitRegion[6 <= x - y + 2*z <= 7, {{x, -5*Pi, 5*Pi}, {y, -5*Pi, 5*Pi}, {z, -10, 10}}]; Then pts2 = RandomPoint[region2, 10^4]; ListPointPlot3D[{pts2, pts1}, AxesLabel -> {"x", "y", "z"}, BoxRatios -> {1, 1, ...

4

As per comments, this should fit the bill: dist = EmpiricalDistribution[ PDF[TransformedDistribution[ x + y, {x \[Distributed] DiscreteUniformDistribution[{1, 6}], y \[Distributed] DiscreteUniformDistribution[{1, 6}]}], Range[1, 12]] -> {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5}]; {Mean[dist], Quantile[dist, .5], RandomVariate[dist, 5]} ...

3

Generate $n-1$ random numbers first. Then the $n$th number is given by $a$ minus the sum of the $n-1$ randomly generated numbers. Your code could look like this, for example, rTable = RandomReal[{rmin, rmax}, n-1] AppendTo[rTable, a-Total@rTable] a == Total@rTable Edit As pointed out by Szabolcs in the comments of this answer, this method fails when the ...

3

Exploiting @ciao efficient way of counting the length of splits ( I have upvoted his answer) allows exact calculation of expectation of split length for this setup. The 792 (Binomial[12,7]) cases make it tractable. tally = Tally[ 6 - ((Tr@Unitize@Subtract[Differences@#, 1]) & /@ Subsets[Range[12], {7}])]; tot = Total@tally[[All, 2]]; prob = ...

2

This is my attempt at Probabilistic Bisection Algorithm, as described in the thesis linked by @Szabolcs in the comments. ClearAll[pbaFindRoot]; Module[{initialDistribution, modifyDistribution, outputDistribution, bernoulliTestPowerOneFilter}, initialDistribution[rangemin_, rangemax_] := N@{(rangemin + rangemax)/ 2, {{{0, rangemin}, ...

2

This is a hack to create a function which interoperates at least on some level with FindRoot. Still, it's very much only a starting point. Primary goal of regularize is to attempt keeping values below and above sought root not jumping on the other side. ClearAll@regularize; regularize[f_Function, rootval_, minsigmas_, minsamples_Integer, ...

2

Since you changed the question completely and rendered every answer posted and the effort involved moot, here's a method to compute the exact PMF and Mean for your new formulation with nearly nil memory requirements. Since you've not responded to requests by me and others to clarify precisely what it is you're after, I don't plan on spending any time ...

1

This issue has been fixed as of version 10.2.0. NIntegrate[1, x ∈ ImplicitRegion[(x > 5 && x < 9) || (x > 11 && x < 13), {x}], Method -> "MonteCarlo"] (* 6.06192 *) The syntax is fine, since x is taken to be a vector variable, similarly to NIntegrate[1, x ∈ Ball[]]

Only top voted, non community-wiki answers of a minimum length are eligible