{"id":13870023,"url":"https://github.com/pyro-ppl/funsor","last_synced_at":"2025-04-04T16:12:47.284Z","repository":{"id":38451573,"uuid":"168430006","full_name":"pyro-ppl/funsor","owner":"pyro-ppl","description":"Functional tensors for probabilistic programming","archived":false,"fork":false,"pushed_at":"2023-08-31T18:37:21.000Z","size":2729,"stargazers_count":239,"open_issues_count":90,"forks_count":21,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-28T15:06:02.568Z","etag":null,"topics":["jax","machine-learning","numpy","probabilistic-programming","pyro","pytorch","symbolic"],"latest_commit_sha":null,"homepage":"https://funsor.pyro.ai","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/pyro-ppl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-30T23:13:39.000Z","updated_at":"2025-03-17T15:32:36.000Z","dependencies_parsed_at":"2024-01-16T07:39:18.063Z","dependency_job_id":null,"html_url":"https://github.com/pyro-ppl/funsor","commit_stats":{"total_commits":554,"total_committers":15,"mean_commits":36.93333333333333,"dds":0.6155234657039711,"last_synced_commit":"ff5e410de720bc1f423f57cf156592fc194b058c"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyro-ppl%2Ffunsor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyro-ppl%2Ffunsor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyro-ppl%2Ffunsor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyro-ppl%2Ffunsor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyro-ppl","download_url":"https://codeload.github.com/pyro-ppl/funsor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208141,"owners_count":20901570,"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":["jax","machine-learning","numpy","probabilistic-programming","pyro","pytorch","symbolic"],"created_at":"2024-08-05T20:01:25.861Z","updated_at":"2025-04-04T16:12:47.267Z","avatar_url":"https://github.com/pyro-ppl.png","language":"Python","funding_links":[],"categories":["Python","概率统计"],"sub_categories":[],"readme":"[![Build Status](https://github.com/pyro-ppl/funsor/workflows/CI/badge.svg)](https://github.com/pyro-ppl/funsor/actions)\n[![Latest Version](https://badge.fury.io/py/funsor.svg)](https://pypi.python.org/pypi/funsor)\n[![Documentation Status](https://readthedocs.org/projects/funsor/badge)](http://funsor.readthedocs.io)\n\n# Funsor\n\nFunsor is a tensor-like library for functions and distributions.\n\nSee\n[Functional tensors for probabilistic programming](https://arxiv.org/abs/1910.10775)\nfor a system description.\n\n## Installing\n\n**Install using pip:**\n\nFunsor supports Python 3.7+.\n\n```sh\npip install funsor\n```\n\n**Install from source:**\n```sh\ngit clone git@github.com:pyro-ppl/funsor.git\ncd funsor\ngit checkout master\npip install .\n```\n\n## Using funsor\n\nFunsor can be used through a number of interfaces:\n\n-   Funsors can be used directly for probabilistic computations, using PyTorch\n    optimizers in a standard training loop. Start with these examples:\n    [discrete_hmm](examples/discrete_hmm.py),\n    [eeg_slds](examples/eeg_slds.py),\n    [kalman_filter](examples/kalman_filter.py),\n    [pcfg](examples/pcfg.py),\n    [sensor](examples/sensor.py),\n    [slds](examples/slds.py), and\n    [vae](examples/vae.py).\n-   Funsors can be used to implement custom inference algorithms within Pyro,\n    using custom elbo implementations in standard\n    [pyro.infer.SVI](http://docs.pyro.ai/en/stable/inference_algos.html#pyro.infer.svi.SVI)\n    training. See these examples:\n    [mixed_hmm](examples/mixed_hmm/model.py) and\n    [bart forecasting](https://github.com/pyro-ppl/sandbox/blob/master/2019-08-time-series/bart/forecast.py).\n-   [funsor.pyro](https://funsor.readthedocs.io/en/latest/pyro.html) provides a\n    number of Pyro-compatible (and PyTorch-compatible) distribution classes\n    that use funsors under the hood, as well\n    [utilities](https://funsor.readthedocs.io/en/latest/pyro.html#module-funsor.pyro.convert)\n    to convert between funsors and distributions.\n-   [funsor.minipyro](https://funsor.readthedocs.io/en/latest/minipyro.html)\n    provides a limited alternate backend for the Pyro probabilistic programming\n    language, and can perform some ELBO computations exactly.\n\n## Design\n\nSee [design doc](https://docs.google.com/document/d/1NVlfQnNQ0Aebg8vfIGcJKsnSqAhB4bbClQrb5dwm2OM). \n\nThe goal of this library is to generalize [Pyro](http://pyro.ai)'s delayed\ninference algorithms from discrete to continuous variables, and to create\nmachinery to enable partially delayed sampling compatible with universality. To\nachieve this goal this library makes three orthogonal design choices:\n\n1.  Open terms are objects. Funsors generalize the tensor interface\n    to also cover arbitrary functions of multiple variables (\"inputs\"), where\n    variables may be integers, real numbers, or real tensors. Function\n    evaluation / substitution is the basic operation, generalizing tensor\n    indexing.  This allows probability distributions to be first-class Funsors\n    and make use of existing tensor machinery, for example we can generalize\n    tensor contraction to computing analytic integrals in conjugate\n    probabilistic models.\n\n2.  Support nonstandard interpretation. Funsors support user-defined\n    interpretations, including, eager, lazy, mixed eager+lazy, memoized (like\n    opt\\_einsum's sharing), and approximate interpretations like Monte Carlo\n    approximations of integration operations (e.g. `.sum()` over a funsor\n    dimension).\n\n3.  Named dimensions. Substitution is the most basic operation of Funsors. To\n    avoid the difficulties of broadcasting and advanced indexing in\n    positionally-indexed tensor libraries, all Funsor dimensions are named.\n    Indexing uses the `.__call__()` method and can be interpreted as\n    substitution (with well-understood semantics).  Funsors are viewed as\n    algebraic expressions with one algebraic free variable per dimension. Each\n    dimension is either covariant (an output) or contravariant (an input).\n\nUsing `funsor` we can easily implement Pyro-style\n[delayed sampling](http://pyro.ai/examples/enumeration.html), roughly:\n\n```py\ntrace_log_prob = 0.\n\ndef pyro_sample(name, dist, obs=None):\n    assert isinstance(dist, Funsor)\n    if obs is not None:\n        value = obs\n    elif lazy:\n        # delayed sampling (like Pyro's parallel enumeration)\n        value = funsor.Variable(name, dist.support)\n    else:\n        value = dist.sample('value')[0]['value']\n\n    # save log_prob in trace\n    trace_log_prob += dist(value)\n\n    return value\n\n# ...later during inference...\nloss = -trace_log_prob.reduce(logaddexp)  # collapses delayed variables\n```\nSee [funsor/minipyro.py](funsor/minipyro.py) for complete implementation.\n\n## Related projects\n\n- Pyro's [ops.packed](https://github.com/uber/pyro/blob/dev/pyro/ops/packed.py),\n  [ops.einsum](https://github.com/uber/pyro/blob/dev/pyro/ops/einsum), and\n  [ops.contract](https://github.com/uber/pyro/blob/dev/pyro/ops/contract.py)\n- [Birch](https://birch-lang.org/)'s [delayed sampling](https://arxiv.org/abs/1708.07787)\n- [autoconj](https://arxiv.org/abs/1811.11926)\n- [dyna](http://www.cs.jhu.edu/~nwf/datalog20-paper.pdf)\n- [PSI solver](https://psisolver.org)\n- [Hakaru](https://hakaru-dev.github.io)\n- [sympy](https://www.sympy.org/en/index.html)\n- [namedtensor](https://github.com/harvardnlp/namedtensor)\n\n## Citation\n\nIf you use Funsor, please consider citing:\n```\n@article{obermeyer2019functional,\n  author = {Obermeyer, Fritz and Bingham, Eli and Jankowiak, Martin and\n            Phan, Du and Chen, Jonathan P},\n  title = {{Functional Tensors for Probabilistic Programming}},\n  journal = {arXiv preprint arXiv:1910.10775},\n  year = {2019}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyro-ppl%2Ffunsor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyro-ppl%2Ffunsor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyro-ppl%2Ffunsor/lists"}