scamp_extensions.process.markov.MarkovModel

class scamp_extensions.process.markov.MarkovModel(data: Optional[Sequence] = None, max_order: int = 1, cyclic: bool = True)[source]

Bases: object

A Markov analysis-synthesis tool that analyzes the given data, and can generate new data based on the same statistical patterns.

Parameters:
  • data – A sequence of states whose transition probabilities to analyze (can train after instantiating too)

  • max_order – The maximum order of Markov analysis to perform

  • cyclic – Whether or not to treat the data as cyclic. (If not, resynthesis can reach a dead end.)

Methods

generate(num_values, order[, ...])

Generates a sequence of states following the Markov analysis performed on the input data.

get_iterator(order[, start_values, keep_looping])

Returns a MarkovIterator based on this model.

move(state[, random_func])

Do one step from the indicated state, and return the final state.

move_zeroth_order()

Returns a randomly selected state (weighted by frequency).

train(data[, cyclic])

move_zeroth_order()[source]

Returns a randomly selected state (weighted by frequency).

generate(num_values: int, order: float, initial_history: Optional[Sequence] = None, keep_looping: bool = False) Sequence[source]

Generates a sequence of states following the Markov analysis performed on the input data.

Parameters:
  • num_values – How many states to generate.

  • order – The Markov order used in generating new states. Can be floating point, in which case the order for any given move is a weighted random choice between the adjacent integer orders.

  • initial_history – Values with which to seed the state history. If none, simply starts at random state from within the data set.

  • keep_looping – if True, then when we hit a dead end, keep reducing the order by one until we find a next move (once it gets to order zero, it just chooses randomly)

move(state, random_func=None)[source]

Do one step from the indicated state, and return the final state. Optionally, a function that generates a random number can be supplied.

train(data, cyclic=True)[source]
get_iterator(order: float, start_values: Optional[Sequence] = None, keep_looping: bool = False) MarkovIterator[source]

Returns a MarkovIterator based on this model.

Parameters:
  • order – the Markov order to use in generating new states. Can be floating point (see MarkovIterator), and can be altered during iteration.

  • start_values – Values with which to seed the iterator’s history. If none, simply starts at random state from within the data set.

  • keep_looping – if True, then when we hit a dead end, keep reducing the order by one until we find a next move (once it gets to order zero, it just chooses randomly)