{"id":22158608,"url":"https://github.com/danylevych/precision-tree","last_synced_at":"2026-01-31T08:33:12.882Z","repository":{"id":264345784,"uuid":"893100991","full_name":"danylevych/precision-tree","owner":"danylevych","description":"Precision Tree Module for precision decision analysis, supporting custom nodes (Decision, Chance, and Payoff) with visualization and optimal path calculation.","archived":false,"fork":false,"pushed_at":"2024-11-26T18:57:54.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-25T13:00:02.909Z","etag":null,"topics":["decsion-tree","precision-tree","pypl","python","python3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/precision-tree/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danylevych.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-23T14:36:44.000Z","updated_at":"2024-11-26T18:57:58.000Z","dependencies_parsed_at":"2025-06-27T18:44:52.597Z","dependency_job_id":null,"html_url":"https://github.com/danylevych/precision-tree","commit_stats":null,"previous_names":["danylevych/precision-tree"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/danylevych/precision-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danylevych%2Fprecision-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danylevych%2Fprecision-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danylevych%2Fprecision-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danylevych%2Fprecision-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danylevych","download_url":"https://codeload.github.com/danylevych/precision-tree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danylevych%2Fprecision-tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28935415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T07:49:44.436Z","status":"ssl_error","status_checked_at":"2026-01-31T07:49:34.274Z","response_time":128,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decsion-tree","precision-tree","pypl","python","python3"],"created_at":"2024-12-02T03:34:43.435Z","updated_at":"2026-01-31T08:33:12.867Z","avatar_url":"https://github.com/danylevych.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Guide\n - [Start](#start)\n - [Modules](#modules)\n    - [Nodes](#nodes)\n    - [Tree](#tree)\n - [Usage](#usage)\n\n---\n\n## Start\n\nThis is a library to create decision trees and calculate the expected value of the best strategy.\n\nTo install the library, run the following command:\n```bash\npip install precision-tree\n```\n\n---\n\n## Modules\n\nThe library has two main modules: `nodes` and `tree`.\n\nThe `nodes` module contains the classes to create the nodes of the decision tree. The `tree` module contains the class to wrap the root node and calculate the expected value of the best strategy and visualize the tree.\n\n### Nodes\n\nThe `nodes` module contains the following classes:\n\n- `DecisionNode`: Represents a decision node.\n\n- `ChanceNode`: Represents a chance node.\n\n- `PayoffNode`: Represents a payoff node.\n\nAll of the classes are subclasses of the `Node` class.\n\n#### DecisionNode\n\nThe `DecisionNode` class represents a decision node (in graph it looks like a squere).\n\nThe following table shows the attributes of the `DecisionNode` class:\n\n| Attribute | Description |\n| --- | --- |\n| `name` | The name of the node. |\n| `branches` | A list of branches. |\n\n\nThe following table shows the methods of the `DecisionNode` class:\n\n| Method | Description |\n| --- | --- |\n| `add_branch(self, label, child)` | Adds a branch to the node. `label` is the name of the branch and `child` is the child node. |\n| `calculate_value` | Calculates the expected value of the best strategy. |\n\n\n#### ChanceNode\n\nThe `ChanceNode` class represents a chance node (in graph it looks like a circle).\n\nThe following table shows the attributes of the `ChanceNode` class:\n\n| Attribute | Description |\n| --- | --- |\n| `name` | The name of the node. |\n| `cost` | The cost of the node. |\n| `years` | The number of years. |\n| `branches` | A list of branches. |\n\nThe following table shows the methods of the `ChanceNode` class:\n\n| Method | Description |\n| --- | --- |\n| `add_branch(self, label, child, probability)` | Adds a branch to the node. `label` is the name of the branch, `child` is the child node, and `probability` is the probability of the branch. |\n| `calculate_value` | Calculates the expected value of the best strategy. |\n\n#### PayoffNode\n\nThe `PayoffNode` class represents a payoff node (in graph it looks like a triangle).\n\nThe following table shows the attributes of the `PayoffNode` class:\n\n| Attribute | Description |\n| --- | --- |\n| `name` | The name of the node. |\n| `value` | The value of the node. |\n| `branches` | A list of branches. |\n\nThe following table shows the methods of the `PayoffNode` class:\n\n| Method | Description |\n| --- | --- |\n| `calculate_value` | Calculates the expected value of the best strategy. |\n\n### Tree\n\nThe `tree` module contains the `TreeWrapper` class.\n\nThe following table shows the attributes of the `TreeWrapper` class:\n\n| Attribute | Description |\n| --- | --- |\n| `root` | The root node of the tree. |\n\nThe following table shows the methods of the `TreeWrapper` class:\n\n| Method | Description |\n| --- | --- |\n| `show(self, title: str, format: str):` | Shows the tree. `title` is the title of the tree and `format` is the format of the file `png`, `pdf` etc. |\n| `get_optimal_path` | Returns the optimal path as a tuple, where the first element is the optimal nodes and second element is the optimal edges. |\n| `calculate_value` | Calculates the expected value of the best strategy. |\n\n\n---\n\n## Usage\n\n\n**Example**\n```python\nfrom precision_tree.nodes import DecisionNode, ChanceNode, PayoffNode\nfrom precision_tree.tree import TreeWrapper\n\n\nroot = DecisionNode(\"Decision\")\n\n# Decision Node Without Analytics\nwithout_analytics = DecisionNode(\"Without Analytics\")\n\nbig_factory = ChanceNode(\"Big Factory 1\", cost=0, years=1)\nbig_factory.add_branch(label=\"Favorable P(0.7)\", child=PayoffNode(\"Favorable 1\", 200), probability=0.7)\nbig_factory.add_branch(label=\"Unfavorable P(0.3)\", child=PayoffNode(\"Unfavorable 1\", -180), probability=0.3)\n\nsmall_factory = ChanceNode(\"Small Factory 1\", cost=0, years=1)\nsmall_factory.add_branch(label=\"Favorable P(0.7)\", child=PayoffNode(\"Favorable 2\", 100), probability=0.7)\nsmall_factory.add_branch(label=\"Unfavorable P(0.3)\", child=PayoffNode(\"Unfavorable 2\", -20), probability=0.3)\n\nwithout_analytics.add_branch(label=\"Big Factory\", child=big_factory)\nwithout_analytics.add_branch(label=\"Small Factory\", child=small_factory)\nwithout_analytics.add_branch(label=\"Sell Patent\", child=PayoffNode(\"Sell Patent 1\", 10))\n\n# Make Decision Node With Analytics\nwith_analytics = ChanceNode(\"With Analytics\", cost=8, years=1)\n\n# Positive Result\npositive_result = DecisionNode(\"Positive Result\")\n\nbig_factory_positive = ChanceNode(\"Big Factory 2\", cost=0, years=1)\nbig_factory_positive.add_branch(label=\"Favorable\", child=PayoffNode(\"Favorable 3\", 200), probability=0.81)\nbig_factory_positive.add_branch(label=\"Unfavorable\", child=PayoffNode(\"Unfavorable 3\", -180), probability=0.19)\n\nsmall_factory_positive = ChanceNode(\"Small Factory 2\", cost=0, years=1)\nsmall_factory_positive.add_branch(label=\"Favorable\", child=PayoffNode(\"Favorable 4\", 100), probability=0.81)\nsmall_factory_positive.add_branch(label=\"Unfavorable\", child=PayoffNode(\"Unfavorable 4\", -20), probability=0.19)\n\npositive_result.add_branch(label=\"Big Factory\", child=big_factory_positive)\npositive_result.add_branch(label=\"Small Factory\", child=small_factory_positive)\npositive_result.add_branch(label=\"Sell Patent\", child=PayoffNode(\"Sell Patent 2\", 10))\n\n# Negative Result\nnegative_result = DecisionNode(\"Negative Result\")\n\nbig_factory_negative = ChanceNode(\"Big Factory 3\", cost=0, years=1)\nbig_factory_negative.add_branch(label=\"Favorable\", child=PayoffNode(\"Favorable 5\", 200), probability=0.28)\nbig_factory_negative.add_branch(label=\"Unfavorable\", child=PayoffNode(\"Unfavorable 5\", -180), probability=0.72)\n\nsmall_factory_negative = ChanceNode(\"Small Factory 3\", cost=0, years=1)\nsmall_factory_negative.add_branch(label=\"Favorable\", child=PayoffNode(\"Favorable 6\", 100), probability=0.28)\nsmall_factory_negative.add_branch(label=\"Unfavorable\", child=PayoffNode(\"Unfavorable 6\", -20), probability=0.72)\n\nnegative_result.add_branch(label=\"Big Factory\", child=big_factory_negative)\nnegative_result.add_branch(label=\"Small Factory\", child=small_factory_negative)\nnegative_result.add_branch(label=\"Sell Patent\", child=PayoffNode(\"Sell Patent 3\", 10))\n\nwith_analytics.add_branch(label=\"Positive Result\", child=positive_result, probability=0.48)\nwith_analytics.add_branch(label=\"Negative Result\", child=negative_result, probability=0.52)\n\n# Add Branches to Root\nroot.add_branch(label=\"With Analytics\", child=with_analytics)\nroot.add_branch(label=\"Without Analytics\", child=without_analytics)\n\ntree = TreeWrapper(root)\nprint(f\"Expected Value of the best strategy: {tree.calculate_value():.2f}\")\nprint(f\"Optimal branch: {tree.get_optimal_path()[0]}\")\n```\n\n**Output**\n\n```bash\nExpected Value of the best strategy: 86.00\nOptimal branch: {'Unfavorable 1', 'Favorable 1', 'Big Factory 1', 'Without Analytics', 'Decision'}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanylevych%2Fprecision-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanylevych%2Fprecision-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanylevych%2Fprecision-tree/lists"}