{"id":17730787,"url":"https://github.com/kaandesu/special-distributions","last_synced_at":"2025-06-20T08:09:57.422Z","repository":{"id":176073112,"uuid":"654644585","full_name":"kaandesu/special-distributions","owner":"kaandesu","description":"For studying MMCS, defined special probability distributions as classes. Also renders example graphs.","archived":false,"fork":false,"pushed_at":"2023-06-17T15:01:24.000Z","size":306,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-18T07:45:29.677Z","etag":null,"topics":["learning-purpose","mathematical-methods","probability","random-variables"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/kaandesu.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":"2023-06-16T15:33:01.000Z","updated_at":"2023-06-17T13:07:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"859bb1a3-a958-45bc-9341-90abb9748ae9","html_url":"https://github.com/kaandesu/special-distributions","commit_stats":null,"previous_names":["kaandesu/special-distributions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kaandesu/special-distributions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaandesu%2Fspecial-distributions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaandesu%2Fspecial-distributions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaandesu%2Fspecial-distributions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaandesu%2Fspecial-distributions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaandesu","download_url":"https://codeload.github.com/kaandesu/special-distributions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaandesu%2Fspecial-distributions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260907193,"owners_count":23080615,"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","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":["learning-purpose","mathematical-methods","probability","random-variables"],"created_at":"2024-10-25T22:07:52.003Z","updated_at":"2025-06-20T08:09:52.409Z","avatar_url":"https://github.com/kaandesu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Special Probability Distributions\n\n\u003cp\u003e\nThe Probability Distributions Project is a TypeScript library that provides implementations of various \nprobability distributions, including Bernoulli, Binomial, Poisson, Geometric, and Negative Binomial \ndistributions. It offers methods to calculate the expected value, variance, and probability at specific values \nfor each distribution. The project also includes examples of rendering distributions to generate visual charts.\n\u003c/p\u003e\n\n## Table of Contents\n\n- [Example Usage](#usage)\n- [Render Example Graphs](#rendering-graphs)\n- [Development](#development)\n  - [Rendering Graphs](#rendering-graphs-1)\n  - [Utils](#utils)\n\n---\n\n# Usage\n\n```typescript\n// index.ts\n\nimport { log } from './utils'\nimport {\n  BinomialDistribution,\n  BernoulliDistribution,\n  PoissonDistribution,\n  GeometricDistribution,\n} from './distributions'\n\n// Create instances of distributions\nconst bernoulli = new BernoulliDistribution(0.5)\nconst binomial = new BinomialDistribution(4, 1 / 3)\nconst poisson = new PoissonDistribution(5)\nconst geometric = new GeometricDistribution(0.5)\n\n// Log information about the distributions\nlog(bernoulli)\nlog(binomial, 2)\nlog(poisson, 4)\nlog(geometric, 2)\n```\n\n\u003cp\u003e\nCode: Creates instances of each distribution with specific parameters. \n Finally, it uses the log function from \u003ci\u003e'utils.ts'\u003c/i\u003e to log information about each distribution,\n  including the calculated value, expected value, variance, \n  and probability at a specific value (if provided).\n\u003c/p\u003e\n\nRun **`npm run log`** to see the output logged in the terminal.\n\n---\n\n## Rendering Graphs\n\nThe `render/[distribution_name].ts` files provide examples of rendering distributions. Each file demonstrates the rendering process for a specific distribution. Below are the available render examples:\n\nIt generates a chart showing the distribution of values obtained from multiple calculations of the geometric distribution.\n\n### Commands to render example graphs:\n\n- Geometric Distribution: **`npm run render:geo`**\n- Negative Binomial Distribution: **`npm run render:negbin`**\n\n### Example Rendered Graphs:\n\n- Negative Binomial Distribution Chart (10_000 calculations for getting 3rd win on 10th try with 8%): \u003cimg src=\"./generated/NegativeBinomial_chart.png\"   height=\"300\"\u003e\n- Geometric Distribution Chart (100_000 times trying until getting %1): \u003cimg src=\"./generated/Geometric_chart.png\"   height=\"300\"\u003e\n\n---\n\n# Development\n\n## Rendering Graphs\n\nFirst: Add a .ts file in the `render` directory to create a new example. Import the class of your distribution. Then:\n\n1. Update the `totalTimes` variable to specify the number of calculations to perform.\n2. Run the file using a TypeScript compiler or runtime environment. Or simply add it to the package.json file as a script and run it using `npm run render:[name]`.\n3. The script will output the progress of the calculations as a percentage.\n4. Once the calculations are complete, a chart image will be saved as `./generated/{distribution}_chart.png`, where `{distribution}` represents the specific distribution used.\n\n## Utils\n\nThe `utils.ts` file provides two utility functions and a `Calc` class.\n\nThe `noop` function is an empty function that does nothing. It can be used as a placeholder or a no-operation function.\n\nThe `log` function is an asynchronous function that logs information about a given distribution. It takes the distribution instance (`dist`) and an optional value (`probAt`) as parameters. It calculates the value of the distribution, expected value, variance, and probability at the specified value (if provided) using the methods of the distribution class. The logged information includes the distribution's ID, calculated value, expected value, variance, and probability.\n\nThe `Calc` class provides mathematical calculation functions used by the distributions. It includes functions for factorial, power, combination, and the mathematical constant `e`.\n\nMake sure to import the `log` function and `Calc` class from `utils.ts` when using them.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaandesu%2Fspecial-distributions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaandesu%2Fspecial-distributions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaandesu%2Fspecial-distributions/lists"}