You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: transition probability calculation feature #205
It would be great to have a method (terminology- am I using this correctly?) for calculating transition probabilities.
In the following code (which is a function right now), I am adding a 'Y' symbol at the start of every bout, as is tradition in the Veit lab, before calculating transition matrix and count matrix (matrix with just the counts, useful for chi-sq test as described in Koparkar*,Warren*, et.al, 2024)
import vocalpy as voc
from collections import Counter
def transition_prob_calc(annots):
"""
annots = list of annotations (voc.annot!) you want to include in this calculation
Returns:
Transition mtx as a dictionary, count mtx as a dictionary
"""
#add a 'Y' placeholder before every bout and join them
marked_bouts = [''.join(['Y',''.join(a.data.seq.labels)]) for a in annots]
# add 'Y' at the end to signify end and join all bouts in one long string
allbouts = ''.join(marked_bouts)
allboutsY = ''.join([allbouts,'Y'])
c_mtx = dict(Counter(zip(allboutsY[:-1], allboutsY[1:]))) # count mtx
# Calculate the total outgoing weight for each starting nod
outgoing_sums = {}
for (start, end), weight in c_mtx.items():
outgoing_sums[start] = outgoing_sums.get(start, 0) + weight
# Normalize the weights
t_mtx = {
edge: weight*100 / outgoing_sums[edge[0]] for edge, weight in c_mtx.items()
}
return t_mtx, c_mtx
Excellent, thank you @avanikop -- agree we want a function like this, I think it will probably live in a syntax module, something like vocalpy.syntax.transmat
Activity
NickleDave commentedon Jan 13, 2025
Excellent, thank you @avanikop -- agree we want a function like this, I think it will probably live in a
syntaxmodule, something likevocalpy.syntax.transmatNickleDave commentedon Jan 13, 2025
@all-contributors please add @avanikop for ideas
allcontributors commentedon Jan 13, 2025
@NickleDave
I've put up a pull request to add @avanikop! 🎉
NickleDave commentedon Jan 13, 2025
For future reference, there's this code from the TweetyNet article that does something similar:
https://github.com/yardencsGitHub/tweetynet/blob/eab406f0590f4e90a36530cada52a78b0c676a80/article/src/article/bfbehav/sequence.py
[-]ENH: transition probability calcualtion feature[/-][+]ENH: transition probability calculation feature[/+]