1
$\begingroup$

I need to generate a large number of random variables from the distribution generated by the following code. Distribution is given by DistributionF. The code is getting stuck at the the execution of the command RandomVariate[DistributionF,1000]. It does not output the R.V.s. How can I resolve this issue.

A = 1/2; 
k = 1; τ = 1;
m = 1; β = .6931; σ = 1.8421;


W = {0.0000, 0.0013, 0.0339, 0.2401, 0.6109, 0.6109, 0.2401, 0.0339, 
   0.0013, 0.0000};

T = {3.4362, 2.5327, 1.7567, 1.0366, 
   0.3429, -0.3429, -1.0366, -1.7567, -2.5327, -3.4362};

G[t_] := Exp[-Exp[-Sqrt[2]*σ*t - β]*m*
     x^2]*(Exp[Sqrt[2]*σ*t + β])^(-m);

f[x_] = (1 - A)*
    FullSimplify[
     2*(1 + k)*x/τ*Exp[-k - (1 + k)*x^2/τ]*
      BesselJ[0, 2*Sqrt[k*(1 + k)/τ]*x]] + 
   A*(x^(2*m - 1)*2*m^m)/(Sqrt[π]*Gamma[m])*W.(G /@ T);

DistributionF = TransformedDistribution[x^2, 
   x \[Distributed] ProbabilityDistribution[f[x], {x, 0, Infinity}]];

RandomVariate[DistributionF,1000]
$\endgroup$
  • $\begingroup$ If f[x] is a PDF then NIntegrate[f[x], {x, 0, ∞}] should return 1 since you have defined {0, ∞} as the domain of f. However, it returns 0.567652. $\endgroup$ – Edmund Feb 8 '17 at 4:14
  • 2
    $\begingroup$ @Edmund - The Method option can handle this. ProbabilityDistribution[f[x], {x, 0, Infinity}, Method -> "Normalize"] $\endgroup$ – Bob Hanlon Feb 8 '17 at 4:18
  • $\begingroup$ @BobHanlon Nice! I did not notice that before. Still taking forever to evaluate for just 1 sample. $\endgroup$ – Edmund Feb 8 '17 at 4:22
  • $\begingroup$ Works for me, 10.x on Windows... $\endgroup$ – ciao Feb 8 '17 at 4:41
  • $\begingroup$ @ciao, I have been using 11.01 on Mac.. $\endgroup$ – George Harnandez Feb 8 '17 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.