# Tag Info

21

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 ...

18

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 = ...

18

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 ...

18

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] ...

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

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 ...

14

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

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 ...

13

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 ...

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

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 ...

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 ...

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 := ...

11

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 *)

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

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.]] &, ...

9

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 ...

9

Here is my entry - thanks to Andy for centering... n = 25; data = Cases[ IntegerPart[ RandomVariate[MultinormalDistribution[{0, 0}, {{1, 0}, {0, 1}}], 2000]*13], {_?(-n <= # <= n &), _?(-n <= # <= n &)}]; Graphics[{ {White, Line[{{-n, -n}, {n, -n}, {n, n}, {-n, n}, {-n, -n}}]}, {RGBColor @@ RandomReal[{0, 1}, {3}], ...

9

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 ...

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 ...

8

You were talking about a square with 100 smaller squares, so you must be thinking of a 10x10 grid. mat = ConstantArray[0, {10, 10}]; Here a bi-bormal distribution which is truncated at the boundaries of the square: d = TruncatedDistribution[{{1, 10}, {1, 10}}, BinormalDistribution[{5.5, 5.5}, {2, 2}, 0] ]; Drawing a few samples from this ...

8

Here is something to get you started. data = RandomVariate[ d = MultinormalDistribution[{0, 0}, {{2, 0}, {0, 2}}], 1000]; hl = HistogramList[data, {0.15}]; ArrayPlot[Sign[hl[[2]]]] The trick is to get the right number of bins as the second argument of HistogramList and to have just the right number of points in data. Too many, and the whole area is ...

8

Since you get the result in terms of Piecewise, you can use things like Refine or Simplify, particularly when you want to get a result given some additional condition on your variables. In particular, Refine[PDF[LogNormalDistribution[1.75, 0.65], x], x > 0] (* ==> (0.613757 E^(-1.18343 (-1.75+Log[x])^2))/x *)

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., ...

8

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] ...

8

It is desired to find all collections $P = \{A_1, A_2, \ldots, A_m\}$ of $m$ disjoint $k$-subsets of a finite set $X$. Such collections consist of two types: those which include a specified element of $X$ (say $a$) and those that do not. If $a \in A_j$ for some $j$ then we might as well reindex the elements of $P$ so that $j=1$. All possibilities for ...

8

If $X\sim N\left(\mu ,\sigma ^2\right)$ and $Y=e^X$, then $Y\sim \text{Lognormal}(\mu ,\sigma )$. So, by selecting LogNormalDistribution[10, 10], you are effectively generating values from a $N(10, 100$) distribution (which is a very large variance), and then raising them to $e^X$ ... which will generate deliciously large variates. To see this: Here are 6 ...

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