-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.py
More file actions
21 lines (18 loc) · 828 Bytes
/
state.py
File metadata and controls
21 lines (18 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'''
State class. A Markov Chain consists of states.
Every state has an ID (str) and connections to other states (and/or itself).
The connections are equipped with a probability; how probable is it to transition from state A to state B in the next step.
'''
class State:
def __init__(self, id):
self.__id = id
self.__connections = {} # dictionary contains the state's connections and
# their probabilities, P(self-loop)=0 by default
def createConnection(self, state, P):
'''Creates a connection to another state. Function overwrites an existing connection with a new P'''
self.__connections[state] = P
def getConnections(self):
return self.__connections
def __str__(self):
desc = f"ID: {self.__id}\n"
# TODO