{"id":15647492,"url":"https://github.com/lucacappelletti94/dictances","last_synced_at":"2025-10-18T04:39:51.096Z","repository":{"id":57418140,"uuid":"132608548","full_name":"LucaCappelletti94/dictances","owner":"LucaCappelletti94","description":"Distances and divergences between distributions implemented in the best way I found in python.","archived":false,"fork":false,"pushed_at":"2024-07-06T19:20:08.000Z","size":215,"stargazers_count":46,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T03:34:56.035Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucaCappelletti94.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"LucaCappelletti94"}},"created_at":"2018-05-08T12:52:15.000Z","updated_at":"2025-01-21T07:17:56.000Z","dependencies_parsed_at":"2024-07-06T22:15:57.824Z","dependency_job_id":null,"html_url":"https://github.com/LucaCappelletti94/dictances","commit_stats":{"total_commits":203,"total_committers":2,"mean_commits":101.5,"dds":"0.11330049261083741","last_synced_commit":"13665ff8a09765811b2465a61f72442ba371f530"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fdictances","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fdictances/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fdictances/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucaCappelletti94%2Fdictances/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucaCappelletti94","download_url":"https://codeload.github.com/LucaCappelletti94/dictances/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248349413,"owners_count":21089041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:19:38.988Z","updated_at":"2025-10-18T04:39:46.035Z","avatar_url":"https://github.com/LucaCappelletti94.png","language":"Python","readme":"# Dictances\n\n[![pip](https://badge.fury.io/py/dictances.svg)](https://pypi.org/project/dictances/)\n[![downloads](https://pepy.tech/badge/dictances)](https://pepy.tech/project/dictances)\n[![license](https://img.shields.io/github/license/LucaCappelletti94/dictances)](https://github.com/LucaCappelletti94/dictances/blob/master/LICENSE)\n[![python versions](https://img.shields.io/pypi/pyversions/dictances)](https://www.python.org/downloads/)\n[![GitHub actions](https://github.com/LucaCappelletti94/dictances/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/dictances/actions/)\n\nDistances and divergences between discrete distributions described as dictionaries implemented in Python.\n\nThese are meant as fast solutions to compute distances and divergences between discrete distributions, especially when the two distributions contain a significant amount of events with nil probability which are not described in the dictionaries.\n\nFind the complete list just below.\n\n## How do I install this package?\n\nAs usual, just download it using pip:\n\n```shell\npip install dictances\n```\n\n## Available metrics\n\nA number of distances and divergences are available:\n\n| Distances                                                                                                   | Methods                                     |\n| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------- |\n| [Bhattacharyya distance](https://en.wikipedia.org/wiki/Bhattacharyya_distance)                              | `bhattacharyya`                             |\n| [Bhattacharyya coefficient](https://en.wikipedia.org/wiki/Bhattacharyya_distance#Bhattacharyya_coefficient) | `bhattacharyya_coefficient`                 |\n| [Canberra distance](https://en.wikipedia.org/wiki/Canberra_distance)                                        | `canberra`                                  |\n| [Chebyshev distance](https://en.wikipedia.org/wiki/Chebyshev_distance)                                      | `chebyshev`                                 |\n| [Chi Square distance](https://en.wikipedia.org/wiki/Chi-squared_test)                                       | `chi_square`                                |\n| [Cosine Distance](https://en.wikipedia.org/wiki/Cosine_similarity)                                          | `cosine`                                    |\n| [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance)                                      | `euclidean`                                 |\n| [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance)                                          | `hamming`                                   |\n| [Jensen-Shannon divergence](https://en.wikipedia.org/wiki/Jensen%E2%80%93Shannon_divergence)                | `jensen_shannon`                            |\n| [Kullback-Leibler divergence](https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence)            | `kullback_leibler`                          |\n| [Mean absolute error](https://en.wikipedia.org/wiki/Mean_absolute_error)                                    | `mae`                                       |\n| [Taxicab geometry](https://en.wikipedia.org/wiki/Taxicab_geometry)                                          | `manhattan`, `cityblock`, `total_variation` |\n| [Minkowski distance](https://en.wikipedia.org/wiki/Minkowski_distance)                                      | `minkowsky`                                 |\n| [Mean squared error](https://en.wikipedia.org/wiki/Mean_squared_error)                                      | `mse`                                       |\n| [Pearson's distance](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient#Pearson's_distance)      | `pearson`                                   |\n| [Squared deviations from the mean](https://en.wikipedia.org/wiki/Squared_deviations_from_the_mean)          | `squared_variation`                         |\n\n## Usage example with points\n\nSuppose you have a point described by `my_first_dictionary` and another one described by `my_second_dictionary`:\n\n```python\nfrom dictances import cosine\n\nmy_first_dictionary = {\n    \"a\": 56,\n    \"b\": 34,\n    \"c\": 89\n}\n\nmy_second_dictionary = {\n    \"a\": 21,\n    \"d\": 51,\n    \"e\": 74\n}\n\ncosine(my_first_dictionary, my_second_dictionary)\n#\u003e\u003e\u003e 0.8847005261889619\n```\n\n## Usage example with distributions\n\nSuppose you have a point described by `my_first_dictionary` and another one described by `my_second_dictionary`:\n\n```python\nfrom dictances import bhattacharyya, bhattacharyya_coefficient\n\na = {\n    \"event_1\": 0.4,\n    \"event_2\": 0.1,\n    \"event_3\": 0.2,\n    \"event_4\": 0.3,\n}\nb = {\n    \"event_1\": 0.1,\n    \"event_2\": 0.2,\n    \"event_5\": 0.2,\n    \"event_9\": 0.5,\n}\n\nbhattacharyya_coefficient(a, b)\n#\u003e\u003e\u003e 0.3414213562373095\nbhattacharyya(a, b)\n#\u003e\u003e\u003e 1.07463791569453\n```\n\n## Handling nested dictionaries\n\nIf you need to compute the distance between two nested dictionaries you can use [`deflate_dict`](https://github.com/LucaCappelletti94/deflate_dict) as follows:\n\n```python\nfrom dictances import cosine\nfrom deflate_dict import deflate\n\nmy_first_dictionary = {\n    \"a\": 8,\n    \"b\": {\n        \"c\": 3,\n        \"d\": 6\n    }\n}\n\nmy_second_dictionary = {\n    \"b\": {\n        \"c\": 8,\n        \"d\": 1\n    },\n    \"y\": 3,\n}\n\ncosine(deflate(my_first_dictionary), deflate(my_second_dictionary))\n```\n\n## License\nThis software is distributed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n\n## How to contribute\nIf you want to contribute to the project and make it better, your help is very welcome. If you find a bug, please raise an issue with all the minimal code necessary to reproduce it. If you have a feature request, please open an adequately detailed issue to discuss it before starting to work on it in a pull request.\n","funding_links":["https://github.com/sponsors/LucaCappelletti94"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacappelletti94%2Fdictances","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucacappelletti94%2Fdictances","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucacappelletti94%2Fdictances/lists"}