NAME

PDL::GA - Genetic algorithm utilities for PDLs

SYNOPSIS

use PDL;
use PDL::GA;

##-------------------------------------------------------------
## TODO...

FUNCTIONS

Weighted Selection

roulette

Signature: (weightmap(M); %options)
Options:
  n  => $n
  to => [o]selindices($n)

Stochastic (roulette-wheel) selection of $n objects from $M objects, governed by the likelihood distribution $weightmap(), allowing repetitions. Calls PDL::Primitive::vsearch().

roulette_nr

Signature: (weightmap(M); %options)
Options:
  n  => $n
  to => [o]selindices($n)

Stochastic (roulette-wheel) selection of $n objects from $M objects, governed by the likelihood distribution $weightmap(), without repetitions. Wrapper for cumuweighselect_nr.

weightselect

Signature: (weightmap(M); selweights(S); [o]selindices(S))

Stochastically select $S objects from a pool $M objects, allowing repetitions. Likelihood selecting an object $i is given by $weightmap($i). Target selection likelihoods are passed as $selweights(), which should have values in the range [0,sum($weightmap)\(. Selected targets are returned as indices in the range [0,$M\( in the PDL $selindices().

See also: roulette(), cumuweightselect(), roulette_nr(), weightselect_nr(), cumuweightselect_nr(), PDL::Primitive::vsearch(), PDL::Ufunc::cumusumover().

weightselect_nr

Signature: (weightmap(M); selweights(S); [o]selindices(S))

Like weightselect() without repetition. Wraps cumuweightselect_nr().

cumuweightselect

Signature: (cumuweightmap(M); selweights(S); indx [o]selindices(S))

Stochastically select $S objects from a pool $M objects, allowing repetitions. Cumulative likelihood selecting an object $i is given by $cumweightmap($i). Target selection likelihoods are passed as $selweights(), which should have values in the range [0,$cumuweightmap[-1]\(. Selected targets are returned as indices in the range [0,$M\( in the PDL $selindices(). Really just a wrapper for PDL::Primitive::vsearch().

See also: roulette(), weightselect(), roulette_nr(), weightselect_nr(), cumuweightselect_nr(), PDL::Primitive::vsearch(), PDL::Ufunc::cumusumover().

cumuweightselect_nr

Signature: (cumuweightmap(M); selweights(S); indx [o]selindices(S); indx [t]trynext(M); byte [t]ignore(M))

Stochastically select $S objects from a pool $M objects, without repetitions. Really just a wrapper for PDL::Primitive::vesarch() and ga_make_unique().

ga_make_unique

Signature: (indx selected(S); int trynext(M); indx [o]unique_selected(S); byte [t]ignore(M))

Remove repetitions from a vector of selected items $selected() while retaining vector length. $selected() should have values in the range [0..($M-1)], and it must be the case that $S <= $M. The vector $trynext() is used to (iteratively) map a non-unique item to the "next-best" item, and are implicitly interpreted modulo $M. The temporary $ignore is used to record which items have already appeared. May be run in-place on $selected(). Generally, $trynext() should be something like 1+sequence($M).

ga_make_unique processes bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Gene Encoding and Decoding

tobits

Signature: (ints(); [o]bits(B))

Extract individual bits from integer type pdls. Output pdl will be created with appropriate dimensions if unspecified. Serious waste of memory, since PDL does not have a 'bit' type.

_tobits

Signature: (a(); [o]bits(B))

(Low-level method)

Extract individual bits from integer type pdls. Output pdl $bits() must be specified!

_tobits does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

frombits

Signature: (bits(B); [o]a())

Compress expanded bit-pdls to integer types.

frombits does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Mutation

mutate_bool

Signature: (genes(G); float+ rate(G); [o]mutated(G))

Mutate binary-valued (boolean) genes.

mutate_bool does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

mutate_range

Signature: (genes(G); float+ rate(G); min(G); max(G); [o]mutated(G))

Mutate genes in the range [$min,$max\(.

mutate_range does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

mutate_addrange

Signature: (genes(G); float+ rate(G); min(G); max(G); [o]mutated(G))

Mutate genes by adding values in the range [$min,$max\(.

mutate_addrange does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

mutate_bits

Signature: (genes(G); rate(); [o]mutated(G))

Mutate traditional bit-string genes. Calls mutate_bool(), tobits(), frombits().

_mutate_bits

Signature: (genes(G); float+ rate(G); [o]mutated(G))

(Low-level method)

Mutate traditional bit-string genes. This should be equivalent to mutate_bits(), but appears to involve less overhead (faster for many calls).

_mutate_bits does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

Crossover

_xover1

Signature: (mom(G); dad(G); indx xpoint(); [o]kid(G))

(Low-level method)

Single-point crossover. $kid() is computed by single-point crossover of $mom() (initial subsequence) and $dad() (final subsequence). For symmetric crossover (two offspring per crossing), call this method twice:

$kid1 = _xover1($mom, $dad, $points);
$kid2 = _xover1($dad, $mom, $points);

_xover1 does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

_xover2

Signature: (mom(G); dad(G); indx xstart(); int xend(); [o]kid(G))

(Low-level method)

Dual-point crossover. $kid() is computed by dual-point crossover of $mom() (initial and final subsequences) and $dad() (internal subsequence). For symmetric crossover (two offspring per crossing), call this method twice:

$kid1 = _xover2($mom, $dad, $points1, $points2);
$kid2 = _xover2($dad, $mom, $points1, $points2);

_xover2 does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

xover1

Signature: (mom(G); dad(G); float+ rate(); [o]kid(G))

Random single-point crossover. Calls _xover1().

xover2

Signature: (mom(G); dad(G); float+ rate(); [o]kid(G))

Random dial-point crossover. Calls _xover2().

ACKNOWLEDGEMENTS

Perl by Larry Wall.

PDL by Karl Glazebrook, Tuomas J. Lukka, Christian Soeller, and others.

KNOWN BUGS

Probably many.

AUTHOR

Bryan Jurish <moocow@cpan.org<gt>

Copyright (C) 2006-2007, Bryan Jurish. All rights reserved.

This package is free software, and entirely without warranty. You may redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), PDL(3perl).