Tag Info

New answers tagged

1

This will give exact answer: setp[eggs_, pPerEgg_, setSize_, wanted_] := With[{r = Range[1, wanted]}, 1 - Tr[Binomial[wanted, r]*(1 - r*pPerEgg/setSize)^eggs*(-1)^(r - 1)]]; Example: 500 eggs collected, 1/10 chance of egg having item, 50 items available, you want 20 particular: setp[500, 1/10, 50, 20] For huge arguments, you can use inexact ...


1

Just for curiosity, this is another way using higher level built-in "stats" functions : Given for example your data: xw = {{x1, w1}, {x2, w2}, {x3, w3}}; the corresponding probability distribution is: myDist = EmpiricalDistribution[xw[[All, 2]] -> xw[[All, 1]]]; then you can compute Expectation[hello, Distributed[hello, myDist]] which is ...


5

Using symbolic values and descriptive names for clarity. Unless the sum of the weights is unity you will have to rescale the weights to get the expected value. n = 4; data = Array[{x[#1], y[#1]} &, n]; {values, weights} = data // Transpose; expValue = values.weights/Total[weights] Equivalently, expValue == Total[Times @@@ data]/Total[weights] ...


2

If you are just learning about expected value (as I seem to be), the following may seem like a natural way to obtain it. However, as Bob Hanlon notes, it assumes that the weights are positive integers. This is imposed by Constant Array[a, b], which gives b copies of a. Mean[Flatten[ConstantArray @@@ {{1, 2}, {3, 4}, {5, 6}, {7, 8}}]] 5 ConstantArray ...


5

Suppose your list is as follows m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}} Dot @@ Transpose[m]/Total[m[[All, 2]]] (* 5 *)


5

An exact symbolic solution can be obtained in the case when $\mu=0$, with arbitrary $\sigma$. We then have two independent $N(0,\sigma^2)$ random variables, each with pdf $f(x)$: The pdf of the product of two Normals can then be derived exactly as: ... where I am using the TransformProduct function from the mathStatica package for Mathematica. Here is ...


4

RandomVariate for BinomialDistribution[n,p] changes between methods depending on the value of Min[n*{p,1-p}]. What we're seeing here is that one of those methods is poorly optimized. Because of this thread, we've made some improvements which should improve speed when Min[n*{p,1-p}]<10. These will be in the next release of Mathematica. We'll also ...


8

Let $Z_1$ and $Z_2$ be independent Gaussian random variables with unit mean and unit standard deviation. Let $W = Z_1 Z_2$. Clearly $$\begin{eqnarray} F_W\left(w\right) &=& \Pr\left(W \leqslant w\right) = \Pr\left(Z_1 Z_2 \leqslant w\right) \\ &=& \mathbb{E}\left(\Pr\left(Z_1 Z_2 \leqslant w \mid Z_2\right) \right) \\ &=& ...


3

You can actually do the integral in closed form: f[z_] = Integrate[Exp[-x^2/2] Exp[-y^2/2] DiracDelta[x y - z]/(4 Pi), {x, -Infinity, Infinity}, {y, -Infinity, Infinity}, Assumptions -> z ∈ Reals] and then Plot Plot[f[z], {z, -2, 2}, PlotRange -> All] To change the variances: f[z_] = Integrate[Exp[-x^2/(2 sigX^2)] Exp[-y^2/(2 sigY^2)] ...


6

The problem arises due to PiecewiseExpand operating inside TransformedDistribution, similarly to the following pw = PiecewiseExpand[f[Max[x, y], z]] (* Piecewise[{{f[x, z], x - y >= 0}}, f[y, z]] *) however this kind of transformation is not appropriate when f is TransformedDistribution pw /. {f -> TransformedDistribution, z -> {x ...


2

You may try with this list of rules, in this order since your transformations are overlapping: rules = { Power[Subscript[X_,Subscript[a_,j_]], n_] :> Power[Subscript[\[Sigma],Subscript[a,j]], n]+ Power[Subscript[\[Mu],Subscript[a,j]], n], Times[rest1___, Subscript[X_,Subscript[a_,j_]], ...


5

Increase WorkingPrecision: NSolve[PDF[BinomialDistribution[80, p], 0] == 0.95`200 && 0 < p < 1, p, Reals, WorkingPrecision -> 50] PDF[BinomialDistribution[80, p], 0] /. % (* {{p -> 0.00064096067673218860969986162632491931947341012861}} {0.9500000000000000000000000000000000000000000000000} *)


5

I get on Mathematica 10.2, Ubuntu 14.04 In[10]:= Map[{First[ Timing[Do[ RandomVariate[BinomialDistribution[10 #, 1/#]], {100}]]], First[Timing[ Do[RandomVariate[ BinomialDistribution[10 #, 1/(# + 1)]], {100}]]]} &, {1500, 3000, 5000, 10000}] Out[10]= {{0.023484, 2.37428}, {0.012502, 6.22335}, {0.013843, 12.4218}, ...


5

Please edit with your results: MMa 10.0.0.0, Windows 8.1 – Sektor {0.015625, 0.03125}, {0.`, 0.0625}, {0.`, 0.125}, {0.`, 0.`}} MMa 10.0.0.0 through MinGW & mintty, Windows 8.1 – Sektor {0., 0.03125}, {0., 0.0625}, {0., 0.125}, {0., 0.}} MMA 10.2, Ubuntu 12.04 - blochwave {0.03, 0.1, ...


1

The weghts do not have to be equal or even numerical. $Version (* "10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)" *) Format[p[x_, y_]] := Subscript[p, Row[{x, y}]] assume = {Thread[0 <= {p[0, 0], p[0, 1], p[1, 0], p[1, 1]} <= 1], p[0, 0] + p[0, 1] + p[1, 0] + p[1, 1] == 1} // Flatten; gmultdist = EmpiricalDistribution[{p[0, 0], p[0, 1], ...


2

I'd subsequently realized that I could simply just do gmultdist = EmpiricalDistribution[ {0.25, 0.25, 0.25, 0.25} -> { {0, 0}, {0, 1}, {1, 0}, {1, 1} } ] for the case of all equal weights. My original mistake was in "flipping" the order of -> initially in EmpiricalDistribution.


2

Just building on @ciao (@rasher) to deal with second part: c66 = TransformedDistribution[ a + b, {a, b} \[Distributed] DiscreteUniformDistribution[{{1, 6}, {1, 6}}]]; p66 = Probability[x == 11, x \[Distributed] c66]; c620 = TransformedDistribution[ a + b, {a, b} \[Distributed] DiscreteUniformDistribution[{{1, 6}, {1, 20}}]]; p620 = ...


4

While the unknown g might or might not be amenable to this approach, it's really fast on g == 1: Expectation[ 1, {x1, x2, x3, x4} \[Distributed] MultinormalDistribution[muvec, sigmat]] // RepeatedTiming (23000 times faster than NIntegrate.) Then there's also NExpectation to try, too. Ever since I came across Guess who it is's use of the ...


3

Because the integrand is highly localized at the origin; e.g., Log[10, npdf[{6, 0, 0, 0}]] // N (* -9.16177 *) limiting the range of integration reduces run time by a factor of three and moderately improves accuracy. muvec = ConstantArray[1/10, 4]; sigmat = IdentityMatrix[4]; npdf[x_] := PDF[MultinormalDistribution[muvec, sigmat], x]; ...


1

About 30X faster integration, no errors... Clear[x, x1, x2, x3, x4] muvec = ConstantArray[1/10, 4]; sigmat = IdentityMatrix[4]; pdf = PDF[MultinormalDistribution[muvec, sigmat], {x1, x2, x3, x4}] // FullSimplify Integrate[ 1*pdf, {x1, -Infinity, Infinity}, {x2, -Infinity, Infinity}, {x3, -Infinity, Infinity}, {x4, -Infinity, Infinity}] // ...


4

Here's a start for you. p is probability of choosing die 1, f1/f2 are number of faces (starting at 1) for die 1/2: p1 = 3/10 f1 = 6 f2 = 20 d = MixtureDistribution[{p1, 1 - p1}, {DiscreteUniformDistribution[{1, f1}], DiscreteUniformDistribution[{1, f2}]}]; d2 = TransformedDistribution[a + b, {a, b} \[Distributed] ...


2

The bin-sizes (which is what you interval sizes) can be specified directly in Histogram: Histogram[RandomReal[-30, 40], {5}] Btw, it's funny when you say random numbers from RandomReal[-30,30] (where the size of the list is 40) and you just specified to get a list with 30 random numbers :-) Edit: Ahh, and now I see why you said it. When you want ...


3

One obvious answer is to use the answer to your related earlier question with the straightforward modification of renaming the random variables: Clear[expect] expect[expr_Plus] := Map[expect, expr] expect[Times[x_, y__]] /; (FreeQ[x, x1 | x2 | x3 | x4]) := x expect[Times[y]] expect[Times[x_expect, y__]] := x expect[Times[y]] expect[expr_?(FreeQ[#, x1 ...


2

(Just an extension of belisarius' excellent answer which I have upvoted.) The physically meaningful approach to the determination of FWHM requires working with actual physical intensity values, not gamma-corrected and artificially deformed intensity values which one gets with the usual photographic cameras generating images in the sRGB colorspace. If it is ...


4

Here is one way of defining the linearity of your expectation value. Updated in response to comments To allow for powers as they arise in the definition of the variance, I just added rules that expand such powers when possible (it is only possible when there is a sum under the power, that's why I restrict the pattern expect[Power[expr_Plus, n_]] to ...


1

I just needed to do ClearAll[dist] first, as mfvonh pointed out in the comments.


9

If you don't care about the algorithm and only want to sample points with density according to image brightness, you could just use RandomChoice: using a test image that looks a little bit like a PDF: img = Image[ Rescale[Array[ Sin[#1^2]*Cos[#2 + Sin[#1/5]] + Exp[-(#1^2 + #2^2)/2] &, {512, 512}, {{-2., 4.}, {-3., 3.}}]]]; I can then ...


9

f[m_] = 1/(2*E^((-m + Log[5])^2/8)*Sqrt[2*Pi]); Integrate[f[m], {m, -Infinity, Infinity}] 1 dist = ProbabilityDistribution[f[m], {m, -Infinity, Infinity}]; Since the integral of f[m] is unity, f[m] does not have to be scaled to be a distribution. A candidate distribution will probably have two parameters and must be defined on the interval ...


12

UPDATE: quite interesting parallel discussion and solutions (see Emerson Willard answer) can be found HERE. Maybe this is not exactly what you are looking for, but at least this gives you a very close guess and it is easy to figure out the rest. dis = ProbabilityDistribution[ 1/(2*E^((-m + Log[5])^2/8)*Sqrt[2*Pi]), {m, -Infinity, Infinity}]; PDF[dis, ...


1

It does appear something might have been tinkered with, or my recollection / documentation is in error. InverseFourierSequenceTransform[cf, t, -n, FourierParameters -> {1, 1}, Assumptions -> 0 < p < 1] // PiecewiseExpand properly recovers the PDF (PMF) for the GeometricDistribution case.


1

Just another way to calculate volume of hypersphere and then relevant probability using recursion: vs[n_] := Most@Nest[{#[[2]]/(#[[3]] + 1), 2 Pi #[[1]], #[[3]] + 1} &, {1, 2, 0}, n] v[n_] := vs[n][[1]] The probabilities: Grid[Prepend[{#1, #2, N@#2} & @@@ ({#, v[#]/2^#} & /@ Range[10]), Style[#, Bold] & /@ {"n", ...


4

As noted in the comment by WRI staff, this is indeed a bug in the interplay between RandomVariate and the distribution at hand. The obvious workaround for now is to use UniformDistribution[{μ - Pi, μ + Pi}] for zero-concentration cases.


7

To me this looks like a bug. A possible workaround is to use ProbabilityDistribution together with the PDF of the VonMisesDistribution: SeedRandom[1] RandomVariate@ProbabilityDistribution[PDF[VonMisesDistribution[0, 0], x], {x, -∞, ∞}] $\ $ 1.99422 This bug is caused by the evaluation of Statistics`NormalDistributionsDump`compiledvonmisesrandom[0, 0, ...



Top 50 recent answers are included