Algorithm-RandomPointGenerator

 view release on metacpan or  search on metacpan

examples/bb1.csv  view on Meta::CPAN

# The first row of this file shows the start and the end of the horizontal
# extent of the bounding box.  The second row does the same for the vertical
# extent.

 -10.00,  10.00
 -10.00,  10.00


examples/bb2.csv  view on Meta::CPAN

# This bounding is supposed to go with hist3.csv histogram

# The first row of this file shows the start and the end of the horizontal
# extent of the bounding box.  The second row does the same for the vertical
# extent.

# In each line, the first value must be smaller than the second

 -71.772016,  -70.431923
 -34.254251,   -33.203240

examples/genRand2D  view on Meta::CPAN

my $help_msg = "\nThe file supplied with the option '--histfile' should contain\n" .
               "a 2D histogram that is to be used for generating the random\n" .
               "points.  Each line of this file should show the bins of the\n" .
               "histogram along the x-axis and the different rows should correspond\n" .
               "to the bin structure along the y-direction.  Use the CSV format for\n" .
               "this file.\n" .
               "\nThe file supplied with the option '--bbfile' needs to delineate\n" .
               "the bounding box of the xy-plane for which the input histogram was\n" .
               "generated by some other tool in your application. Apart from any\n" .
               "comment lines, this file should contain EXACTLY two rows, and each\n" .
               "row with EXACTLY two numbers in it. The second number in each row\n" .
               "must be larger than the first. The two numbers in the first row are\n" .
               "for the x axis and the two number in the second row for the y axis.\n" .
               "Use the CSV format for this file also.\n\n";

die "$help_msg$!\n" if "@ARGV" eq '--help';
my %all_args = @ARGV;
die "\nYou did not supply a histogram file with the '--histfile' option.\n" .
    "Try entering `GenRand2D --help' for info regarding the options\n\n"
    unless exists $all_args{'--histfile'};
die "\nYou did not supply a bounding-box file with the '--bbfile' option.\n" .
    "Try entering `GenRand2D --help' for info regarding the options\n\n"
    unless exists $all_args{'--bbfile'};

lib/Algorithm/RandomPointGenerator.pm  view on Meta::CPAN

        die "Something is wrong with your value for the construction option 'y_xis_pos_direction'";
    }
}


# This subroutine is for reading from a text file the horizontal and the vertical
# limits of the bounding box in which the randomly generated points must reside.  The
# file can either be in the CSV format or the white-space-separated format.  Apart
# from any comment lines that begin with the hash mark, this must must contain
# exactly two lines, the first indicated the x-axis points that define the horizontal
# span of the bounding box and the second indicating the y-axis points that define
# the vertical span of the same.
sub read_file_for_bounding_box {
    my $self = shift;
    my $histref = $self->{_input_histogram};
    my $filename = $self->{_bbox_file};
    open FILEIN, $filename
        or die "unable to open file: $!";
    my @bounding_box;
    while (<FILEIN>) {
        next if /^#/;

lib/Algorithm/RandomPointGenerator.pm  view on Meta::CPAN


The C<bounding_box_file> parameter of the constructor should delineate the portion of
the plane to which the input histogram corresponds.  Here is an example of the
contents of an actual file supplied for this option:

     -71.772016, -70.431923
     -34.254251,  -33.203240

Apart from any comment lines, there must exist exactly two lines in the bounding-box
file, with the first line indicating the left and the right limits of the horizontal
coordinates and the second line indicating the lower and the upper limits of the
vertical coordinates.  (The values shown above are the longitude and the latitude
limits for a region in Chile, in case you are curious.)

=back 

=head2 Constructor Parameters:

=over 8

=item C<input_histogram_file>:

lib/Algorithm/RandomPointGenerator.pm  view on Meta::CPAN

orientation of the y axis in both the histogram and the bounding box will be the
same.>

=item C<bounding_box_file>:

This required parameter supplies the name of the file that contains the bounding box
information.  By bounding box is meant the part of the XY-plane that corresponds to
the histogram supplied through the C<input_histogram_file> option.  Apart from any
comment lines, this file must contain exactly two lines and each line must contain
exactly two numeric entries.  Additionally, the first entry in each of the two lines
must be smaller than the second entry in the same line.  The two entries in the first
line define the lower and the upper bounds on the x-axis and the two entries in the
second line do the same for the y-axis.

=item C<number_of_points>:

This parameter specifies the number of random points that you want the module to
generate.

=item C<how_many_to_discard>:

The Metropolis-Hastings algorithm belongs to a category of algorithms known as
random-walk algorithms. Since the random walk carried out by such algorithms must be



( run in 1.296 second using v1.01-cache-2.11-cpan-39bf76dae61 )