The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MachineLearning::IntegerAnnealing - optimize a list of integers according to a cost function

SYNOPSIS

  use MachineLearning::IntegerAnnealing;
  my $result_array_ref = anneal({
    "Ranges" => [ [2, 4], [9, 18], [19, 28], [29, 55] ],
    "CostCalculator" => $cost_calculator_coderef,
    "CyclesPerTemperature" => 1_000});

DESCRIPTION

This module exports a single function, anneal(), which performs simulated annealing to optimize a list of integers that have predefined ranges. The list can be of any size N.

In addition to the ranges for the integers, the anneal() function takes a reference to a cost function that takes a reference to an array with N elements and returns a number representing a cost to be minimized. The returned number does not have to be an integer.

The anneal() function also takes as input a positive integer specifying the number of cycles per temperature; that is, the number of randomization cycles to perform at each temperature level during the annealing process. A higher number of cycles per temperature produces more accurate results while increasing the amount of time required for the annealing process to complete.

FUNCTIONS

anneal($args_hashref);

This function takes a reference to a hash with the following fields:

    Ranges - A reference to an array of pairs of bounds, lower and
    upper, where a pair is a reference to an array of two integers
    of which the first is less than the second.

    CostCalculator - A reference to a function that takes a
    reference to an array of integers and returns a single number
    representing a cost to be minimized.  The function must accept
    a reference to an input array that is the same size as the
    Ranges array.

      NOTE:  The returned number does not have to be an integer.

    CyclesPerTemperature - A positive integer specifying the number
    of randomization cycles performed at each temperature level.

      NOTE:  Temperature starts at the size of the largest range
      (which means that each integer gets randomized within 100% of
      its specified range) and then gradually decreases.  Each
      temperature reduction multiplies the temperature by 96% and
      then rounds that result down to the nearest integer.

    If the CyclesPerTemperature value is not a positive integer,
    the anneal() function returns a reference to an empty array.

The anneal() function returns a reference to an array of integers that corresponds to the Ranges array (that is, the output array is the same size as the Ranges array, and each integer in the output array is within the range indicated by the corresponding element in the Ranges array). The output array is the list of integers that has the lowest cost (according to the specified cost function) of any of the lists tested during the annealing process.

AUTHOR

Benjamin Fitch, <blernflerkl@yahoo.com>

COPYRIGHT AND LICENSE

Copyright 2009 by Benjamin Fitch

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.