RANDOM_DATA
Generation of random data
RANDOM_DATA
is a MATLAB library which
generates sets of data points using certain
random number distributions, in a given dimension, and in a given
physical region.
Most of these routines assume that there is an available source
of pseudorandom numbers, distributed uniformly in the unit
interval [0,1]. In this package, that role is played by the
routine R8_UNIFORM_01, which allows us some portability.
We can get the same results in C, FORTRAN or MATLAB, for instance.
In general, however, it would be more efficient to use the
language-specific random number generator for this purpose.
If we have a source of pseudorandom values in [0,1], it's trivial
to generate pseudorandom points in any line segment; it's easy to
take pairs of pseudorandom values to sample a square, or triples to
sample a cube. It's easy to see how to deal with square region that
is translated from the origin, or scaled by different amounts in
either axis, or given a rigid rotation. The same simple transformations
can be applied to higher dimensional cubes, without giving us any
concern.
For all these simple shapes, which are just generalizations of
a square, we can easily see how to generate sample points that
we can guarantee will lie inside the region; in most cases, we
can also guarantee that these points will tend to be uniformly
distributed, that is, every subregion can expect to contain
a number of points proportional to its share of the total area.
However, we will not achieve uniform distribution in the
simple case of a rectangle of nonequal sides [0,A] x [0,B],
if we naively scale the random values (u1,u2) to
(A*u1,B*u2). In that case, the expected point density of
a wide, short region will differ from that of a narrow tall region.
The absence of uniformity is most obvious if the points are plotted.
If you realize that uniformity is desirable, and easily lost,
it is possible to adjust the approach so that rectangles are
properly handled.
But rectangles are much too simple. We are interested in circles,
triangles, and other shapes. Once the geometry of the region
becomes more "interesting", there are two common ways to continue.
In the acceptance-rejection method,
uniform points are generated in a superregion that encloses the
region. Then, points that do not lie within the region are rejected.
More points are generated until enough have been accepted to satisfy the
needs. If a circle was the region of interest, for instance, we
could surround it with a box, generate points in the box, and throw
away those points that don't actually lie in the circle. The resulting
set of samples will be a uniform sampling of the circle.
In the direct mapping method, a formula or mapping
is determined so that each time a set of values is taken from
the pseudorandom number generator, it is guaranteed to correspond
to a point in the region. For the circle problem, we can use
one uniform random number to choose an angle between 0 and 2 PI,
the other to choose a radius. (The radius must be chosen in
an appropriate way to guarantee uniformity, however.) Thus,
every time we input two uniform random values, we get a pair
(R,T) that corresponds to a point in the circle.
The acceptance-rejection method can be simple to program, and
can handle arbitrary regions. The direct mapping method is
less sensitive to variations in the aspect ratio of a region
and other irregularities. However, direct mappings are only
known for certain common mathematical shapes.
Points may also be generated according to a nonuniform density.
This creates an additional complication in programming. However,
there are some cases in which it is possible to use direct mapping
to turn a stream of scalar uniform random values into a set of
multivariate data that is governed by a normal distribution.
Another way to generate points replaces the uniform pseudorandom number
generator by a quasirandom number generator. The main difference
is that successive elements of a quasirandom sequence may be highly
correlated (bad for certain Monte Carlo applications) but will tend
to cover the region in a much more regular way than pseudorandom
numbers. Any process that uses uniform random numbers to carry out
sampling can easily be modified to do the same sampling with
a quasirandom sequence like the Halton sequence, for instance.
The library includes a routine that can write the resulting
data points to a file.
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
RANDOM_DATA is available in
a C++ version and
a FORTRAN90 version and
a MATLAB version.
Related Data and Programs:
ASA183,
a MATLAB library which
implements the Wichman-Hill pseudorandom number generator.
BALL_GRID,
a MATLAB library which
computes grid points that lie inside a ball.
CIRCLE_GRID,
a MATLAB library which
computes grid points that lie inside a circle.
DISCRETE_PDF_SAMPLE,
a MATLAB program which
demonstrates how to construct a Probability Density Function (PDF)
from a table of sample data, and then to use that PDF to create new samples.
RBOX,
a C program which
produces random data from a number of regions.
RSITES,
a C++ program which
produces random data in an M-dimensional box.
SIMPLEX_COORDINATES,
a MATLAB library which
computes the Cartesian coordinates of the vertices of a regular
simplex in M dimensions.
TETRAHEDRON_GRID,
a MATLAB library which
computes a tetrahedral grid of points.
TETRAHEDRON_MONTE_CARLO,
a MATLAB program which
uses the Monte Carlo method to estimate integrals over a tetrahedron.
TETRAHEDRON_SAMPLES,
a dataset directory which
contains examples of sets of sample points from the unit tetrahedron.
TRIANGLE_GRID,
a MATLAB library which
computes a triangular grid of points.
TRIANGLE_HISTOGRAM,
a MATLAB program which
computes histograms of data on the unit triangle.
TRIANGLE_MONTE_CARLO,
a MATLAB program which
uses the Monte Carlo method to estimate integrals over a triangle.
TRIANGLE_SAMPLES,
a dataset directory which
contains examples of sets of sample points from the unit triangle.
UNIFORM,
a MATLAB library which
samples the uniform random distribution.
XYZ_DISPLAY,
a MATLAB program which
reads XYZ information defining points in 3D,
and displays an image in the MATLAB graphics window.
XYZ_DISPLAY_OPENGL,
a C++ program which
reads XYZ information defining points in 3D,
and displays an image using OpenGL.
Reference:
-
Milton Abramowitz, Irene Stegun,
Handbook of Mathematical Functions,
National Bureau of Standards, 1964,
ISBN: 0-486-61272-4,
LC: QA47.A34.
-
James Arvo,
Stratified sampling of spherical triangles,
Computer Graphics Proceedings, Annual Conference Series,
ACM SIGGRAPH '95, pages 437-438, 1995.
-
Gerard Bashein, Paul Detmer,
Centroid of a Polygon,
in Graphics Gems IV,
edited by Paul Heckbert,
AP Professional, 1994,
ISBN: 0123361559,
LC: T385.G6974.
-
Paul Bratley, Bennett Fox, Linus Schrage,
A Guide to Simulation,
Second Edition,
Springer, 1987,
ISBN: 0387964673,
LC: QA76.9.C65.B73.
-
Russell Cheng,
Random Variate Generation,
in Handbook of Simulation,
edited by Jerry Banks,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
-
Jack Dongarra, Jim Bunch, Cleve Moler, Pete Stewart,
LINPACK User's Guide,
SIAM, 1979,
ISBN13: 978-0-898711-72-1,
LC: QA214.L56.
-
John Halton,
On the efficiency of certain quasi-random sequences of points
in evaluating multi-dimensional integrals,
Numerische Mathematik,
Volume 2, Number 1, December 1960, pages 84-90.
-
John Halton, GB Smith,
Algorithm 247:
Radical-Inverse Quasi-Random Point Sequence,
Communications of the ACM,
Volume 7, Number 12, December 1964, pages 701-702.
-
John Hammersley,
Monte Carlo methods for solving multivariable problems,
Proceedings of the New York Academy of Science,
Volume 86, 1960, pages 844-874.
-
Ladislav Kocis, William Whiten,
Computational Investigations of Low-Discrepancy Sequences,
ACM Transactions on Mathematical Software,
Volume 23, Number 2, June 1997, pages 266-294.
-
Pierre LEcuyer,
Random Number Generation,
in Handbook of Simulation,
edited by Jerry Banks,
Wiley, 1998,
ISBN: 0471134031,
LC: T57.62.H37.
-
Albert Nijenhuis, Herbert Wilf,
Combinatorial Algorithms for Computers and Calculators,
Second Edition,
Academic Press, 1978,
ISBN: 0-12-519260-6,
LC: QA164.N54.
-
Reuven Rubinstein,
Monte Carlo Optimization, Simulation and Sensitivity of
Queueing Networks,
Krieger, 1992,
ISBN: 0894647644,
LC: QA298.R79.
-
Peter Shirley,
Nonuniform Random Point Sets Via Warping,
in Graphics Gems III,
edited by David Kirk,
Academic Press, 1992,
ISBN: 0124096735,
LC: T385.G6973
-
Greg Turk,
Generating Random Points in a Triangle,
in Graphics Gems I,
edited by Andrew Glassner,
AP Professional, 1990,
ISBN: 0122861663,
LC: T385.G697
-
Daniel Zwillinger, editor,
CRC Standard Mathematical Tables and Formulae,
30th Edition,
CRC Press, 1996,
ISBN: 0-8493-2479-3,
LC: QA47.M315.
Source Code:
-
arc_cosine.m
evaluates the arc cosine function, with argument truncation.
-
bad_in_simplex01.m
is a "bad" (nonuniform) sampling of the unit simplex.
-
brownian.m
creates Brownian motion points.
-
dpo_fa.m
factors a real symmetric positive definite matrix.
-
dpo_sl.m
solves a linear system factored by DPO_CO or DPO_FA.
-
direction_uniform_nd.m
generates a random direction vector.
-
grid_in_cube01.m
generates grid points in the unit hypercube.
-
grid_side.m
finds the smallest grid containing at least N points.
-
halham_dim_num_check.m
checks DIM_NUM for a Halton or Hammersley sequence.
-
halham_leap_check.m
checks LEAP for a Halton or Hammersley sequence.
-
halham_n_check.m
checks N for a Halton or Hammersley sequence.
-
halham_seed_check.m
checks SEED for a Halton or Hammersley sequence.
-
halham_step_check.m
checks STEP for a Halton or Hammersley sequence.
-
halton_base_check.m
checks BASE for a Halton sequence.
-
halton_in_circle01_accept.m
accepts Halton points in the unit circle.
-
halton_in_circle01_map.m
maps Halton points into the unit circle.
-
halton_in_cube01.m
generates Halton points in the unit hypercube.
-
hammersley_base_check.m
is TRUE if BASE is legal.
-
hammersley_in_cube01.m
generates Hammersley points in the unit hypercube.
-
i4_factorial.m
computes the factorial N!
-
i4_modp.m
returns the nonnegative remainder of integer division.
-
i4_to_halton.m
computes one element of a leaped Halton subsequence.
-
i4_to_halton_sequence.m
computes N elements of a leaped Halton subsequence.
-
i4_to_hammersley.m
computes one element of a leaped Hammersley subsequence.
-
i4_to_hammersley_sequence.m
computes N elements of a leaped Hammersley subsequence.
-
i4_uniform.m
returns a integer pseudorandom number.
-
i4vec_transpose_print.m
prints an integer vector "transposed".
-
ksub_random2.m
selects a random subset of size K from a set of size N.
-
normal.m
creates normally distributed points.
-
normal_circular.m
creates circularly normal points.
-
normal_multivariate.m
samples a multivariate normal distribution.
-
normal_simple.m
creates normally distributed points.
-
polygon_centroid_2d.m
computes the centroid of a polygon in 2D.
-
prime.m
returns any of the first PRIME_MAX prime numbers.
-
r8_normal_01.m
returns a unit pseudonormal R8.
-
r8_uniform_01.m
returns a unit pseudorandom R8.
-
r8mat_normal_01.m
returns a unit pseudonormal R8MAT.
-
r8mat_print.m
prints an R8MAT, with an optional title.
-
r8mat_print_some.m
prints some of an R8MAT, with an optional title.
-
r8mat_write.m
writes an R8MAT file.
-
r8mat_uniform_01.m
returns a unit pseudorandom R8MAT.
-
r8vec_normal_01.m
returns a unit pseudonormal R8VEC.
-
r8vec_print.m
prints an R8VEC.
-
r8vec_uniform_01.m
returns a unit pseudorandom R8VEC.
-
s_len_trim.m
returns the length of a string to the last nonblank.
-
scale_from_simplex01.m
rescales data from a unit to non-unit simplex.
-
scale_to_ball01.m
translates and rescales data to fit within the unit ball.
-
scale_to_block01.m
translates and rescales data to fit in the unit block.
-
scale_to_cube01.m
translates and rescales data to the unit hypercube.
-
stri_angles_to_area.m,
computes the area of a spherical triangle;
-
stri_sides_to_angles.m,
computes the angles of a spherical triangle from its sides;
-
stri_vertices_to_sides.m,
computes the sides of a spherical triangle from its sides;
-
timestamp.m
prints the current YMDHMS date as a time stamp.
-
triangle_area_2d.m
computes the area of a triangle in 2D.
-
tuple_next_fast.m
computes the next element of a tuple space, "fast".
-
uniform_in_annulus.m
samples a circular annulus.
-
uniform_in_annulus_accept.m
accepts points in an annulus.
-
uniform_in_annulus_accept.m
samples an annular sector in 2D.
-
uniform_in_circle01_map.m
maps uniform points into the unit circle.
-
uniform_in_cube01.m
creates uniform points in the unit hypercube.
-
uniform_in_ellipsoid_map.m
maps uniform points into an ellipsoid.
-
uniform_in_parallelogram_map.m
maps uniform points into a parallelogram.
-
uniform_in_polygon_map.m
maps uniform points into a polygon.
-
uniform_in_sector_map.m
maps uniform points into a circular sector.
-
uniform_in_simplex01_map.m
maps uniform points into the unit simplex.
-
uniform_in_sphere01_map.m
maps uniform points into the unit sphere.
-
uniform_in_tetrahedron.m
maps uniform points into a tetrahedron.
-
uniform_in_triangle_map1.m
maps uniform points into a triangle.
-
uniform_in_triangle_map2.m
maps uniform points into a triangle.
-
uniform_in_triangle01_map.m
maps uniform points into the unit triangle.
-
uniform_on_ellipsoid_map.m
maps uniform points onto an ellipsoid.
-
uniform_on_hemisphere01_phong.m
maps uniform points onto the unit hemisphere, with the Phong
distribution.
-
uniform_on_simplex01_map.m
maps uniform points onto the unit simplex.
-
uniform_on_sphere01_map.m
maps uniform points onto the unit sphere.
-
uniform_on_sphere01_patch_tp.m
maps uniform points onto a unit sphere TP (THETA,PHI) patch in 3D.
-
uniform_on_sphere01_patch_xyz.m
maps uniform points onto a unit sphere XYZ patch in 3D.
-
uniform_on_sphere01_triangle_xyz.m
maps uniform points onto a spherical triangle on the unit sphere, using
XYZ coordinates.
-
uniform_walk.m
generates points on a uniform random walk.
Examples and Tests:
-
random_data_test.m,
calls all the test programs.
-
random_data_test_output.txt,
output from the sample calling program.
-
random_data_test005.m,
tests BAD_IN_SIMPLEX01.
-
random_data_test01.m,
tests BROWNIAN.
-
random_data_test02.m,
tests R8_NORMAL_01.
-
random_data_test03.m,
tests R8_UNIFORM_01.
-
random_data_test04.m,
tests GRID_IN_CUBE01.
-
random_data_test05.m,
tests HALTON_IN_CIRCLE01_ACCEPT.
-
random_data_test06.m,
tests HALTON_IN_CIRCLE01_MAP.
-
random_data_test07.m,
tests HALTON_IN_CUBE01.
-
random_data_test08.m,
tests HAMMERSLEY_IN_CUBE01.
-
random_data_test09.m,
tests NORMAL.
-
random_data_test10.m,
tests NORMAL_CIRCULAR.
-
random_data_test11.m,
tests NORMAL_SIMPLE.
-
random_data_test115.m,
tests UNIFORM_IN_ANNULUS.
-
random_data_test12.m,
tests UNIFORM_IN_ANNULUS_ACCEPT.
-
random_data_test125.m,
tests UNIFORM_IN_ANNULUS_SECTOR.
-
random_data_test13.m,
tests UNIFORM_IN_CIRCLE01_MAP.
-
random_data_test14.m,
tests UNIFORM_IN_CUBE01.
-
random_data_test15.m,
tests UNIFORM_IN_ELLIPSOID_MAP.
-
random_data_test16.m,
tests UNIFORM_IN_PARALLELOGRAM_MAP.
-
random_data_test17.m,
tests UNIFORM_IN_POLYGON_MAP.
-
random_data_test18.m,
tests UNIFORM_IN_SECTOR_MAP.
-
random_data_test19.m,
tests UNIFORM_IN_SIMPLEX01_MAP.
-
random_data_test20.m,
tests UNIFORM_IN_SPHERE01_MAP.
-
random_data_test21.m,
tests UNIFORM_IN_TRIANGLE_MAP1.
-
random_data_test22.m,
tests UNIFORM_IN_TRIANGLE_MAP2.
-
random_data_test23.m,
tests UNIFORM_IN_TRIANGLE01_MAP.
-
random_data_test24.m,
tests UNIFORM_ON_ELLIPSOID_MAP.
-
random_data_test245.m,
tests UNIFORM_ON_HEMISPHERE01_PHONG.
-
random_data_test25.m,
tests UNIFORM_ON_SIMPLEX01_MAP.
-
random_data_test26.m,
tests UNIFORM_ON_SPHERE01_MAP.
-
random_data_test264.m,
tests UNIFORM_ON_SPHERE01_PATCH_TP.
-
random_data_test265.m,
tests UNIFORM_ON_SPHERE01_PATCH_XYZ.
-
random_data_test267.m,
tests UNIFORM_ON_SPHERE01_TRIANGLE_XYZ.
-
random_data_test27.m,
tests UNIFORM_WALK.
The sample calling program generates sets of points:
-
bad_in_tetrahedron.txt,
points in the unit tetrahedron, not uniformly chosen.
-
bad_in_triangle.txt,
points in the unit triangle, not uniformly chosen.
-
brownian.txt, Brownian motion.
-
grid_in_cube01.txt,
grid points in the unit hypercube, with CENTER = 1.
-
halton_in_circle01_accept.txt,
Halton points in the unit circle by acceptance/rejection.
-
halton_in_circle01_map.txt,
Halton points in the unit circle by direct mapping.
-
halton_in_cube01.txt,
Halton points in the unit hypercube.
-
hammersley_in_cube01.txt, Hammersley points in the unit hypercube.
-
normal.txt, normal points, with
strong correlation between the two coordinates.
-
normal_circular.txt,
circular normal points.
-
normal_simple.txt,
normal points in which there is no correlation between the
X and Y coordinates.
-
polygon_vertices.txt,
the vertices of a polygon to be filled by random points.
-
uniform_in_annulus.txt,
uniform random points in an annulus, mappint.
-
uniform_in_annulus_accept.txt,
uniform random points in an annulus, acceptance/rejection.
-
uniform_in_annulus_sector.txt,
uniform random points in an annulus sector, mapping.
-
uniform_in_cube.txt,
uniform random points in the unit hypercube.
-
uniform_in_circle01_map.txt,
uniform random points in the unit circle.
-
uniform_in_ellipsoid.txt,
uniform random points in an ellipsoid.
-
uniform_in_parallelogram_map.txt,
uniform random points in a parallelogram.
-
uniform_in_polygon_map.txt,
uniform random points in a polygon (a star, in this case).
-
uniform_in_sector_map.txt,
uniform random points in a circular sector.
-
uniform_in_simplex01_map.txt,
uniform random points in the unit simplex.
-
uniform_in_sphere01_map.txt,
uniform random points in the unit sphere.
-
uniform_in_tetrahedron.txt,
uniform random points in an arbitrary tetrahedron.
-
uniform_in_triangle_map1.txt,
uniform random points in an arbitrary triangle, Turk method 1.
-
uniform_in_triangle_map2.txt,
uniform random points in an arbitrary triangle, Turk method 2.
-
uniform_in_triangle01_map.txt,
uniform random points in the unit triangle.
-
uniform_on_ellipsoid_map.txt,
uniform random points on an ellipsoid.
-
uniform_on_hemisphere01_phong.txt,
uniform random points on the unit hemisphere, Phong distribution.
-
uniform_on_simplex01_map.txt,
uniform random points on the unit simplex.
-
uniform_on_sphere01_map.txt,
uniform random points on the unit sphere in 2D.
-
uniform_on_sphere01_patch_tp.txt,
uniform random points on a unit sphere TP (THETA,PHI) patch in 3D.
-
uniform_on_sphere01_patch_xyz.txt,
uniform random points on a unit sphere XYZ patch in 3D.
-
uniform_on_sphere01_triangle_xyz.txt,
uniform random points on a spherical triangle of the unit sphere in 3D
using XYZ coordinates.
-
uniform_walk.txt,
points on a uniform random walk.
A file of commands is provided to simplify the use of PLOT_POINTS:
PLOT_POINTS makes Encapsulated PostScript images of the points,
in cases where the data is 2 dimensional. The CONVERT command
was used to convert these to
PNG files.
-
brownian.png
-
grid_in_cube01.png
-
halton_in_circle01_accept.png
-
halton_in_circle01_map.png
-
halton_in_cube01.png
-
hammersley_in_cube01.png
-
normal.png
-
normal_circular.png
-
normal_simple.png
-
polygon_vertices.png,
-
uniform_in_annulus.png,
-
uniform_in_annulus_accept.png,
-
uniform_in_annulus_sector.png,
-
uniform_in_cube01.png,
-
uniform_in_circle01_map.png,
-
uniform_in_ellipsoid_map.png,
-
uniform_in_parallelogram_map.png,
-
uniform_in_polygon_map.png,
-
uniform_in_sector_map.png,
-
uniform_in_simplex01_map.png,
-
uniform_in_sphere01_map.png,
-
uniform_in_triangle_map1.png,
-
uniform_in_triangle_map2.png,
-
uniform_in_triangle01_map.png,
-
uniform_on_ellipsoid_map.png,
-
uniform_on_simplex01_map.png,
-
uniform_on_sphere01_map.png,
-
uniform_on_sphere01_patch_tp.png
-
uniform_on_sphere01_patch_xyz.png,
-
uniform_walk.png,
You can go up one level to
the MATLAB source codes.
Last revised on 24 August 2010.