Algorithm-SpiralSearch

 view release on metacpan or  search on metacpan

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


   my @x             = ();
   my @y             = ();
   my @nrv_ary       = ();
   my $x_inc         = $grad_x[1] - $grad_x[0];
   my $y_inc         = $grad_y[1] - $grad_y[0];
   my $maximize      = $max_or_min =~ /^\s*MIN\s*$/i ? -1 : 1;
   my $ret_val       = 0;
   my $new_ret_val   = 0;
   my $theta         = 0;
   my $best_x        = 0;
   my $best_y        = 0;
   my $out_of_bounds = 0;

   # Increase the radius of the search by the following factor
   # if a better function evaluation is not found.
   my $rad_inc  = 1.2;

   my $bounded  = 1;
   my $radius_x = 1;
   my $radius_y = 1;

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

            $x_init = $x[$t-1];
            $y_init = $y[$t-1];
         }

         $ret_val = $new_ret_val;
      } else {
         $nrv_ary[$t-1] = 0;
      }
   }

   # Find the best return value and its corresponding input coordinates.
   {
      my $m = 0;

      for (my $i = 0; $i < @nrv_ary; $i++) {
         if ($maximize * $nrv_ary[$i] >= $maximize * $m) {
            $best_x = $x[$i];
            $best_y = $y[$i];
            $m      = $nrv_ary[$i];
         }
      }
   }

   return($best_x, $best_y);
}

1;

__END__

=head1 NAME

Algorithm::SpiralSearch - Function Optimization of Two Parameters



( run in 0.920 second using v1.01-cache-2.11-cpan-4e96b696675 )