Skip to content

ENH: transition probability calculation feature #205

Open

Description

@avanikop

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

Activity

  1. added
    ENH: enhancement
    on Jan 13, 2025
  2. NickleDave commented on Jan 13, 2025

    @NickleDave
    Contributor

    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

  3. NickleDave commented on Jan 13, 2025

    @NickleDave
    Contributor

    @all-contributors please add @avanikop for ideas

  4. allcontributors commented on Jan 13, 2025

    @allcontributors
    Contributor

    @NickleDave

    I've put up a pull request to add @avanikop! 🎉

  5. NickleDave commented on Jan 13, 2025

    @NickleDave
    Contributor
  6. changed the title [-]ENH: transition probability calcualtion feature[/-] [+]ENH: transition probability calculation feature[/+] on Jul 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ENH: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions