Home > Software engineering >  How can I compute the chance of going into a certain state, given the current state?
How can I compute the chance of going into a certain state, given the current state?

Time:05-03

I am trying to compute the change of going into a certain state, given the current state.

I need this for a simulation that I am doing as my machine needs to know what state it go into next, what these chances are and also the length of time before this state change happens.

So for now I am not focusing on the time aspect, just the state changes.

So my question is: Given a current state which state will the machine go into next and what are these chances.

Here is a reproducible sample of my dataframe:

df = pd.DataFrame({'CurrentState': {'2022-02-01 00:20:00': '128',
  '2022-02-01 00:21:00': '1024',
  '2022-02-01 00:22:00': '128',
  '2022-02-01 00:23:00': '1024',
  '2022-02-01 00:34:00': '128',
  '2022-02-01 00:35:00': '1024',
  '2022-02-01 00:37:00': '128',
  '2022-02-01 00:42:00': '16',
  '2022-02-01 00:43:00': '8',
  '2022-02-01 00:47:00': '128'},
 'Next_State': {'2022-02-01 00:20:00': '1024',
  '2022-02-01 00:21:00': '128',
  '2022-02-01 00:22:00': '1024',
  '2022-02-01 00:23:00': '128',
  '2022-02-01 00:34:00': '1024',
  '2022-02-01 00:35:00': '128',
  '2022-02-01 00:37:00': '16',
  '2022-02-01 00:42:00': '8',
  '2022-02-01 00:43:00': '128',
  '2022-02-01 00:47:00': '16'},
 'State_Change': {'2022-02-01 00:20:00': '128-1024',
  '2022-02-01 00:21:00': '1024-128',
  '2022-02-01 00:22:00': '128-1024',
  '2022-02-01 00:23:00': '1024-128',
  '2022-02-01 00:34:00': '128-1024',
  '2022-02-01 00:35:00': '1024-128',
  '2022-02-01 00:37:00': '128-16',
  '2022-02-01 00:42:00': '16-8',
  '2022-02-01 00:43:00': '8-128',
  '2022-02-01 00:47:00': '128-16'}})

CodePudding user response:

The probability is the number of recorded occurrences relative to the total. This is easily done with value_counts using the normalize=True parameter:

df['State_Change'].value_counts(normalize=True)

output:

128-1024    0.3
1024-128    0.3
128-16      0.2
16-8        0.1
8-128       0.1
Name: State_Change, dtype: float64
  • Related