https://github.com/boppreh/markov
Markov chain library to create new data from examples
https://github.com/boppreh/markov
Last synced: 2 months ago
JSON representation
Markov chain library to create new data from examples
- Host: GitHub
- URL: https://github.com/boppreh/markov
- Owner: boppreh
- License: other
- Created: 2013-05-16T19:05:16.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-10-12T20:31:19.000Z (over 8 years ago)
- Last Synced: 2025-01-25T23:34:15.383Z (4 months ago)
- Language: Python
- Homepage:
- Size: 225 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
markov
======`markov` is a very simple implementation of the Markov chain algorithm.
It is useful for creating new data (especially text) from examples. For
example, you could give it a book's text and ask it to write a completely
new paragraph.There are two ways to use this library:
`predict(previous, length=1, prefix_size=2)`
--------------------------------------------Given a list of items, predicts the next `length` items in the sequence.
`prefix_size` is a parameter to the algorithm that roughly dictates how
much of the original data should be used. A value of 0 will produce
completely random values sampled from the original data, while a value
of 2 or 3 may fool casual observers when generating text. The greater
the `prefix_size` value, the more data you need to avoid repetition.class Markov
------------
The `Markov` class gives a more fine-grained control over the process.
You initialize it with the desired prefix size (see above for a description
of its function) and an optional data source. New data sources can be added
by using the `learn` method.The method `chain(length=1, prefix=[])` generates a new chain of `length`
items, based on the data already given, and starting from `prefix`.You can access the inner statistical model using the attribute `stats`, which
is in the format {prefix: {candidate: weight}}.