Last active
November 17, 2019 20:12
-
-
Save MortenHegewald/7a1f6328e7391ade99ab8e66e0611b05 to your computer and use it in GitHub Desktop.
MA - trans prob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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