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

Algorithm::MarkovChain - Object oriented Markov chain generator

SYNOPSIS

  use Algorithm::MarkovChain;

  my $chain = Algorithm::MarkovChain::->new();

  # learn about things from @symbols
  $chain->seed(symbols => \@symbols,
               longest => 6);

  # attempt to tell me something about the sky
  my @newness = $chain->spew(length   => 20,
                             complete => [ qw( the sky is ) ]);

DESCRIPTION

Algorithm::MarkovChain is an implementation of the Markov Chain algorithm within an object container.

METHODS

Algorithm::MarkovChain::->new() or $obj->new()

Creates a new instance of the Algorithm::MarkovChain class.

Takes one optional parameter: recover_symbols

recover_symbols has meaning if your symbols differ from their true values when stringifyed. With this option enabled steps are taken to ensure that the original values for symbols are returned by the spew method.

$obj->seed()

Seeds the markov chains from an example symbol stream.

Takes two parameters, one required symbols, one optional longest

symbols presents the symbols to seed from

longest sets an upper limit on the longest chain to construct. (defaults to 4)

$obj->spew()

Uses the constructed chains to produce symbol streams

Takes two optional parameters length and complete

length specifies the number of symbols to produce (default is 30)

complete provides a starting point for the generation of output. Note: the algorithm will discard elements of this list if it does not find a starting chain that matches it, this is infinite-loop avoidance.

TODO

Documentation

I need to explain Markov Chains, and flesh out the examples some more.

Serialization interface

Currently seeding the chain list is very intensive, and so there should be a useful way to serialize objects of Algorithm::MarkovChain.

With the current implementation there are no private object variables, so it's possible to cheat and just freeze the raw object, but I wouldn't want for people to rely on that.

Fix bugs/respond to feature requests

Just email me <richardc@unixbeard.net> and we'll sort something out...

BUGS

Hopefully not, though if they probably arise from my not understanding Markov chaining as well as I thought I did when coding commenced.

That or they're jst stupid mistakes :)

AUTHOR

Richard Clamp <richardc@unixbeard.net>

SEE ALSO

perl(1).