All Projects → brendanhasz → Probflow

brendanhasz / Probflow

Licence: mit
A Python package for building Bayesian models with TensorFlow or PyTorch

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Probflow

Bayesian Cognitive Modeling In Pymc3
PyMC3 codes of Lee and Wagenmakers' Bayesian Cognitive Modeling - A Pratical Course
Stars: ✭ 93 (-2.11%)
Mutual labels:  data-science, statistics, bayesian-inference, bayesian-methods
Probability
Probabilistic reasoning and statistical analysis in TensorFlow
Stars: ✭ 3,550 (+3636.84%)
Mutual labels:  data-science, statistics, bayesian-methods
Rstanarm
rstanarm R package for Bayesian applied regression modeling
Stars: ✭ 285 (+200%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Bayesian Analysis Recipes
A collection of Bayesian data analysis recipes using PyMC3
Stars: ✭ 479 (+404.21%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Stan
Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
Stars: ✭ 2,177 (+2191.58%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Uncertainty Metrics
An easy-to-use interface for measuring uncertainty and robustness.
Stars: ✭ 145 (+52.63%)
Mutual labels:  data-science, statistics, bayesian-methods
Edward2
A simple probabilistic programming language.
Stars: ✭ 419 (+341.05%)
Mutual labels:  data-science, statistics, bayesian-methods
Stats Maths With Python
General statistics, mathematical programming, and numerical/scientific computing scripts and notebooks in Python
Stars: ✭ 381 (+301.05%)
Mutual labels:  data-science, statistics, bayesian-statistics
Probabilistic Programming And Bayesian Methods For Hackers
aka "Bayesian Methods for Hackers": An introduction to Bayesian methods + probabilistic programming with a computation/understanding-first, mathematics-second point of view. All in pure Python ;)
Stars: ✭ 23,912 (+25070.53%)
Mutual labels:  data-science, statistics, bayesian-methods
Bat.jl
A Bayesian Analysis Toolkit in Julia
Stars: ✭ 82 (-13.68%)
Mutual labels:  statistics, bayesian-inference, bayesian-statistics
Rhat ess
Rank-normalization, folding, and localization: An improved R-hat for assessing convergence of MCMC
Stars: ✭ 19 (-80%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Dynamichmc.jl
Implementation of robust dynamic Hamiltonian Monte Carlo methods (NUTS) in Julia.
Stars: ✭ 172 (+81.05%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Shinystan
shinystan R package and ShinyStan GUI
Stars: ✭ 172 (+81.05%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Uncertainty Baselines
High-quality implementations of standard and SOTA methods on a variety of tasks.
Stars: ✭ 278 (+192.63%)
Mutual labels:  data-science, statistics, bayesian-methods
Rethinking Pyro
Statistical Rethinking with PyTorch and Pyro
Stars: ✭ 116 (+22.11%)
Mutual labels:  bayesian-inference, bayesian-statistics, bayesian-methods
Edward
A probabilistic programming language in TensorFlow. Deep generative models, variational inference.
Stars: ✭ 4,674 (+4820%)
Mutual labels:  data-science, statistics, bayesian-methods
Looper
A resource list for causality in statistics, data science and physics
Stars: ✭ 23 (-75.79%)
Mutual labels:  data-science, statistics, bayesian-inference
Resources
PyMC3 educational resources
Stars: ✭ 930 (+878.95%)
Mutual labels:  data-science, bayesian-inference, bayesian-statistics
25daysinmachinelearning
I will update this repository to learn Machine learning with python with statistics content and materials
Stars: ✭ 53 (-44.21%)
Mutual labels:  data-science, statistics
Ppd599
USC urban data science course series with Python and Jupyter
Stars: ✭ 1,062 (+1017.89%)
Mutual labels:  data-science, statistics

ProbFlow

|Version Badge| |Build Badge| |Docs Badge| |Coverage Badge|

.. |Version Badge| image:: https://img.shields.io/pypi/v/probflow :target: https://pypi.org/project/probflow/

.. |Build Badge| image:: https://github.com/brendanhasz/probflow/workflows/tests/badge.svg :target: https://github.com/brendanhasz/probflow/actions?query=branch%3Amaster

.. |Docs Badge| image:: https://readthedocs.org/projects/probflow/badge/ :target: http://probflow.readthedocs.io

.. |Coverage Badge| image:: https://codecov.io/gh/brendanhasz/probflow/branch/master/graph/badge.svg :target: https://codecov.io/gh/brendanhasz/probflow

ProbFlow is a Python package for building probabilistic Bayesian models with TensorFlow 2.0 <http://www.tensorflow.org/beta>_ or PyTorch <http://pytorch.org>_, 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.

It's very much still a work in progress.

Getting Started

ProbFlow allows you to quickly and less painfully build, fit, and evaluate custom Bayesian models (or ready-made <http://probflow.readthedocs.io/en/latest/api/applications.html>_ ones!) which run on top of either TensorFlow 2.0 <http://www.tensorflow.org/beta>_ and TensorFlow Probability <http://www.tensorflow.org/probability>_ or PyTorch <http://pytorch.org>_.

With 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).

For example, a simple Bayesian linear regression

.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/regression_equation.svg?sanitize=true :width: 30 % :align: center

can 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:

.. code-block:: python

import probflow as pf
import tensorflow as tf

class LinearRegression(pf.ContinuousModel):

    def __init__(self):
        self.weight = pf.Parameter(name='weight')
        self.bias = pf.Parameter(name='bias')
        self.std = pf.ScaleParameter(name='sigma')

    def __call__(self, x):
        return pf.Normal(x*self.weight()+self.bias(), self.std())

model = LinearRegression()

Then, the model can be fit using stochastic variational inference, in one line:

.. code-block:: python

# x and y are Numpy arrays or pandas DataFrame/Series
model.fit(x, y)

You can generate predictions for new data:

.. code-block:: pycon

# x_test is a Numpy array or pandas DataFrame
>>> model.predict(x_test)
[0.983]

Compute probabilistic predictions for new data, with 95% confidence intervals:

.. code-block:: python

model.pred_dist_plot(x_test, ci=0.95)

.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/pred_dist.svg?sanitize=true :width: 90 % :align: center

Evaluate your model's performance using metrics:

.. code-block:: pycon

>>> model.metric('mse', x_test, y_test)
0.217

Inspect the posterior distributions of your fit model's parameters, with 95% confidence intervals:

.. code-block:: python

model.posterior_plot(ci=0.95)

.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/posteriors.svg?sanitize=true :width: 90 % :align: center

Investigate how well your model is capturing uncertainty by examining how accurate its predictive intervals are:

.. code-block:: pycon

>>> model.pred_dist_coverage(ci=0.95)
0.903

and diagnose where your model is having problems capturing uncertainty:

.. code-block:: python

model.coverage_by(ci=0.95)

.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/coverage.svg?sanitize=true :width: 90 % :align: center

ProbFlow 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:

.. image:: https://raw.githubusercontent.com/brendanhasz/probflow/master/docs/img/dual_headed_net.svg?sanitize=true :width: 99 % :align: center

Can be built and fit with ProbFlow in only a few lines:

.. code-block:: python

class DensityNetwork(pf.ContinuousModel):

    def __init__(self, units, head_units):
        self.core = pf.DenseNetwork(units)
        self.mean = pf.DenseNetwork(head_units)
        self.std  = pf.DenseNetwork(head_units)

    def __call__(self, x):
        z = tf.nn.relu(self.core(x))
        return pf.Normal(self.mean(z), tf.exp(self.std(z)))

# Create the model
model = DensityNetwork([x.shape[1], 256, 128], [128, 64, 32, 1])

# Fit it!
model.fit(x, y)

For convenience, ProbFlow also includes several pre-built models <http://probflow.readthedocs.io/en/latest/api/applications.html>_ 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:

.. code-block:: python

model = pf.LinearRegression(x.shape[1])
model.fit(x, y)

And a multi-layer Bayesian neural net can be made easily using ProbFlow's ready-made DenseRegression model:

.. code-block:: python

model = pf.DenseRegression([x.shape[1], 128, 64, 1])
model.fit(x, y)

Using parameters and distributions as simple building blocks, ProbFlow allows for the painless creation of more complicated Bayesian models like generalized linear models <http://probflow.readthedocs.io/en/latest/examples/glm.html>, deep time-to-event models <http://probflow.readthedocs.io/en/latest/examples/time_to_event.html>, neural matrix factorization <http://probflow.readthedocs.io/en/latest/examples/nmf.html>_ models, and Gaussian mixture models <http://probflow.readthedocs.io/en/latest/examples/gmm.html>. You can even mix probabilistic and non-probabilistic models <http://probflow.readthedocs.io/en/latest/examples/neural_linear.html>! Take a look at the examples <http://probflow.readthedocs.io/en/latest/examples/examples.html>_ and the user guide <http://probflow.readthedocs.io/en/latest/user_guide/user_guide.html>_ for more!

Installation

If you already have your desired backend installed (i.e. Tensorflow/TFP or PyTorch), then you can just do:

.. code-block:: bash

pip install probflow

Or, to install both ProbFlow and the CPU version of TensorFlow + TensorFlow Probability,

.. code-block:: bash

pip install probflow[tensorflow]

Or, install ProbFlow and the GPU version of TensorFlow + TensorFlow Probability,

.. code-block:: bash

pip install probflow[tensorflow_gpu]

Or, to install ProbFlow and PyTorch,

.. code-block:: bash

pip install probflow[pytorch]

Support

Post bug reports, feature requests, and tutorial requests in GitHub issues <http://github.com/brendanhasz/probflow/issues>_.

Contributing

Pull requests <http://github.com/brendanhasz/probflow/pulls>_ 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.

Why the name, ProbFlow?

Because it's a package for probabilistic modeling, and it was built on TensorFlow. ¯\(ツ)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].