ConsoleUser

Copyright (c) 2010-2023 Skaion Corporarion, www.skaion.com

This project was developed in part by numerous sponsorships from the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints of Governmental purposes notwithstanding any copyright notation thereon.

All content reflects those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of the U.S. Government or Skaion Corporation.

class MarkovChooser.MarkovChooser(dist='uniform', args=(), seed=None, config=None)

This implements <no title> to make choices based on the current state. This assumes that it is a 1st order matrix.

Parameters:

  • dist: the name of the distrbution to use

  • args: a tuple of any arguments the distribution needs during initialization

  • seed: the seed to give to the random number generator

get_all_choices()

Return a set of all possible choices in this matrix.

get_keys()

Return: a list of all the keys in the transition matrix

get_values()

Return a set of all values that could be states in the matrix

is_state(state)

Parameters:

  • state: a potential state in the matrix

Return: True iff state is an actual state, False otherwise

load_from_db(cursor, query, func=None)

Load the values based on the results of a DB query rather than reading from a file.

Parameters:

  • cursor: a database object conforming to the python DB-API

  • query: an SQL query that will return th eresults as a Markov matrix

  • func: optionally a value that will transform state names taking the state name as an argument and returning the transformed name

load_from_file(path, func=None)

Load our transition matrices from the file, including the special “init” state which is used when there is no known current state, such as when the first choice is made or when a state has no valid next states.

Parameters:

  • path: the path to the file to load

  • func: optionally a function to that will take the name of the current state as an argument

load_string(line, func=None)

Load a state from a string. The string should look like a line from a markov file.

Parameters:

  • line: the string to load

  • func: optionally a function transforming state names

next_choice()

Return: the next choice

num_choices()

Return: the number of potential states in the transition matrix

reset()

Reset the markov chain to its initial state

set_state(state)

Update the current state. This is to support external modification of the state changes, as someone may wish to make a particular choice at some point in time and then continue from there.

This call will reset back to the initial state if the given state is not valid for this Chooser.

Parameters:

  • state: the new current state

MarkovChooser.test(iters)

Repeat the test some number of times and make sure it each method of loading produces expected results at some scale.

Parameters:

  • iters: the int number of iterations to repeat the test