r/madeinpython • • 16h ago

We built sentropy, a Python package for measuring diversity while accounting for similarities between data points

Hi Python community!

I'd like to share an open-source Python package that I've co-authored: sentropy.

The motivation behind it is that traditional entropy measures, such as Shannon entropy, treat every distinct element as completely different. But in many datasets, distinct elements can be very similar to one another.

For example, consider a dataset of protein sequences. Two sequences that differ by a single amino acid are arguably more similar than two sequences that differ at every position. Traditional Shannon entropy doesn't capture this distinction.

Sentropy implements similarity-sensitive entropy measures, based on the mathematical framework developed by Leinster, Cobbold and Reeve.

A few things you can do with it:

  • Calculate similarity-sensitive α, β and γ diversity.
  • Explore different viewpoints using the parameter q.
  • Pass your own similarity matrix or define a custom similarity function.
  • Calculate similarities on the fly, without explicitly constructing a potentially large similarity matrix.
  • Calculate relative sentropy and cross-sentropy.
  • Use PyTorch/GPU functionality.
  • Calculate the Vendi score.

It's not restricted to biological data, either. The package can work with any dataset for which you can define a meaningful similarity function.

For example, the README includes demonstrations using amino-acid sequences and image datasets.

Installation:

pip install sentropy

Links:

I'd love to hear what you think! In particular, I'm interested in how people might use similarity-sensitive diversity measures in machine learning, data analysis, or other areas outside bioinformatics.

Feedback, suggestions, and contributions are welcome!

1 Upvotes

0 comments sorted by