Skip to main content

A variant of MTrees, where NonLeafNodes do not propagate splits to the parent, but combine routing objects downwards

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

downward_mtree-1.0.4-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file downward_mtree-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: downward_mtree-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for downward_mtree-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 00941df6ed6dffbdb53dabb01884cc79dbfd798a8b87a031c9feaf5a52a2e301
MD5 cb0e060fdb3b7a2fef910969a96681c4
BLAKE2b-256 417e9673456381473f0fc84397960cea861b424e4042fb123f5c639b6afe9a7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page