{"id":15066278,"url":"https://github.com/brendanhasz/probflow","last_synced_at":"2025-04-07T12:03:52.038Z","repository":{"id":48675989,"uuid":"164249963","full_name":"brendanhasz/probflow","owner":"brendanhasz","description":"A Python package for building Bayesian models with TensorFlow or PyTorch","archived":false,"fork":false,"pushed_at":"2022-08-10T20:50:04.000Z","size":3387,"stargazers_count":173,"open_issues_count":22,"forks_count":17,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T11:05:19.994Z","etag":null,"topics":["bayesian","bayesian-inference","bayesian-methods","bayesian-neural-networks","bayesian-statistics","data-science","machine-learning","python","pytorch","statistics","tensorflow"],"latest_commit_sha":null,"homepage":"http://probflow.readthedocs.io","language":"Python","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/brendanhasz.png","metadata":{"files":{"readme":"README.rst","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}},"created_at":"2019-01-05T20:46:44.000Z","updated_at":"2025-02-07T23:07:17.000Z","dependencies_parsed_at":"2022-08-27T07:51:58.178Z","dependency_job_id":null,"html_url":"https://github.com/brendanhasz/probflow","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanhasz%2Fprobflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanhasz%2Fprobflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanhasz%2Fprobflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brendanhasz%2Fprobflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brendanhasz","download_url":"https://codeload.github.com/brendanhasz/probflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648976,"owners_count":20972945,"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":["bayesian","bayesian-inference","bayesian-methods","bayesian-neural-networks","bayesian-statistics","data-science","machine-learning","python","pytorch","statistics","tensorflow"],"created_at":"2024-09-25T01:04:59.590Z","updated_at":"2025-04-07T12:03:52.014Z","avatar_url":"https://github.com/brendanhasz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"ProbFlow\n========\n\n|Version Badge|  |Build Badge|  |Docs Badge|  |Coverage Badge|\n\n.. |Version Badge| image:: https://img.shields.io/pypi/v/probflow\n    :target: https://pypi.org/project/probflow/\n\n.. |Build Badge| image:: https://github.com/brendanhasz/probflow/workflows/tests/badge.svg\n    :target: https://github.com/brendanhasz/probflow/actions?query=branch%3Amaster\n\n.. |Docs Badge| image:: https://readthedocs.org/projects/probflow/badge/\n    :target: http://probflow.readthedocs.io\n\n.. |Coverage Badge| image:: https://codecov.io/gh/brendanhasz/probflow/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/brendanhasz/probflow\n\n\nProbFlow is a Python package for building probabilistic Bayesian models with `TensorFlow 2.0 \u003chttp://www.tensorflow.org/beta\u003e`_ or `PyTorch \u003chttp://pytorch.org\u003e`_, performing stochastic variational inference with those models, and evaluating the models' inferences.  It provides both high-level modules for building Bayesian neural networks, as well as low-level parameters and distributions for constructing custom Bayesian models.\n\nIt's very much still a work in progress.\n\n- **Git repository:** http://github.com/brendanhasz/probflow\n- **Documentation:** http://probflow.readthedocs.io\n- **Bug reports:** http://github.com/brendanhasz/probflow/issues\n\n\nGetting Started\n---------------\n\n**ProbFlow** allows you to quickly and less painfully build, fit, and evaluate custom Bayesian models (or `ready-made \u003chttp://probflow.readthedocs.io/en/latest/api/applications.html\u003e`_ ones!) which run on top of either `TensorFlow 2.0 \u003chttp://www.tensorflow.org/beta\u003e`_ and `TensorFlow Probability \u003chttp://www.tensorflow.org/probability\u003e`_ or `PyTorch \u003chttp://pytorch.org\u003e`_.\n\nWith ProbFlow, the core building blocks of a Bayesian model are parameters and probability distributions (and, of course, the input data).  Parameters define how the independent variables (the features) predict the probability distribution of the dependent variables (the target).\n\nFor example, a simple Bayesian linear regression\n\n.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/regression_equation.svg?sanitize=true\n   :width: 30 %\n   :align: center\n\ncan be built by creating a ProbFlow Model.  This is just a class which inherits ``pf.Model`` (or ``pf.ContinuousModel`` or ``pf.CategoricalModel`` depending on the target type).  The ``__init__`` method sets up the parameters, and the ``__call__`` method performs a forward pass of the model, returning the predicted probability distribution of the target:\n\n.. code-block:: python\n\n    import probflow as pf\n    import tensorflow as tf\n\n    class LinearRegression(pf.ContinuousModel):\n\n        def __init__(self):\n            self.weight = pf.Parameter(name='weight')\n            self.bias = pf.Parameter(name='bias')\n            self.std = pf.ScaleParameter(name='sigma')\n\n        def __call__(self, x):\n            return pf.Normal(x*self.weight()+self.bias(), self.std())\n\n    model = LinearRegression()\n\nThen, the model can be fit using stochastic variational inference, in *one line*:\n\n.. code-block:: python\n\n    # x and y are Numpy arrays or pandas DataFrame/Series\n    model.fit(x, y)\n\nYou can generate predictions for new data:\n\n.. code-block:: pycon\n\n    # x_test is a Numpy array or pandas DataFrame\n    \u003e\u003e\u003e model.predict(x_test)\n    [0.983]\n\nCompute *probabilistic* predictions for new data, with 95% confidence intervals:\n\n.. code-block:: python\n\n    model.pred_dist_plot(x_test, ci=0.95)\n\n.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/pred_dist_light.svg?sanitize=true\n   :width: 90 %\n   :align: center\n\nEvaluate your model's performance using metrics:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e model.metric('mse', x_test, y_test)\n    0.217\n\nInspect the posterior distributions of your fit model's parameters, with 95% confidence intervals:\n\n.. code-block:: python\n\n    model.posterior_plot(ci=0.95)\n\n.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/posteriors_light.svg?sanitize=true\n   :width: 90 %\n   :align: center\n\nInvestigate how well your model is capturing uncertainty by examining how accurate its predictive intervals are:\n\n.. code-block:: pycon\n\n    \u003e\u003e\u003e model.pred_dist_coverage(ci=0.95)\n    0.903\n\nand diagnose *where* your model is having problems capturing uncertainty:\n\n.. code-block:: python\n\n    model.coverage_by(ci=0.95)\n\n.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/coverage_light.svg?sanitize=true\n   :width: 90 %\n   :align: center\n\nProbFlow also provides more complex modules, such as those required for building Bayesian neural networks.  Also, you can mix ProbFlow with TensorFlow (or PyTorch!) code.  For example, even a somewhat complex multi-layer Bayesian neural network like this:\n\n.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/dual_headed_net_light.svg?sanitize=true\n   :width: 99 %\n   :align: center\n\nCan be built and fit with ProbFlow in only a few lines:\n\n.. code-block:: python\n\n    class DensityNetwork(pf.ContinuousModel):\n\n        def __init__(self, units, head_units):\n            self.core = pf.DenseNetwork(units)\n            self.mean = pf.DenseNetwork(head_units)\n            self.std  = pf.DenseNetwork(head_units)\n\n        def __call__(self, x):\n            z = tf.nn.relu(self.core(x))\n            return pf.Normal(self.mean(z), tf.exp(self.std(z)))\n\n    # Create the model\n    model = DensityNetwork([x.shape[1], 256, 128], [128, 64, 32, 1])\n\n    # Fit it!\n    model.fit(x, y)\n\n\nFor convenience, ProbFlow also includes several `pre-built models \u003chttp://probflow.readthedocs.io/en/latest/api/applications.html\u003e`_ for standard tasks (such as linear regressions, logistic regressions, and multi-layer dense neural networks).  For example, the above linear regression example could have been done with much less work by using ProbFlow's ready-made LinearRegression model:\n\n.. code-block:: python\n\n    model = pf.LinearRegression(x.shape[1])\n    model.fit(x, y)\n\nAnd a multi-layer Bayesian neural net can be made easily using ProbFlow's ready-made DenseRegression model:\n\n.. code-block:: python\n\n    model = pf.DenseRegression([x.shape[1], 128, 64, 1])\n    model.fit(x, y)\n\nUsing parameters and distributions as simple building blocks, ProbFlow allows\nfor the painless creation of more complicated Bayesian models like `generalized\nlinear models \u003chttp://probflow.readthedocs.io/en/latest/examples/glm.html\u003e`_,\n`deep time-to-event models\n\u003chttp://probflow.readthedocs.io/en/latest/examples/time_to_event.html\u003e`_,\n`neural matrix factorization\n\u003chttp://probflow.readthedocs.io/en/latest/examples/nmf.html\u003e`_ models, and\n`Gaussian mixture models\n\u003chttp://probflow.readthedocs.io/en/latest/examples/gmm.html\u003e`_.  You can even\nmix `probabilistic and non-probabilistic models\n\u003chttp://probflow.readthedocs.io/en/latest/examples/neural_linear.html\u003e`_!  Take\na look at the `examples \u003chttp://probflow.readthedocs.io/en/latest/examples/examples.html\u003e`_\nand the `user guide \u003chttp://probflow.readthedocs.io/en/latest/user_guide/user_guide.html\u003e`_\nfor more!\n\n\nInstallation\n------------\n\nIf you already have your desired backend installed (i.e. Tensorflow/TFP or\nPyTorch), then you can just do:\n\n.. code-block:: bash\n\n    pip install probflow\n\nOr, to install both ProbFlow and the CPU version of TensorFlow + TensorFlow\nProbability,\n\n.. code-block:: bash\n\n    pip install probflow[tensorflow]\n\nOr, to install ProbFlow and the GPU version of TensorFlow + TensorFlow\nProbability,\n\n.. code-block:: bash\n\n    pip install probflow[tensorflow_gpu]\n\nOr, to install ProbFlow and PyTorch,\n\n.. code-block:: bash\n\n    pip install probflow[pytorch]\n\n\nSupport\n-------\n\nPost bug reports, feature requests, and tutorial requests in `GitHub issues \u003chttp://github.com/brendanhasz/probflow/issues\u003e`_.\n\n\nContributing\n------------\n\n`Pull requests \u003chttp://github.com/brendanhasz/probflow/pulls\u003e`_ are totally welcome!  Any contribution would be appreciated, from things as minor as pointing out typos to things as major as writing new applications and distributions.\n\n\nWhy the name, ProbFlow?\n-----------------------\n\nBecause it's a package for probabilistic modeling, and it was built on TensorFlow.  ¯\\\\_(ツ)_/¯\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendanhasz%2Fprobflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrendanhasz%2Fprobflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendanhasz%2Fprobflow/lists"}