Skip to content
A Markov Chain class and some fun stuff I did with it
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
licence.txt
markov.py
word-game.py
word-learning.py

README.md

markov

A Markov Chain class and some fun stuff I did with it

Useage

Import the markov class with:

from markov import markov

The first thing you will need to do is create a markov object:

Markov = markov()

To train the markov chain simply use:

Markov.record( previous, current )

previous is the nth item in the sequence. current is the n+1th item in the sequence.

Once the object is trained on all of your data, you simply use:

Markov.predict( current )

current is the nth item in the sequence and this function will return the n+1th item in the sequence or None if there is no data to base the decision off of.

Samples

word-learning.py is a sample program using the markov class designed to learn how to write based on a set of text that it reads. To run this program use python word-learning.py <filename> where <filename> is the name of the file that contains the learning text. This program will also dump it's object as hidden files and load them back up on each run to save on computational time, if you change your text files make sure you delete the hidden files too.

You can’t perform that action at this time.