Algorithm-RandomPointGenerator
view release on metacpan or search on metacpan
lib/Algorithm/RandomPointGenerator.pm view on Meta::CPAN
my ($class, %args) = @_;
my @params = keys %args;
croak "\nYou have used a wrong name for a keyword argument " .
"--- perhaps a misspelling\n"
if check_for_illegal_params(@params) == 0;
bless {
_hist_file => $args{input_histogram_file} || croak("histogram file required"),
_bbox_file => $args{bounding_box_file} || croak("bounding box file required"),
_N => $args{number_of_points} || 2000,
_how_many_to_discard => $args{how_many_to_discard} || 500,
_debug => $args{debug} || 0,
_proposal_density_width => $args{proposal_density_width} || 0.1,
_y_axis_pos_direction => $args{y_axis_pos_direction} || "down",
_output_hist_bins_along_x => $args{output_hist_bins_along_x} || 40,
_command_line_mode => $args{command_line_mode} || 0,
_x_delta => undef,
_y_delta => undef,
_input_histogram => undef,
_output_histogram => undef,
_bounding_box => undef,
_generated_points => undef,
lib/Algorithm/RandomPointGenerator.pm view on Meta::CPAN
# proposal density function. The desired density is calculated by applying bilinear
# interpolation to the bin counts to the four nearest four points in the normalized
# version of the input histogram.
sub desired_density {
my $self = shift;
my $sample = shift;
my $histref = $self->{_normalized_input_hist};
my $bbsize = $self->{_bounding_box};
my $horiz_delta = $self->{_x_delta};
my $vert_delta = $self->{_y_delta};
print "horiz_delta: $horiz_delta vert_delta: $vert_delta\n" if $self->{_debug};
return 0 if $sample->[0] < $bbsize->[0][0] || $sample->[0] > $bbsize->[0][1] ||
$sample->[1] < $bbsize->[1][0] || $sample->[1] > $bbsize->[1][1];
print "horizontal extent: $bbsize->[0][0] $bbsize->[0][1]\n" if $self->{_debug};
print "vertical extent: $bbsize->[1][0] $bbsize->[1][1]\n" if $self->{_debug};
my $bin_horiz = int( ($sample->[0] - $bbsize->[0][0]) / $horiz_delta );
my $bin_vert = int( ($sample->[1] - $bbsize->[1][0]) / $vert_delta );
print "bin 2D index: horiz: $bin_horiz vert: $bin_vert for sample value @$sample\n"
if $self->{_debug};
my $prob00 = $histref->[$bin_vert][$bin_horiz] || 0;
return $prob00 if (($bin_horiz + 1) >= @{$histref->[0]}) || (($bin_vert + 1) >= @{$histref});
my $prob01 = $histref->[$bin_vert + 1][$bin_horiz] || 0;
my $prob10 = $histref->[$bin_vert][$bin_horiz+ 1] || 0;
my $prob11 = $histref->[$bin_vert + 1][$bin_horiz + 1] || 0;
print "The four probs: $prob00 $prob01 $prob10 $prob11\n" if $self->{_debug};
my $horiz_fractional = (($sample->[0] - $bbsize->[0][0]) / $horiz_delta) - $bin_horiz;
my $vert_fractional = (($sample->[1] - $bbsize->[1][0]) / $vert_delta) - $bin_vert;
print "horiz frac: $horiz_fractional vert frac: $vert_fractional\n" if $self->{_debug};
my $interpolated_prob = $prob00 * (1 - $horiz_fractional) * (1 - $vert_fractional) +
$prob10 * $horiz_fractional * (1 - $vert_fractional) +
$prob01 * (1 - $horiz_fractional) * $vert_fractional +
$prob11 * $horiz_fractional * $vert_fractional;
print "Interpolated prob: $interpolated_prob\n" if $self->{_debug};
return $interpolated_prob;
}
sub proposal_density {
my $self = shift;
my $sample = shift;
my $mean = shift;
my $sigmax = $self->{_sigmax_for_proposal_density};
my $sigmay = $self->{_sigmay_for_proposal_density};
my @SIGMA = ( [$sigmax, 0], [0, $sigmay] );
lib/Algorithm/RandomPointGenerator.pm view on Meta::CPAN
sub check_for_illegal_params {
my @params = @_;
my @legal_params = qw / input_histogram_file
bounding_box_file
number_of_points
how_many_to_discard
proposal_density_width
y_axis_pos_direction
output_hist_bins_along_x
command_line_mode
debug
/;
my $found_match_flag;
foreach my $param (@params) {
foreach my $legal (@legal_params) {
$found_match_flag = 0;
if ($param eq $legal) {
$found_match_flag = 1;
last;
}
}
lib/Algorithm/RandomPointGenerator.pm view on Meta::CPAN
=item B<plot_histogram_lineplot():>
$generator->plot_histogram_lineplot();
This creates a 3D line plot display of the histogram of the generated random points.
=item B<display_output_histogram_in_terminal_window():>
$generator->display_output_histogram_in_terminal_window();
Useful for debugging purposes, it displays in the terminal window a two dimensional
array of numbers that is the histogram of the random points generated by the module.
=back
=head1 THE C<examples> DIRECTORY
Probably the most useful item in the C<examples> directory is the command-line script
C<genRand2D> that can be called simply with two arguments for generating a set of
random points. A call to this script looks like
( run in 1.109 second using v1.01-cache-2.11-cpan-49f99fa48dc )