3
$\begingroup$

I'm computing the max over a set of uniformly distributed random variables. I know that this value converges to 1 as the number of variables increases. Mathematica is having difficulty computing the approximation for larger values of n:

ListPlot[
 Table[NExpectation[Max @@ Table[x[i], {i, 1, n}], 
   Table[x[i] \[Distributed] UniformDistribution[], {i, 1, n}]], {n, 
   1, 10}]]

Notice that the approximation is near 0 for one of the points, and I get several warnings:

enter image description here

Why is this happening? Is it possible to fix?

It looks like it could be related to the option MaxPiecewiseCases, but I can't seem to specify that from the call to NExpectation.

$\endgroup$

2 Answers 2

5
$\begingroup$

Using OrderDistribution makes it easy:

Mean[OrderDistribution[{UniformDistribution[{0, 1}], n}, n]]
(* n/(1 + n) *)
$\endgroup$
4
$\begingroup$
Clear["Global`*"]

$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

Use the Mean of the TransformedDistribution

data = Table[
  Mean[
   TransformedDistribution[Max @@ Table[x[i], {i, 1, n}],
    Table[x[i] \[Distributed] UniformDistribution[], {i, 1, n}]]],
  {n, 1, 10}]

(* {1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, 9/10, 10/11} *)

ListPlot[data]

enter image description here

For arbitrary n

mean[n_] = FindSequenceFunction[data, n]

(* n/(1 + n) *)

EDIT: Using NExpectation

data2 = Table[
  NExpectation[Max @@ Table[x[i], {i, 1, n}],
   Table[x[i] \[Distributed] UniformDistribution[], {i, 1, n}],
   WorkingPrecision -> 15,
   Method -> {"MonteCarlo", "SamplingIncrement" -> 10^6}],
  {n, 1, 10}]

(* {0.499634476170700, 0.666505623364029, 0.751636048372117, \
0.798185580996715, 0.834673695845299, 0.858042194869023, \
0.872491243043538, 0.885804474685710, 0.898368121403151, \
0.912293708632319} *)

ListPlot[data2]

enter image description here

$\endgroup$
1
  • $\begingroup$ Any idea why this works but my example doesnt? It seems like they should be implemented the same way. $\endgroup$
    – dmh
    Commented Nov 19, 2021 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.