0

Simple question : how does one simulate a Poisson distribution ?

And preferably, in a way compatible with the use of tikz (the goal is to automatically plot a random number of points in a given area).

EDIT : A way to tackle this problem is to sample independant explonential variables X_i, i>0 and have as a result of the simulation the index N at wich the sum X_1+...+X_N exceeds 1 (or any given threshold).

But I lack experience so I don't know how to code that. Simulating an exponential variable is no problem but i don't see how to have LaTeX run the procedure.

EDIT2 :

-ln(rand)

More precisely, this command is enough to simulate an exponential variable of parameter 1.

  • Welcome. // Have a look at R, which e.g. generates random numbers also with that distribution. – MS-SPO Nov 30 '23 at 15:15
  • Of course with R or any statistics oriented language, there is absolutely no problem. But i would prefer not to run myself the simulation and then fill in the blanks. The goal is to have LaTeX directly sample it. – 20-sided-dice Nov 30 '23 at 15:20
  • 2
    why exactly poisson distrib? the tex engines provide uniformly distributed random integers with \pdfuniformdeviate or normal distrbution via \pdfnormaldeviate providing anything else would require coding the arithmetic to derive it from one of those, or coding a whole random number generator in tex macros. For most random plots just using the former to generate random coordinates in a given range is enough – David Carlisle Nov 30 '23 at 15:50
  • Specifically Poisson distribution because this is what I need (more precisely, i would like to illustrate a Poisson point process, but this does not matter). But my question would be the same for a binomial or geometric. – 20-sided-dice Nov 30 '23 at 15:51
  • 1
    OK I think the most reasonable way is going to be to generate the sample points with R or python or whatever and then just read the table of points in latex to do the plot, tex isn't really optimised for doing that kind of arithmetic (even if theoretically it's possible) – David Carlisle Nov 30 '23 at 15:59
  • Maybe https://tex.stackexchange.com/questions/185419/poisson-disc-sampling-implemented-in-luatex could give some inspiration – samcarter_is_at_topanswers.xyz Nov 30 '23 at 16:02
  • 1
    I’m voting to close this question because in my view this is reinventing the wheel with a tool (Tikz) which doesn't make the required operations easy ... so I suggest to close this question, as it also lacks focus on Latex. – MS-SPO Nov 30 '23 at 16:18

1 Answers1

1

run with lualatex

\DocumentMetadata{}
\documentclass{article}
\usepackage{pst-func}
\begin{document}

\psset{xunit=1cm,yunit=20cm}% \begin{pspicture}(-1,-0.05)(14,0.25) \psPoisson[linecolor=red,markZeros,fillstyle=solid, fillcolor=blue!10,printValue,valuewidth=20]{13}{6} % N lambda \psaxes[Dy=0.1,dy=0.1\psyunit]{->}(0,0)(-1,0)(14,0.2)[$k$,-90][$P(X=k)$,90] \end{pspicture}

\psset{xunit=1cm,yunit=20cm} \begin{pspicture}(-1,-0.05)(14,0.25) \psPoisson[linecolor=blue,markZeros,fillstyle=solid,barwidth=0.4, fillcolor=blue!10,printValue,valuewidth=20]{10}{6} % N lambda \psaxes[Dy=0.1,dy=0.1\psyunit]{->}(0,0)(-1,0)(11,0.2)[$k$,-90][$P(X=k)$,90] \end{pspicture} \end{document}

enter image description here

user187802
  • 16,850
  • I think you did not get what I asked for. I want LaTeX to give me a random number, not the respective probabilities to pick any integer. Or I missed the point of your answer. – 20-sided-dice Nov 30 '23 at 15:57