# Tag Info

29

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

22

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

20

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

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

17

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

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

16

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

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

14

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

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

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

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

13

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 ... 13 Introduction as of 31 January 2015 This is a very interesting problem which on trying to solve it with Mathematica requires skilled handling in an interactive way ("man-machine-interaction"). What do you do when Mathematica refuses to solve an integral? How to help solving integrals which Mathematica declares (erroneously) as divergent. I have done an ... 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 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_}] := # ... 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 Starting with a corrected version of your ProbabilityDistribution f[a_, b_, g_, c_, k_] := ProbabilityDistribution[ a b c k x^(c - 1) (1 + x^c)^(k - 1) ((1 + x^c)^k - 1)^(-b - 1) (1 + g ((1 + x^c)^k - 1)^-b)^(-(a/g) - 1), {x, 0, Infinity}, Assumptions -> a > 0 && b > 0 && g > 0 && c > 0 && k > ... 11 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 ... 11 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., ... 11 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] ... 11 $$\mathbb{P} \big(\sum_{i=1}^{m} (A_i + S_i) \le L < \sum_{i=1}^{m+1} (A_i + S_i) \big) = \frac{\mu ^m (2 \lambda +\mu )}{2^{m+1} (\lambda +\mu )^{m+1}}$$ Observing: d1 = TransformedDistribution[ a + s, {a \[Distributed] ExponentialDistribution[λ], s \[Distributed] ExponentialDistribution[μ]}] (* ... 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 As I use this a lot in my own research, let me answer your question by generalizing it to possibly larger dimensions and with a possibly correlated joint probability. Let me define the following function ConditionalMultinormalDistribution::usage ="ConditionalMultinormalDistribution[pdf,val,idx] returns the conditional MultiNormal PDF from the joint PDF ... 10 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 ... 10 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 ...

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