Wolfram Computation Meets Knowledge

New in the Wolfram Language: RandomPoints

Picking random points on the surface of a sphere so that the points are uniformly distributed is not as straightforward as you might think. Naively picking random spherical coordinates ϕ and θ will not give a uniform distribution of points. The problem is important enough to warrant a dedicated article in encyclopedias, such as Wolfram MathWorld (see Sphere Point Picking). Uniform sampling from Sphere[] is now available in the Wolfram Language with the RandomPoint function:

RandomPoint on a Sphere

Finding if the point is on the sphere

In fact, RandomPoint can be used to uniformly sample from any bounded geometric region, in any dimension. In 2D:

Uniformly sample geometric region in 2D

In 3D:

Uniformly sample geometric region in 3D

In 10D:

In 10D

Use the 10D points to estimate the region centroid:

Using 10D points to estimate the region centroid

Compare to the numerical value of the exact coordinates:

Numerical value of exact centroid coordinates

RandomPoint aims to enable sampling from all the geometric regions supported in the Wolfram Language, including basic geometric regions, mesh regions, and formula and derived regions.

For example, you can use RandomPoint to mark uniformly distributed locations on a map of Africa:

MeshRegion representing the African continent

Uniformly sampled points over Africa

Random points can be used to approximate geometric quantities. For instance, to estimate the maximum distance between two points in a regular pentagon inscribed in the unit circle, find the maximum distance between 1,000 pairs of random points on the boundary of a pentagon:

Realizing the largest pairwise distance between uniform sample on the boundary of a pentagon

Or estimate the area of the symmetric difference using RegionSymmetricDistance (or any Boolean combination) of region sets:

Estimating the area of the symmetric difference using RegionSymmetricDistance

Visualize the point cloud:

Visualizing the point cloud

Build the Nearest function to quickly test if a point is within a given distance r from the point cloud:

Build the Nearest function to test if a point is within a given distance

Use the Monte Carlo method to estimate the area of the underlying region ℛ* from the set of sample points pts. This is done by sampling n points from the bounding rectangular region and counting the fraction of points that are within the range of r from the point cloud.

Using the Monte Carlo method to estimate the area of an underlying region

Accumulate the estimate statistics:

Accumulate the estimate statistics

Estimate the distribution density:

Estimated density for the region area

Compare the estimated value with the exact numerical value:

Compare the estimated value with the exact numerical value

I will conclude with a one-liner, a RandomPoint-based, Styrofoam-style visualization of the 8₃ knot:

One-liner, RandomPoint-based, Styrofoam-style visualization

RandomPoint is part of both the geometric computation and the probability and statistics capabilities in the Wolfram Language. RandomPoint was first introduced in Version 10.2 of the Wolfram Language and has been extended to cover new methods with the release of 10.3.

Download this post as a Computable Document Format (CDF) file.

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.

1 comment