graphs.markov_chain

Classes

MarkovChainGraphUndirectedUnweighted

Undirected Unweighted Graph for running Markov Chain Algorithm

Functions

get_transitions(→ dict[str, int])

Running Markov Chain algorithm and calculating the number of times each node is

Module Contents

class graphs.markov_chain.MarkovChainGraphUndirectedUnweighted

Undirected Unweighted Graph for running Markov Chain Algorithm

add_node(node: str) None
add_transition_probability(node1: str, node2: str, probability: float) None
get_nodes() list[str]
transition(node: str) str
connections
graphs.markov_chain.get_transitions(start: str, transitions: list[tuple[str, str, float]], steps: int) dict[str, int]

Running Markov Chain algorithm and calculating the number of times each node is visited

>>> transitions = [
... ('a', 'a', 0.9),
... ('a', 'b', 0.075),
... ('a', 'c', 0.025),
... ('b', 'a', 0.15),
... ('b', 'b', 0.8),
... ('b', 'c', 0.05),
... ('c', 'a', 0.25),
... ('c', 'b', 0.25),
... ('c', 'c', 0.5)
... ]
>>> result = get_transitions('a', transitions, 5000)
>>> result['a'] > result['b'] > result['c']
True