/Spatial-Poisson-Process-Demo

A demonstration of a Poisson point process.

Primary LanguageTypeScriptApache License 2.0Apache-2.0

Spatial-Poisson-Process-Demo

Spatial Poisson Process visual for this wikipedia article: https://en.wikipedia.org/wiki/Poisson_point_process

Overview

Draws random unit squares (area = 1), in a region with area A. Then draws N random points all at once. Records how many points land in each unit square. Does this many times. Then plots how many times 0 points landed in square (how many squares are empty), how many squares contain exactly 1 point, 2 points, etc. Then plots this against the Poisson expected distribution.

How to use:

Install Typescript transpiler (if not already installed. Can check for installation with tsc --version):

sudo npm install -g typescript

Install Plotly (if not already installed). These installation commands were described in this stackoverflow post.

npm install plotly.js-dist --save
npm install @types/plotly.js --save-dev
npm install @types/d3 --save-dev

Transpile the typescript file to create the javascript file:

tsc demo1.ts

TODO:

  • Fix the exports not defined error, to ensure that the project is set up correctly, and the javascript does not give an "exports is not defined" error at runtime. Learn to use browserify.
  • Add plot for the number of squares hit by 1 point, 2 points, 3, etc. Figure out how to use plotly in typescript to do ths.
  • Add html sliders for number of points, number of squares, and the size of squares (as a percentage of size of canvas).
  • Add text on simulation indicating probability that a single point will hit a square.
  • Add this page to personal website.
  • Upload a gif to wikipedia.
  • Add a screenshot of the page to the "overview" section of the README, to appear on github.
  • Tell friends.
  • Add the equation used to calculate the expectation in the plot.
  • Add explanation of the Wikipedia page and edit. Link to the Wikipedia page and the source code in GitHub.

Potential future related projects:

  • Make a demo that does the same thing, but draw the points first, and then randomly place the squares.
  • Unit test the demo. Replace "TestSpatialPoissonProcess" in the package.json file with whatever command should be used to run the tests when "npm test" is called. Figure out if gts has a recommended style of testing.
  • Consider making a 1 dimensional version where raindrops vertically fall into buckets in a row, and the buckets fill up over time, and the histogram of the amount of drops collected is plotted.
  • If the performance is not good, consider using webassembly or gpu to speed up the process of generating squares without collisions (which is an O(n^2) algorithm for n squares) and checking whether points are inside squares (also approximately O(n*m) for n squares and m points).

Useful links: