D-MTree (Downward-MTree)
This library implements a datastructure very similar to the MTree datastructure in pure python (for more information, see https://en.wikipedia.org/wiki/M-tree)
The main difference is that the split of a NonLeafNode (inner node) will not propagate to the parent node, but instead creates a new subtree with the two closest routing objects as descendants.
- This has the advantage that the covering-radii of the NonLeafNodes have the least overlap.
- The disadvantage is that if the points are added in an unlucky order, the depth of the tree can grow very fast!
Usage
def distance(p1, p2):
return abs(p1 - p2)
dmtree = DMTree(distance_measure=distance, leaf_node_capacity=10, inner_node_capacity=5)
# inserting 1000 values with equal identifier:
for i in range(1000):
dmtree.insert(identifier=i, value=i)
# search in radius and order them by distance (ascending):
elements = dmtree.find_in_radius(value=50.5, radius=1)
# find the 10 nearest neighbours and order them by distance (ascending):
# the parameter 'truncate' decides if the results is trimmed to exactly k if there are multiple elements with the same distance
elements = dmtree.knn(value=50.5, k=10, truncate=True)
# deleting entries
for identifier in range(1000):
dmtree.remove(identifier)
- identifier should be a datatype that can be compared with ==, <=, >=, <, >
- mtree.knn(value, k, truncate=True) is equal to mtree.knn(value, k, truncate=False)[:k]
Parameters
| Parameter | Description |
|---|---|
| distance_measure | Custom distance method that fulfills the triangle inequality |
| leaf_node_capacity | The number of children a NonLeafNode can hold before it is split (>=2) Default=50 |
| inner_node_capacity | The number of objects a LeafNode can hold before it is split (>=2) Default=20 |
| split_method | The algorithm that splits overflowing LeafNodes Default='max_distance' |
Split methods
| Parameter | Description |
|---|---|
| random | Choose two random elements of the LeafNode as new routing objects |
| min_sum_radii | Choose the two elements of the LeafNode that minimizes the sum of the resulting radii |
| max_distance | Choose the two elements of the LeafNode that maximizes the distance between the routing values |
Best practice
- When inserting the values, do so in a randomized order, or the resulting tree can very quickly become heavily unbalanced
Release files for downward-mtree 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| downward_mtree-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Release files / downward_mtree-1.0.4-py3-none-any.whl
| Download URL | downward_mtree-1.0.4-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00941df6ed6dffbdb53dabb01884cc79dbfd798a8b87a031c9feaf5a52a2e301
|
|
BLAKE2b-256 checksum How to use checksums |
417e9673456381473f0fc84397960cea861b424e4042fb123f5c639b6afe9a7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
|