09 May 2004 01:59:47 UTC
- Distribution: Algorithm-MarkovChain
- Module version: 0.06
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (599 / 3 / 1)
- KwaliteeBus factor: 0
- 72.12% Coverage
- License: perl_5
- Download (4.85KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:
Algorithm::MarkovChain - Object oriented Markov chain generator
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 ) ]);
Algorithm::MarkovChain is an implementation of the Markov Chain algorithm within an object container.
It is implemented as a base class,
Algorithm::MarkovChain::Base, with storage implementations of a hash (
Algorithm::MarkovChain), and an fairly memory efficent implementation using
Algorithm::MarkovChain::GHash). DBI and MLDBM-friendly versions are planned.
Deriving alternate representations is intended to be straightforward.
- Algorithm::MarkovChain::->new() or $obj->new()
Creates a new instance of the Algorithm::MarkovChain class.
Takes one optional parameter:
recover_symbolshas 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.
Seeds the markov chains from an example symbol stream.
Takes two parameters, one required
symbols, one optional
symbolspresents the symbols to seed from
longestsets an upper limit on the longest chain to construct. (defaults to 4)
Uses the constructed chains to produce symbol streams
Takes four optional parameters
completeprovides 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.
lengthspecifies the minimum number of symbols desired (default is 30)
stop_at_terminaldirects the spew to stop chaining at the first terminal point reached
force_lengthensures you get exactly
lengthsymbols returned (note this overrides the behaviour of
strict_startmakes the spew operation always take a known start state rather than selecting a sequence at random
- $obj->increment_seen($sequence, $symbol)
Increments the seeness of a symbol following a sequence.
Recompute the probabilities for a branch of the tree. Called towards the end of the seed operation for 'dirty' sequences.
Returns possible next symbols and probablities as a hash.
I need to explain Markov Chains, and flesh out the examples some more.
- Fix bugs/respond to feature requests
Just email me <email@example.com> and I'll hit it with hammers...
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 :)
Richard Clamp <firstname.lastname@example.org>
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 180:
You forgot a '=back' before '=head2'
- Around line 184:
=back without =over
Module Install Instructions
To install Algorithm::MarkovChain, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Algorithm::MarkovChain
For more information on module installation, please visit the detailed CPAN module installation guide.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|