{ "info": { "author": "Marcell Vazquez-Chanlatte", "author_email": "marcell.vc@eecs.berkeley.edu", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# Lazy Tree\n\n[![Build Status](https://cloud.drone.io/api/badges/mvcisback/pyLazyTree/status.svg)](https://cloud.drone.io/mvcisback/pyLazyTree)\n[![codecov](https://codecov.io/gh/mvcisback/DiscreteSignals/branch/master/graph/badge.svg)](https://codecov.io/gh/mvcisback/pyLazyTree)\n[![PyPI version](https://badge.fury.io/py/lazytree.svg)](https://badge.fury.io/py/lazytree)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [View the current root.](#view-the-current-root)\n\n\n\n\n# Installation\n\nIf you just need to use `lazytree`, you can just run:\n\n`$ pip install lazytree`\n\nFor developers, note that this project uses the\n[poetry](https://poetry.eustace.io/) python package/dependency\nmanagement tool. Please familarize yourself with it and then\nrun:\n\n`$ poetry install`\n\n# Usage\n\nA `LazyTree` is a triple, `(root, child_map, view)` where `root : A`\nand a child map, `child_map`, which maps `a` to a (finite) list of\nchildren `child_map : A -> List[A]` define the tree's structure and\n`view : A -> B` defines what the tree represents. The default view is\nthe identity map, `lambda x: x`.\n\nThis structure is useful for modeling infinite (or really large) trees\nwhere only a finite number of nodes need to be accessed. For example,\nthe following Binary tree represents the recursive subdivision of the\ninterval [0, 1].\n\n```python\nfrom lazytree import LazyTree\n\ndef split(itvl):\n lo, hi = itvl\n mid = lo + (hi - lo)/2\n return (lo, mid), (mid, hi)\n\ntree = LazyTree(\n root=(0, 1), # Initial Itvl\n child_map=split # Itvl -> [Itvl]\n)\n```\n\nConceptually a `LazyTree` object can be thought of as containing the pieces of data.\n\n1. The `root` of the tree.\n2. The data represented by the `root`, accessed via the `view` method.\n3. The child subtrees - computed using `child_map` and accessed through the `.children` attribute.\n\nFor example, in our interval example, each node corresponds to an interval of `(0, 1)` and has two child subtrees.\n\n```python\n# View the current root.\nassert tree.view() == tree.root\n\nsubtrees = tree.children\nassert len(subtrees) == 2\n```\n\nOften, for each node in a tree, one is interested in computing a particular function. This can be done using the `map` and `view` methods. For example, below `map` each interval in the tree to it's size. This results in a new `LazyTree` object.\n\n```python\ntree2 = tree.map(lambda itvl: itvl[1] - itvl[0]) # Change view to itvl size.\nassert tree2.view() == 1\n\n# Access the root's subtrees\nsubtrees = tree2.children\nassert len(subtrees) == 2\nassert subtrees[0].root == (0, 0.5)\nassert subtrees[0].view() == 0.5\n```\n\nTravesals of a `LazyTree` object are also implemented. For example,\n\n```python\n# Breadth First Search through tree.\n## Note: calls .view() before returning. \nitvls = tree.bfs() # returns a generator.\nsizes = tree2.bfs() # returns a generator.\n\nassert next(itvls) == (0, 1)\nassert next(sizes) == 1\n\nassert next(itvls) == (0, 0.5)\nassert next(sizes) == 0.5\n\nassert next(itvls) == (0.5, 1)\nassert next(sizes) == 0.5\n\n# Cost guided traversal.\n## Note: Smaller means higher priority.\nsizes = tree2.cost_guided_refinement(cost=lambda x: x)\nassert next(sizes) == 1 # (0, 1)\nassert next(sizes) == 0.5 # (0, 0.5)\nassert next(sizes) == 0.25 # (0, 0.25)\n\n# Iterative Deepening Depth First Traversal\nsizes = tree2.iddfs(max_depth=3) # returns a generator.\nassert list(sizes) == [1, 0.5, 0.5, 0.25, 0.25, 0.25, 0.25, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125]\n\n# Note, you can reset the current view.\ntree3 = tree2.with_identity_view()\nassert tree3.view() == tree.view()\n```\n\nFinally, one can \"prune\" away subtrees by labeling them as leaf nodes using the `prune` method. If you are sure that the resulting tree is finite (either due to pruning or the provided `child_map`) then one can compute the leaves of the tree.\n\n```python\n# Prune subtrees with a root of size less than 0.1.\ntree4 = tree2.prune(isleaf=lambda s: s < 0.2)\nsizes = tree.bfs()\nassert all(s > 0.001 for s in sizes) # Note that sizes is now finite.\n\n\n\n# Compute leafs of tree. Careful! Could be infinite!\nassert all(s == 0.125 for s in tree4.leaves())\nassert len(list(tree4.leaves())) == 8\n```\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mvcisback/pyLazyTree", "keywords": "", "license": "MIT", "maintainer": "Marcell Vazquez-Chanlatte", "maintainer_email": "marcell.vc@eecs.berkeley.edu", "name": "lazytree", "package_url": "https://pypi.org/project/lazytree/", "platform": "", "project_url": "https://pypi.org/project/lazytree/", "project_urls": { "Homepage": "https://github.com/mvcisback/pyLazyTree", "Repository": "https://github.com/mvcisback/pyLazyTree" }, "release_url": "https://pypi.org/project/lazytree/0.3.1/", "requires_dist": [ "attrs (>=19.1,<20.0)", "funcy (>=1.12,<2.0)" ], "requires_python": ">=3.6,<4.0", "summary": "Python library for manipulating infinite trees.", "version": "0.3.1" }, "last_serial": 5591063, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "099b7a5bb67ab16e9ab7a3a71ae3ee21", "sha256": "fda15f399384466876e13472ff128f8a8d5068ceb74a50c50b7cb8ab005b0d7f" }, "downloads": -1, "filename": "lazytree-0.1.0.tar.gz", "has_sig": false, "md5_digest": "099b7a5bb67ab16e9ab7a3a71ae3ee21", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2231, "upload_time": "2018-12-29T23:55:09", "url": "https://files.pythonhosted.org/packages/27/68/fd285f7df96a983dedeea55f5bcff2b7b9178924d8214e9cb85dc057f875/lazytree-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "8ecf3207f7fcd3bbbdab204be78fea8f", "sha256": "d505091e18591e79f7ca681b5b22d3de0d47512d6f242b1042aa26ae66fed6b3" }, "downloads": -1, "filename": "lazytree-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8ecf3207f7fcd3bbbdab204be78fea8f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3021, "upload_time": "2019-01-14T06:54:57", "url": "https://files.pythonhosted.org/packages/46/35/abc964606c0bb3a2d384a877fdbd3c865104f874e1c2744a811711106de1/lazytree-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "3382f1fa804ddd1450fe13ba9971339a", "sha256": "ca7b5b5c252883b3bd7216b30c6895ad25d2a4848eadd4448a8ebfa41e22f385" }, "downloads": -1, "filename": "lazytree-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "3382f1fa804ddd1450fe13ba9971339a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 3514, "upload_time": "2019-06-14T03:26:18", "url": "https://files.pythonhosted.org/packages/01/f2/3e3066f88d4b3cf794fe9fa04dc7fa7b3c1922c9908c1af88c2b8317d28c/lazytree-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "941d78f3d366d4067d6953080c92e156", "sha256": "9f399fa59e164890a1ebb82582062dda15d98ec96a16d915037560b790a87a47" }, "downloads": -1, "filename": "lazytree-0.2.1.tar.gz", "has_sig": false, "md5_digest": "941d78f3d366d4067d6953080c92e156", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 2914, "upload_time": "2019-06-14T03:26:20", "url": "https://files.pythonhosted.org/packages/f5/83/3eeffcfbcbb2b3d70369aa5c1e75db997b4052cd34998c92140c66c03832/lazytree-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "85d7a99e3593e62eaa25f05977e70383", "sha256": "f04fa548b621da4a440edf4122695298c5fa1c187ac7f8af5399f618b9ff5503" }, "downloads": -1, "filename": "lazytree-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "85d7a99e3593e62eaa25f05977e70383", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 3653, "upload_time": "2019-07-04T03:00:41", "url": "https://files.pythonhosted.org/packages/72/c2/60406816b35b387336e45f51f975de2835b2ca75069d312304c932438af9/lazytree-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "60c0aecca32f14ab8d1fbafb1eaf2f03", "sha256": "a2cd89293d7256f36788502bf725f278ad5d071e24a0b3b47a36cf6f54193d78" }, "downloads": -1, "filename": "lazytree-0.3.0.tar.gz", "has_sig": false, "md5_digest": "60c0aecca32f14ab8d1fbafb1eaf2f03", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 3033, "upload_time": "2019-07-04T03:00:42", "url": "https://files.pythonhosted.org/packages/76/2d/c507fe40fcc37ebf56682193c3403a014dd4f4abd6cc595fc387b9fcc53a/lazytree-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "22be8eb285d355a3502f7c0f12039496", "sha256": "9e2d5a237dbb9be3388edb26fc8d0d06ae1d41186ff6a8f362d10befb951e1f4" }, "downloads": -1, "filename": "lazytree-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "22be8eb285d355a3502f7c0f12039496", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 5637, "upload_time": "2019-07-26T22:32:52", "url": "https://files.pythonhosted.org/packages/92/a6/4a31b2ba1b07314b888beb95959732b7a88ece908fe384404439829a6ebe/lazytree-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "050de37eea92d421bc47951a2bb22ba3", "sha256": "23096b04eb48743e1e90151c285a604e8281c304c7aaa4abb083c0ccca28fa55" }, "downloads": -1, "filename": "lazytree-0.3.1.tar.gz", "has_sig": false, "md5_digest": "050de37eea92d421bc47951a2bb22ba3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 5508, "upload_time": "2019-07-26T22:32:53", "url": "https://files.pythonhosted.org/packages/61/88/14f8b6d6690b8f3c0a6ded481a9c1e018458d8a653d211d9c5836b4a1a66/lazytree-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "22be8eb285d355a3502f7c0f12039496", "sha256": "9e2d5a237dbb9be3388edb26fc8d0d06ae1d41186ff6a8f362d10befb951e1f4" }, "downloads": -1, "filename": "lazytree-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "22be8eb285d355a3502f7c0f12039496", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 5637, "upload_time": "2019-07-26T22:32:52", "url": "https://files.pythonhosted.org/packages/92/a6/4a31b2ba1b07314b888beb95959732b7a88ece908fe384404439829a6ebe/lazytree-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "050de37eea92d421bc47951a2bb22ba3", "sha256": "23096b04eb48743e1e90151c285a604e8281c304c7aaa4abb083c0ccca28fa55" }, "downloads": -1, "filename": "lazytree-0.3.1.tar.gz", "has_sig": false, "md5_digest": "050de37eea92d421bc47951a2bb22ba3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 5508, "upload_time": "2019-07-26T22:32:53", "url": "https://files.pythonhosted.org/packages/61/88/14f8b6d6690b8f3c0a6ded481a9c1e018458d8a653d211d9c5836b4a1a66/lazytree-0.3.1.tar.gz" } ] }