function histogram_pdf_2d_sample_test ( )

%*****************************************************************************80
%
%% histogram_pdf_2d_sample_test() creates a histogram from a PDF over a 2D region.
%
%  Discussion:
%
%    In this function, we consider the region -1 <= X <= +1, 0 <= Y <= 1,
%    with a probability density function (PDF) which happens to be separable:
%      pdf(x,y) = pdf1(x) * pdf2(y)
%    although separability is not an important factor in this example.
%
%    We plan to divide the region into a 20 x 10 array of rectangles, and
%    assign to each rectangle a discrete density equal to the PDF evaluated
%    at the center of that rectangle.  
%
%    We then "forget" the original PDF, and consider this new object as our
%    resource for probabilistic information.
%
%    In particular, we may now normalize the histogram so that, regarded as
%    a piecewise constant function, its integral over the region is 1.
%
%    We may then construct what amounts to a CDF, so that, given a random value
%    between 0 and 1, we can identify a corresponding rectangle from which a 
%    sample point can be drawn uniformly at random.
%
%    The discrete piecewise constant probability structure created in this way
%    can be improved by increasing the number of rectangles, or by adjusting the
%    positions of the rectangles to better match regions in which the original
%    PDF is constant, or negligible.
%
%    The main point is that this approximation is available in cases where an
%    analytic approach would fail because of the impracticality of solving
%    the integration problem for the continuous PDF or the inversion problem 
%    for the corresponding CDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 January 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../histogram_pdf_2d_sample' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'histogram_pdf_2d_sample_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  histogram_pdf_2d_sample() generates a discrete probability \n' );
  fprintf ( 1, '  structure from a continuous PDF defined over a 2D region.\n' );

  m1 = 20;
  m2 = 10;
  n = 1000;
  square_sqrt_test ( m1, m2, n );

  m1 = 20;
  m2 = 20;
  n = 1000;
  chebyshev_test ( m1, m2, n );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'histogram_pdf_2d_sample():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../histogram_pdf_2d_sample' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

