Skip to content

Instantly share code, notes, and snippets.

@MortenHegewald
Last active November 17, 2019 20:12
Show Gist options
  • Save MortenHegewald/7a1f6328e7391ade99ab8e66e0611b05 to your computer and use it in GitHub Desktop.
Save MortenHegewald/7a1f6328e7391ade99ab8e66e0611b05 to your computer and use it in GitHub Desktop.
MA - trans prob
def transition_prob(trans_dict):
list_of_unique_channels = set(x for element in list_of_paths for x in element)
trans_prob = defaultdict(dict)
for state in list_of_unique_channels:
if state not in ['Conversion', 'Null']:
counter = 0
index = [i for i, s in enumerate(trans_dict) if state + '>' in s]
for col in index:
if trans_dict[list(trans_dict)[col]] > 0:
counter += trans_dict[list(trans_dict)[col]]
for col in index:
if trans_dict[list(trans_dict)[col]] > 0:
state_prob = float((trans_dict[list(trans_dict)[col]])) / float(counter)
trans_prob[list(trans_dict)[col]] = state_prob
return trans_prob
trans_prob = transition_prob(trans_states)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment