# Tag Info

24

Mathematica v8 does not provide support for automated random number generation from multivariate distributions, specified in terms of its probability density functions, as you have already discovered it. At the Wolfram Technology conference 2011, I gave a presentation "Create Your Own Distribution", where the issue of sampling from custom distribution is ...

21

This is not an efficient answer but it is fun to play with so I thought I'd post it. For efficiency the use of Nearest might provide a good starting point. g[n_, {low_, high_}, minDist_, step_: 1] := Block[{data = RandomReal[{low, high}, {n, 2}], temp, happy, sdata, hdata}, While[True, temp = ((Nearest[data][#, 2][[-1]] & /@ data)); happy ...

19

Instead of the exponential distribution, consider its truncation $\mathcal{E}_\epsilon(1)$ to $(\epsilon, \infty)$. The expectation can then be found, but it diverges as $\epsilon \downarrow 0$. Indeed, writing the expectation as integral: $$\int_0^\infty \frac{1}{x} \mathrm{e}^{-x} \mathrm{d} x$$ you see that the integral diverges at the lower ...

19

It is possible to do the calculation analytically in Mathematica as well. Here's one way to define the desired distribution: maxDist = TransformedDistribution[Max[x, y], {x \[Distributed] DiscreteUniformDistribution[{1, 6}], y \[Distributed] DiscreteUniformDistribution[{1, 6}]}]; Then the mean is calculated Mean[maxDist] ...

17

This reproduces the image decently. It works by sampling without replacement from all the positions, and randomly coloring them with a built-in color scheme. size = 41; amountCovered = 0.40; noSquares = Floor[amountCovered*size^2]; tiles = Flatten[Table[{i, j}, {i, size}, {j, size}], 1]; probabilities = Flatten@GaussianMatrix[Floor[size/2]]; sample = ...

15

Copying my clock post? Impossible! Anyway, Chapter one: using brute force. Before you complain: I'm a physicist, this is how we do mathematics: by experiment. Ha! We need cards! Inconveniently, Mathematica currently lacks built-in support for Kings. We therefore have to use a workaround: let's call the named cards by their numbers. A is 1, J is 11 etc. ...

14

There are basically four ways you can do this: Discretely, using EmpiricalDistribution, as you suggest in your question Also discretely, but in a bucketed way, using HistogramDistribution Smoothly, using SmoothKernelDistribution or KernelMixtureDistribution. By fitting an assumed distribution, e.g. by using EstimatedDistribution, FindDistributionParameters ...

14

If you don't need high precision, you can do something along these lines: canvas = Image@ConstantArray[0, {100, 100}]; distance = 6; {img, {pts}} = Reap[Nest[ ImageCompose[#, SetAlphaChannel[#, #] &@Image@DiskMatrix[distance], Sow@RandomChoice@ Position[Transpose@ImageData[#, DataReversed -> True], 0.]] &, ...

14

To make this plot, you first need to know about PDF, which gives the probability distribution functions for various distributions. Your distributions are NormalDistribution and LogNormalDistribution, which isn't too hard to figure out. To make the normal plot, you can just use Plot. Since the log-normal is vertical, you need something else; ParametricPlot ...

14

I think you are mixing up the "coordinate" of the breaking point with the length of the resulting stick segment. The length of the resulting stick segment is y-x, (if y>x) not y. If we want x and y to be uniformly distributed, it is is useful to think in terms of the length of the leftmost stick segment l1=Min[x,y] and the length of the center stick segment ...

13

One way to create an image similar to the one you have is with ArrayPlot. The trick to "gaussianly sample" is to simply sample from a bivariate normal distribution and rescale the coordinates so they can be used for array rules in a SparseArray. Here I use Tally to effectively bin the data on the grid. Note that the color function can be changed to ...

13

The integrable singularity of the PDF at the origin is not gracefully dealt with by the underlying solvers. Presently one can work around the issue by exploiting the symmetry of the PDF: Through[{Min, Max}[ sample = RandomVariate[ TransformedDistribution[(-1)^x y, {x \[Distributed] BernoulliDistribution[1/2], y \[Distributed] ...

13

This is not an answer (yet). Rather it explores the question in more depth. n = 8; parameters = ConstantArray[{0, 1}, n]; variables = Symbol /@ CharacterRange["a", FromCharacterCode[ToCharacterCode["a"] + n - 1]]; The following takes a long time to evaluate, but the results it produces reveal give us a better view of the problem with Probability. ...

12

One hack-ish method for evaluating an inverse CDF is to use the event location functionality of NDSolve[]. As an example: dist = HyperbolicDistribution[2, 3/2, 1, 0]; c0 = N[CDF[dist, 0], 20] 0.058032099055437685722 Suppose that we want to evaluate the inverse CDF for this particular hyperbolic distribution at the $p$-value $7\times10^{-6}$. Since this ...

12

This is a perfect place to try out TransformedDistribution. dist = TransformedDistribution[(1 - x)/x, x \[Distributed] BetaDistribution[alpha, beta]]; Variance[dist] ==> (beta (-1 + alpha + beta))/((-2 + alpha) (-1 + alpha)^2) Edit: Based on the comments it is worth pointing out that TransformedDistribution rarely auto-evaluates to a known ...

12

Experience working with distributions suggests analyzing the logarithm of the density function, rather than the density itself. Because the log is a monotonic increasing transformation, the mode of the log density occurs at the same value as the mode of the density. (This approach has general application, not just for beta distributions.) Let's develop ...

12

You could create the TransformedDistribution described by bill s or you could use Mathematica's built in OrderDistribution command, which addresses precisely the sort of problem you have posed. Mean[OrderDistribution[{DiscreteUniformDistribution[{1, 6}], 2}, 2]]//N (* 4.47222 *)

12

The printed version of the 2002 edition was printed 3 times and sold out 3 times; Springer and Google recently started selling it (book only) as a PDF eBook (no software) on the Springer and Google sites for $79. I know other authors (e.g. here) have gone to some trouble to make their books available here on stack exchange ... We are delighted to be able ... 11 Ok, I'll stick to "making MMA do the thinking" The list of all the possibile hands a player can have playerPossibilities = Tuples[Range[13], {2}]; The list of all the triplets of hands the 3 players could have been handed allPossibilities = Tuples[playerPossibilities, {3}]; A function that returns True if a1 won a1winsQ[{h1 : {_, _}, h2_, h3_}] := # ... 11 Estimating probabilities via proportions in simulation outcomes is conveniently done by averaging indicators. An "indicator" equals$1$when an event happens and$0$when it does not: the average of a list of such values is, mathematically, the proportion of$1$'s in the list. Your work can be expressed as birthdays[x_Integer] /; x >= 1 := ... 10 This isn't perhaps exactly what you are looking for but here are some points worth noting. In version 8 NExpectation uses numerical integration and summation methods whereas N[Expectation[...]] uses direct integration or summation and then approximates numerically after the fact. Though the idea is for data-distributions in M to behave just like regular ... 10 Well, a very simple but very limited way could be to generate a random set of points, calculate all distances between them and scale the minimum distance to mindist: mindist = 1; npts = 200; pts = RandomReal[{0, 100}, {npts, 2}]; scaledpts = mindist/Min[Norm /@ Subtract @@@ Subsets[pts, {2}]]*pts; Graphics[{Green, Point[pts], Red, Point[scaledpts]}, Frame ... 10 For your amusement, here is a cute, Mathematica-oriented solution: represent the die by its probabilities and "teach" the software to combine results using the maximum. So, to begin, here's a way to create dice and an example of the usual six-sided fair die: Clear[x]; die[n_] = Sum[x[i]/n, {i, n}]; die[6] ... 9 Here is a way to separate your equation into different subparts. It uses Reap and Sow to tag parts of the expression as either "equation" or "conditions" or "constants". f = Which[FreeQ[#, x], Sow[#, "constants"], MemberQ[{Equal, Unequal, Greater, GreaterEqual, Less, LessEqual, And, Or}, Head[#]], Sow[#, "conditions"],True, Sow[#, ... 9 You can also use OrderDistribution (to get the joint distribution of Min and Max in a sample of size 2 from a standard Uniform distribution) combined with a simpler condition: dist = OrderDistribution[{UniformDistribution[], 2}, {1,2}]; Probability[y > 1/2 && 1/2 > y - x && 1/2 > x, Distributed[{x, y}, dist]] (* 1/4 *) ... 9 Each uniform divides the stick into a smaller and a longer side. If the smaller side of both uniforms coincide (left-left, or right-right) then you won't have a triangle because the rightmost/leftmost division will be longer than 0.5. The odds of this happening is 1/2. If they don't coincide, then you will have a triangle only when the sum of the smallest ... 9 Amazingly, the most direct and mindless possible approach works instantaneously. Start by characterizing the valid side lengths: each side is the shortest distance between its endpoints; the path made by the other two sides cannot be any shorter. triangleQ[x_, y_, z_] := x <= y + z && y <= z + x && z <= x + y; Break the stick ... 9 A pdf is only well-defined if it integrates to unity over the domain of support. You have set up the domain of support as (-400, 400). You would have to check what values of$a$and$b\$ (if any) are appropriate for that domain of support. But, more to the point, your domain of support is ill-defined for the parameter values you have provided: f = Cos[(b ...

8

The short answer is: I don't think it is built to always work for general distributions (though see Sjoerd C. de Vries's answer and continuous example below). You might also want to have a look at the nice tutorial how to Create Your Own Distribution with Oleksandr Pavlyk. Lets see what are your options Mixture For mixture distributions, following J. M., ...

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