Distances and divergences between distributions implemented in python.
Project description
Distances and divergences between dictionaries implemented in python 3.6.
In the complexity notations, n
is len(a)
and m
is len(b)
.
The samples are dictionaries generated by the test utilities here.
Basic example
For each metric, an example is present in the folder examples. Here’s a basic example for those too lazy to click links (like me).
import random
from dictances import cosine
random.seed(42) # for reproducibility
# Simple function to generate the example dictionaries
def generate_example_dict(n=1000):
return {random.randint(0,1000):random.uniform(0,1000) for i in range(n)}
a, b = generate_example_dict(), generate_example_dict()
print(cosine(a,b))
# >>> 0.52336690346601
print(euclidean(a,b))
# >>> 15119.400349404095
print(canberra(a,b))
# >>> 624.9088876554047
Metrics table
Metric name |
Usage example |
Average time on sample |
Complexity |
---|---|---|---|
53.7 µs ± 981 ns |
|||
Squared variation |
50.6 µs ± 982 ns |
||
50.6 µs ± 2.75 µs |
|||
Nth variation |
50.6 µs ± 1.07 µs |
||
51 µs ± 1.2 µs |
|||
51.9 µs ± 2.4 µs |
|||
51.8 µs ± 1.67 µs |
|||
49.8 µs ± 628 ns |
|||
50.4 µs ± 2.94 µs |
|||
30.9 µs ± 340 ns |
|||
41.7 µs ± 1.42 µs |
|||
49.8 µs ± 2.51 µs |
|||
5.57 µs ± 191 ns |
|||
31.6 µs ± 591 ns |
|||
21.1 µs ± 442 ns |
|||
13.7 µs ± 71.9 ns |
|||
16.8 µs ± 372 ns |
Test computer specifications
The computer on which the metrics where timed had the following specifications:
Computer specifications |
|
---|---|
Model Name |
MacBook Pro |
Processor Name |
Intel Core i7 |
Processor Speed |
2.3 GHz |
Number of Processors |
1 |
Total Number of Cores |
4 |
L2 Cache (per Core) |
256 KB |
L3 Cache |
6 MB |
Memory |
16 GB |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dictances-1.1.0.tar.gz
.
File metadata
- Download URL: dictances-1.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b41d70cb4dd68a29db614dde572d3337b7f750751bd2417f38ab19dba1e646d0 |
|
MD5 | a37a93fded75744dd10f2b9edc746c4c |
|
BLAKE2b-256 | d834aa48dfc60ed0551e52036e1e7c335319154e27311f0a1c905aecaf2f5ff5 |