{"id":13688748,"url":"https://github.com/JiaYaobo/stamox","last_synced_at":"2025-05-01T20:30:38.284Z","repository":{"id":62736299,"uuid":"541032822","full_name":"JiaYaobo/stamox","owner":"JiaYaobo","description":"make your statistical research faster","archived":false,"fork":false,"pushed_at":"2023-07-07T11:53:45.000Z","size":1303,"stargazers_count":10,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-29T00:28:03.360Z","etag":null,"topics":["functional-programming","gpu","jax","python","statistics"],"latest_commit_sha":null,"homepage":"https://jiayaobo.github.io/stamox/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JiaYaobo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-25T02:55:37.000Z","updated_at":"2024-05-20T19:15:42.000Z","dependencies_parsed_at":"2023-02-12T14:30:30.509Z","dependency_job_id":null,"html_url":"https://github.com/JiaYaobo/stamox","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiaYaobo%2Fstamox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiaYaobo%2Fstamox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiaYaobo%2Fstamox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JiaYaobo%2Fstamox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JiaYaobo","download_url":"https://codeload.github.com/JiaYaobo/stamox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224274821,"owners_count":17284650,"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":["functional-programming","gpu","jax","python","statistics"],"created_at":"2024-08-02T15:01:21.696Z","updated_at":"2025-05-01T20:30:38.277Z","avatar_url":"https://github.com/JiaYaobo.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003ch1 align='center'\u003eStamox\u003c/h1\u003e\n\n[![PyPI version](https://badge.fury.io/py/stamox.svg)](https://badge.fury.io/py/stamox)\n[![PyPI - License](https://img.shields.io/pypi/l/stamox)](https://pypi.org/project/stamox/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/stamox)](https://pypi.org/project/stamox/)\n[![GitHub stars](https://img.shields.io/github/stars/jiayaobo/stamox)]()\n\n# Hello Stamox, Why Another Wheel?\n\n\n# Why Another Wheel?\n\nWhat stamox does is really simple, just make it possible, it aims to provide a statistic interface for `JAX`. But nowadays, we have so many statistic packages around the world varying from languages, for python, `statsmodels` just works great, for `R`, `tidyverse` derived packages are so delicate and easy to use. So **why build another wheel**?\n\nThree reasons I think:\n\n* Personal interest, as a student of statistics, I want to learn more about statistics and machine learning, proficient knowledge comes from books but more from practice, write down the code behind the theory is a good way to learn.\n\n* Speed, `JAX` is really fast, and `Equinox` is a good tool to make `JAX` more convenient, backend of `JAX` is `XLA`, which makes it possible to compile the code to GPU or TPU, and it is really fast.\n\n* Easy of Use, `%\u003e%` is delicate operation in `R`, it combines the functions to a pipe and make the code more readable, and `stamox` is inspired by it, and I want to take a try to make it convenient in python with `\u003e\u003e`.\n\nAnd here're few benchmarks:\n\n*generate random variables*\n\n![benchmark](./benchmark/benchmark1.png)\n\n*calculate cdf*\n\n![benchmark](./benchmark/benchmark2.png)\n\n## Installation\n\n```bash\npip install -U stamox\n# or\npip install git+https://github.com/JiaYaobo/stamox.git\n```\n\n## Documentation\n\nMore comprehensive introduction and examples can be found in the [documentation](https://jiayaobo.github.io/stamox/).\n\n## Quick Start\n\n### Similar but faster distribution functions to `R`\n\nYou can simply import all functions from `stamox.functions`\n\n```python\nfrom stamox.functions import dnorm, pnorm, qnorm, rnorm\nimport jax.random as jrandom\n\nkey = jrandom.PRNGKey(20010813)\n\n# random\nx = rnorm(key, sample_shape=(1000, ))\n# cdf\nprob = pnorm(x)\n# ppf\nqntl = qnorm(prob)\n# pdf\ndense = dnorm(x)\n```\n\n### Fearless Pipeable\n\n`\u003e\u003e` is the pipe operator, which is the similar to `|\u003e` in `F#` and `Elixir` or `%\u003e%` in `R`.\n\n* You can simply import all pipeable functions from `pipe_functions`\n\n```python\nimport jax.random as jrandom\nimport stamox.pipe_functions as PF\nfrom stamox import pipe_jit\n\nkey = jrandom.PRNGKey(20010813)\n\n@pipe_jit\ndef f(x):\n    return [3 * x[:, 0] + 2 * x[:, 1] - x[:, 2], x] # [y, X]\npipe = PF.rnorm(sample_shape=(1000, 3)) \u003e\u003e f \u003e\u003e PF.lm\nstate = pipe(key)\nprint(state.params)\n```\n\n* Custom Functions Pipeable\n\n```python\nfrom stamox import make_pipe, make_partial_pipe, Pipeable\nimport jax.numpy as jnp\nimport jax.random as jrandom\n\nx = jnp.ones((1000, ))\n# single input, simply add make pipe\n@make_pipe\ndef f(x):\n    return x ** 2\n\n# multiple input, decorate with make partial pipe\n@make_partial_pipe\ndef g(x, y):\n    return x + y\n\n# x -\u003e f -\u003e g(y=2.) -\u003e f -\u003e g(y=3.) -\u003e f\nh = Pipeable(x) \u003e\u003e f \u003e\u003e g(y=2.) \u003e\u003e f \u003e\u003e g(y=3.) \u003e\u003e f\n# h is a Pipeable object, you can call it to get the result\nprint(h())\n```\n\n* Compatible With `JAX` and `Equinox`\n\nYou can use autograd features from `JAX` and `Equinox` with `Stamox` easily.\n\n```python\nimport jax.numpy as jnp\nfrom stamox import make_partial_pipe\nfrom equinox import filter_jit, filter_vmap, filter_grad\n\n@make_partial_pipe\n@filter_jit\n@filter_vmap\n@filter_grad\ndef f(x, y):\n    return y * x ** 3\n\n# df/dx = 3y * x^2\ng = f(y=3.) # derive with respect to x given y=3\ng(jnp.array([1., 2., 3.]))\n```\n\nOr vmap, pmap, jit features integrated with `Stamox`:\n\n```python\nfrom stamox import pipe_vmap, pipe_jit\n\n@pipe_vmap\n@pipe_jit\ndef f(x):\n    return x ** 2\n\ng = f \u003e\u003e f \u003e\u003e f\nprint(g(jnp.array([1, 2, 3])))\n```\n\n### Linear Regression with Formula\n\n```python\nimport pandas as pd\nimport numpy as np\nfrom stamox.functions import lm # or from stamox.pipe_functions import lm\n\n\nx = np.random.uniform(size=(1000, 3))\ny = 2 * x[:,0] + 3 * x[:,1] + 4 * x[:,2] + np.random.normal(size=1000)\ndf = pd.DataFrame(x, columns=['x1', 'x2', 'x3'])\ndf['y'] = y\n\nlm(df, 'y~x1+x2+x3').params\n```\n\n## Acceleration Support\n\n`JAX` can be accelerated by `GPU` and `TPU`. So, `Stamox` is compatible with them.\n\n## Contributing\n\nContributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.\n\n1. Fork the `stamox` repository by clicking the Fork button on the repository page. This creates a copy of the `stamox` repository in your own account.\n2. Install Python \u003e= 3.8 locally in order to run tests.\n3. pip installing your fork from source. This allows you to modify the code and immediately test it out:\n```bash\ngit clone https://github.com/JiaYaobo/stamox.git\ncd stamox\n```\n4. Add the `stamox` repo as an upstream remote, so you can use it to sync your changes.\n```bash\ngit remote add upstream https://github.com/JiaYaobo/stamox.git\n```\n5. Create a branch for local development:\n```bash\ngit checkout -b name-of-your-bugfix-or-feature\n```\n6. Install requirements for tests\n```bash\npip install -r tests/requirements.txt\n```\n7. Make sure the tests pass by running the following command from the top of the repository:\n```bash\npytest tests/\n```\n8. Commit your changes and push your branch to GitHub:\n```bash\ngit add .\ngit commit -m \"Your detailed description of your changes.\"\n```\nThen sync your code with the main repo:\n```bash\ngit fetch upstream\ngit rebase upstream/main\n```\nFinally, push your changes to your fork:\n```bash\ngit push --set-upstream origin name-of-your-bugfix-or-feature\n```\n9. Submit a pull request through the GitHub website.\n    \n## See More\n\n[JAX](https://github.com/google/jax)\n\n[Equinox](https://github.com/patrick-kidger/equinox#readme)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJiaYaobo%2Fstamox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJiaYaobo%2Fstamox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJiaYaobo%2Fstamox/lists"}