{"id":16275274,"url":"https://github.com/arthurkushman/total_probability","last_synced_at":"2025-10-20T12:14:01.266Z","repository":{"id":96025529,"uuid":"80425050","full_name":"arthurkushman/total_probability","owner":"arthurkushman","description":"Total probability + Thomas Bayes, Bernoulli distribution formulas","archived":false,"fork":false,"pushed_at":"2019-05-03T15:39:45.000Z","size":1176,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-08T02:02:49.528Z","etag":null,"topics":["bayes","bernulli","formulas","math","mathematics","php","probability"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/arthurkushman.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}},"created_at":"2017-01-30T13:45:13.000Z","updated_at":"2020-03-17T12:54:25.000Z","dependencies_parsed_at":"2023-04-24T16:47:47.042Z","dependency_job_id":null,"html_url":"https://github.com/arthurkushman/total_probability","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/arthurkushman/total_probability","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Ftotal_probability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Ftotal_probability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Ftotal_probability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Ftotal_probability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arthurkushman","download_url":"https://codeload.github.com/arthurkushman/total_probability/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurkushman%2Ftotal_probability/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280088680,"owners_count":26269906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bayes","bernulli","formulas","math","mathematics","php","probability"],"created_at":"2024-10-10T18:32:42.557Z","updated_at":"2025-10-20T12:14:01.229Z","avatar_url":"https://github.com/arthurkushman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/arthurkushman/total_probability/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/arthurkushman/total_probability/?branch=master)\n[![Build Status](https://scrutinizer-ci.com/g/arthurkushman/total_probability/badges/build.png?b=master)](https://scrutinizer-ci.com/g/arthurkushman/total_probability/build-status/master)\n[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)\n\n## Total probability + Thomas Bayes, Bernoulli distribution formulas\n\nThis project was created for those folks who love Math + PHP and either want to have \na great library to work with Total probability and Bayes, Bernoulli formulas \nto calculate any real-world tasks on demand.\n  \n* [Total probability](#user-content-total-probability)  \n* [Thomas Bayes](#user-content-thomas-bayes)\n* [Bernoulli distribution](#user-content-bernoulli-distribution)\n  \n### Examples\n\n#### Total probability \nWe have 3 baskets:\n\n- 1-st basket contains 7 black and 4 white balls\n\n- 2-nd basket contains only white balls\n\n- 3-d basket contains only black balls\n\nWhat's the probability of taking a black ball?\n\nThe basket choice is 1/3.\n\n- In the 1st basket we've got 7/11(7+4) probability of taking black ball.\n\n- In 2nd basket there are only white balls - probability is 0.\n\n- In 3d basket there are only black balls - probability is 1.\n\nSo we execute ```totalProbability``` method from ```Formula``` class:\n```php\n$this-\u003eformula = new Formula();\n$result = $this-\u003eformula-\u003etotalProbability(\n    [0.33, 0.33, 0.33],\n    [0, 1, 0.45],\n]);\necho $result; // 6/11=0.(54)\n```\n\n#### Thomas Bayes\nAt the warehouse came 2 party products:\n- 1st - 4000 items\n- 2nd - 6000 items\n\nThe percent of a non-standard items in 1st party is 20%\n\nThe percent of a non-standard items in 1st party is 10%\n\nRandomly taken item of two parties turned out to be standard - what's the probability \nrelation of this item to 1st and 2nd party.  \n\nPart 1:\n\nOverall items at the warehouse: 4000 + 6000 = 10000 -\u003e 4000/10000 = 0.4, 6000/10000 = 0.6\n\nCheck: 0.4+0.6=1\n\n- 1st party has standard items -\u003e 100% - 20% = 80% standard items -\u003e 80/100 = 0.8\n\n- 2nd party has standard items -\u003e 100% - 10% = 90% standard items -\u003e 90/100 = 0.9\n\nUsing total probability formula:\n```php\n$this-\u003eformula = new Formula();\n$result = $this-\u003eformula-\u003etotalProbability([0.4, 0.8], [\n    0.8,\n    0.9\n]);\necho $result; // 0.86\n```\nWe've got the probability, that the any picked item will be standard. \n\nThen using Bayes formula:\n```php\n$result = $this-\u003eformula-\u003ebayesProbability(0.4, 0.8, 0.86);\necho $result; // 0.37\n```\nWe've got a probability, that the selected standard item will be related to 1st party.\n\n```php\n$result = $this-\u003eformula-\u003ebayesProbability(0.6, 0.9, 0.86);\necho $result; // 0.63\n```\nWe've got a probability, that the selected standard item will be related to 2nd party.\n\nCheck: 0.37+0.63=1\n\n#### Bernoulli distribution\n\nFind the probability, that within 10 flips of a coin tails will result in 3 times.\n \nUsing combinatorial combinations function 10! / 7! * 3! = 120 \nand combining it with Bernoulli distribution formula ```Cmn * p^m * q^n-m``` - getting the result:\n\n```php\n$result = $this-\u003eformula-\u003eindependentProbability(10, 3, 0.5);\necho $result; // 0.1171875\n```\nWe've got a probability, that withing 10 flips of a coin tails will result in 3 times.\n\n#### The probability of the relative frequency deviation of the probability\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurkushman%2Ftotal_probability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farthurkushman%2Ftotal_probability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurkushman%2Ftotal_probability/lists"}