Suppose I have several different states in the form of an Enum:
class State(Enum):
State1 = 1
State2 = 2
State3 = 3
I define transition probabilities between the states:
transition_probabilities = [
[0.8, 0.1, 0.1],
[0.2, 0.5, 0.3],
[0.3, 0.3, 0.4]
]
I know have a selection of different objects in the form of dataclasses that have as an attribute a particular state:
@dataclass
class Thing:
name: str
state: State
things = [
Thing('a', State.State1),
Thing('b', State.State1),
Thing('c', State.State2),
Thing('d', State.State2),
Thing('e', State.State2),
Thing('f', State.State3),
]
What I'd like to do is generate a sequence of objects using something like random.choices
where the probability of sampling the next object depends on the state of the current object, eg if my first object is Thing('a', State.State1)
, then I have an 80% chance of sampling from [Thing('a', State.State1), Thing('b', State.State1)]
, a 10% chance of sampling from the State2 things and a 10% chance of sampling from the State3 things, and similarly with the other transition probabilities.
Edit: To clarify, if I start with an object in state 1 then I want to transition to a new state with the defined probabilities and then uniformly sample a single object from the objects that have the state that I transitioned to. I want to repeat this until I've generated a sequence of a set length (eg 20)
I can't think of a good way to do this using this current set up - is it possible and if not how should I set it up so that it is?
Thank you!