Dictances
Distances and divergences between discrete distributions described as dictionaries implemented in python.
These are meant as fast solutions to compute distances and divergences between discrete distributions, expecially when the two distributions contains a significant amount of events with nill probability which are not described in the dictionaries.
How do I install this package?
As usual, just download it using pip:
pip install dictances
Available metrics
A number of distances and divergences are available:
Distances |
Methods |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Usage example with points
Suppose you have a point described by my_first_dictionary and another one described by my_second_dictionary:
from dictances import cosine
my_first_dictionary = {
"a": 56,
"b": 34,
"c": 89
}
my_second_dictionary = {
"a": 21,
"d": 51,
"e": 74
}
cosine(my_first_dictionary, my_second_dictionary)
#>>> 0.8847005261889619
Usage example with distributions
Suppose you have a point described by my_first_dictionary and another one described by my_second_dictionary:
from dictances import bhattacharyya, bhattacharyya_coefficient
a = {
"event_1": 0.4,
"event_2": 0.1,
"event_3": 0.2,
"event_4": 0.3,
}
b = {
"event_1": 0.1,
"event_2": 0.2,
"event_5": 0.2,
"event_9": 0.5,
}
bhattacharyya_coefficient(a, b)
#>>> 0.3414213562373095
bhattacharyya(a, b)
#>>> 1.07463791569453
Handling nested dictionaries
If you need to compute the distance between two nested dictionaries you can use deflate_dict as follows:
from dictances import cosine
from deflate_dict import deflate
my_first_dictionary = {
"a": 8,
"b": {
"c": 3,
"d": 6
}
}
my_second_dictionary = {
"b": {
"c": 8,
"d": 1
},
"y": 3,
}
cosine(deflate(my_first_dictionary), deflate(my_second_dictionary))
Metadata
Release files for dictances 1.5.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dictances-1.5.6.tar.gz | 8.3 kB | Without provenance | Details for dictances-1.5.6.tar.gz |
Release files / dictances-1.5.6.tar.gz
| Download URL | dictances-1.5.6.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c94cefa990d8301a225e82acd368f58612830b373572a7a677b8fab2dcde20b3
|
|
BLAKE2b-256 checksum How to use checksums |
aeee79ce1e09ca9cc22f5da12fd7557afb312824b1baa90eb9d27b7fea77a4ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9
|
Security for dictances 1.5.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.