{"id":20799877,"url":"https://github.com/xnacly/statlib","last_synced_at":"2025-12-25T05:38:34.928Z","repository":{"id":195996508,"uuid":"694110830","full_name":"xNaCly/statlib","owner":"xNaCly","description":"go library for commonly used statistical computations, optimized for performance, zero allocations","archived":false,"fork":false,"pushed_at":"2023-09-30T20:13:37.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-18T12:20:12.959Z","etag":null,"topics":["go","math","statistics","zero-allocation"],"latest_commit_sha":null,"homepage":"","language":"Go","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/xNaCly.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}},"created_at":"2023-09-20T10:58:36.000Z","updated_at":"2023-10-01T17:22:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"9bbe4a58-7454-419b-b9ca-4cdaf50e46c5","html_url":"https://github.com/xNaCly/statlib","commit_stats":null,"previous_names":["xnacly/statlib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xNaCly%2Fstatlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xNaCly%2Fstatlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xNaCly%2Fstatlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xNaCly%2Fstatlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xNaCly","download_url":"https://codeload.github.com/xNaCly/statlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243147274,"owners_count":20243744,"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":["go","math","statistics","zero-allocation"],"created_at":"2024-11-17T18:10:35.259Z","updated_at":"2025-12-25T05:38:34.880Z","avatar_url":"https://github.com/xNaCly.png","language":"Go","readme":"## statlib\n\nGo library for commonly used statistical computations, optimized for performance\n\n## Features\n\n- very fast Factorial\n- very fast Binomial coefficient\n- Distributions (for `X=k`)\n  - Binomial\n  - Poisson\n  - Hypergeometric\n  - Geometric\n- Methods for distributions\n  - Probability\n  - Median\n  - Mode\n  - Mean\n  - Variance\n\n## Usage\n\n### Factorial\n\nComputing the value of 12!:\n\n```go\npackage main\n\nimport (\n   \"fmt\"\n   \"github.com/xnacly/statlib\"\n)\n\nfunc main() {\n    val, err := statlib.Fac(12)\n    if err != nil {\n        panic(err)\n    }\n    fmt.Printf(\"12! = %d\\n\", val)\n}\n```\n\n### Binomial coefficient\n\nChoosing 6 possibilities out of 49 options:\n\n```go\npackage main\n\nimport (\n   \"fmt\"\n   \"github.com/xnacly/statlib\"\n)\n\nfunc main() {\n    val, err := statlib.BinomialCoefficient(49, 6)\n    if err != nil {\n        panic(err)\n    }\n    fmt.Printf(\"49nCr6 = %d\\n\", val)\n}\n```\n\n### Distributions\n\n#### Binomial distribution\n\nCalculating the chance of getting 3 heads when throwing a coin 10 times:\n\n```go\npackage main\n\nimport (\n   \"fmt\"\n   \"github.com/xnacly/statlib/distributions\"\n)\n\nfunc main() {\n    bin := distributions.Binomial{\n        N: 10,\n        P: 0.5,\n        Q: 1 - 0.5,\n    }\n\n    val, err := bin.Prob(3)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"chance of getting 3 heads when throwing 10 times = %f%%\\n\", val*100)\n}\n```\n\n#### Poisson distribution\n\nCalculating the chance of getting called 2 times in one minute for the rate $\\lambda = 5.3$:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/xnacly/statlib/distributions\"\n)\n\nfunc main() {\n    pois := distributions.Poisson{\n        Lambda: 5.3,\n    }\n\n    val, err := pois.Prob(2)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"Chance of getting exactly 2 calls in one minute = %f%%\\n\", val*100)\n}\n```\n\n#### Hypergeometric distribution\n\nChoosing 5 light bulbs from a package of 20 light bulbs in which 20% aren't\nworking. What is the chance to have 0 broken light bulbs?\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/xnacly/statlib/distributions\"\n)\n\nfunc main() {\n    hyper := distributions.Hypergeometric{\n        N:      20,\n        K:      20 * 0.2,\n        SmallN: 5,\n    }\n\n    val, err := hyper.Prob(0)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"Chance of 0 broken light bulbs when choosing 5 out of 20 in which 20%% are broken = %f%%\\n\", val*100)\n}\n```\n\n## Contributing\n\nMake sure to write understandable code, document hacks, tricks and hard to read\nsections with the source and or an explanation. Always provide tests, focus\nespecially on edge cases and large inputs.\n\nConsider well written commits:\n\n```\n\u003cfile without extension or context\u003e: \u003cshort description about the change\u003e\n\n\u003c\nlonger description, go into depth on your implementation and mention github issues with:\n\nFix: #00000 if fixed\nAdd: #00000 if added a feature\nUpdate: #00000 if changes regarding the issue occured in your commit\n\u003e\n```\n\n## Test\n\nRun the following to execute the test suite\n\n```sh\ngo test ./...\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxnacly%2Fstatlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxnacly%2Fstatlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxnacly%2Fstatlib/lists"}