Algorithm-SpiralSearch

 view release on metacpan or  search on metacpan

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

require Exporter;

our @ISA         = qw(Exporter);
our %EXPORT_TAGS = ( 'all' => [ qw( ) ] );
our @EXPORT_OK   = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT      = qw(spiral_search);
our $VERSION     = '1.20';

sub spiral_search {
   my $usage = '($opt_x, $opt_y) = spiral_search($lower_boundx,$upper_boundx,' .
               '$lower_boundy,$upper_boundy,$iterations,$function,' .
               "'MAX|MIN')";

   my ($lbx, $ubx, $lby, $uby, $iters, $f, $max_or_min) = @_;

   croak 'A valid input/output funtion reference must be passed in'
      unless $f =~ /CODE/;

   croak 'Two or more iterations are required : ' if $iters < 2;
   croak 'Upper boundary on first parameter must be non-zero : ' if $ubx == 0.0;
   croak 'Upper boundary on second parameter must be non-zero : '
      if $uby == 0.0;

   croak 'Final parameter must be set to MAX or MIN : '
      unless $max_or_min =~ /MAX|MIN/i;

   # Set the initial start points to half the distances of the search space
   # extrema.
   my $x_init = ($ubx - $lbx) / 2;

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


  sub f {
    my ($p1, $p2) = @_;
    my $ret = simulator($p1, $p2, ...);
    return $ret;
  }

=head1 DESCRIPTION

A spiral search is a method used to optimize a two-parameter, relatively,
well-behaved function. Boundary conditions, the maximum number of iterations, a
reference to a function, and an indicator to maximize or minimize the function
are passed to the spiral_search function.  spiral_search() returns the optimal
point in the function passed to it.  It's an elegant optimization algorithm, but
is not well-suited for most applications. SETI uses the spiral search in huntingfor strong radio signals. Spiral search is most effective in situations where
function evaluations are expensive and where there's a small amount of random
noise within the search space. The algorithm is of order O(n).

=head1 METHODS

=head2 Search Methods

B<spiral_search($lowerBound_x, $upperBound_x, $lowerBound_y, $upperBound_y,
   $iterations, \&function, $MAX_or_MIN)>

Initiates the spiral search. The first four parameters define the search space
plane. Spiral search is of order O(n), so the number of iterations defines how
many refinements the algorithm should take into account.  The greater the numberof iterations, the more accurate the findings.

The sixth parameter should be a reference to a function for which the parameters
will be plugged into. This function should return only one value - a scalar
output indicative of the accuracy of the inputs. The last input parameter shouldbe either one of the two strings 'MAX' or 'MIN', each corresponding to how
spiral_search will optimize its given function. spiral_search returns a pair of
parameters that are approximately optimal with respect to the given function.

=head1 AUTHOR

Sean Mostafavi, E<lt>seanm@undersea.netE<gt>



( run in 0.623 second using v1.01-cache-2.11-cpan-96521ef73a4 )