-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from bayesmix-dev/development
Development
- Loading branch information
Showing
150 changed files
with
9,530 additions
and
5,739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,15 @@ Current state of the software: | |
|
||
- `bayesmix` performs inference for mixture models of the kind | ||
|
||
<img src="https://latex.codecogs.com/svg.image?\begin{align*}y_1,\dots,y_n&space;&\sim&space;\int&space;k(\cdot&space;\mid&space;\theta)P(\mathrm{d}\theta)\\P&space;&\sim&space;\Pi\end{align*}&space;" title="\begin{align*}y_1,\dots,y_n &\sim \int k(\cdot \mid \theta)P(\mathrm{d}\theta)\\P &\sim \Pi\end{align*} " /> | ||
|
||
<!--- | ||
<a href="https://www.codecogs.com/eqnedit.php?latex=y_1,&space;\ldots,&space;y_n&space;\sim&space;\int&space;k(\cdot&space;\mid&space;\theta)&space;P(d\theta)" target="_blank"><img src="https://latex.codecogs.com/gif.latex?y_1,&space;\ldots,&space;y_n&space;\sim&space;\int&space;k(\cdot&space;\mid&space;\theta)&space;P(d\theta)" title="y_1, \ldots, y_n \sim \int k(\cdot \mid \theta) \Pi(d\theta)" /></a> | ||
<a href="https://www.codecogs.com/eqnedit.php?latex=P&space;\sim&space;\Pi" target="_blank"><img src="https://latex.codecogs.com/gif.latex?P&space;\sim&space;\Pi" title="\Pi \sim P" /></a> | ||
--> | ||
|
||
where P is either the Dirichlet process or the Pitman--Yor process | ||
|
||
- We currently support univariate and multivariate location-scale mixture of Gaussian densities | ||
|
||
- Inference is carried out using algorithms such as Algorithm 2 in [Neal (2000)](http://www.stat.columbia.edu/npbayes/papers/neal_sampling.pdf) | ||
|
||
- Serialization of the MCMC chains is possible using Google's [Protocol Buffers](https://developers.google.com/protocol-buffers) aka `protobuf` | ||
For descriptions of the models supported in our library, discussion of software design, and examples, please refer to the following paper: https://arxiv.org/abs/2205.08144 | ||
|
||
# Installation | ||
|
||
|
@@ -29,7 +27,7 @@ where P is either the Dirichlet process or the Pitman--Yor process | |
To install and use `bayesmix`, please `cd` to the folder to which you wish to install it, and clone this repository with the following command-line instruction: | ||
|
||
```shell | ||
git clone --recurse-submodule [email protected]:bayesmix-dev/bayesmix.git | ||
git clone --recurse-submodules [email protected]:bayesmix-dev/bayesmix.git | ||
``` | ||
|
||
Then, by using `cd bayesmix`, you will enter the newly downloaded folder. | ||
|
@@ -39,8 +37,8 @@ To build the executable for the main file `run_mcmc.cc`, please use the followin | |
```shell | ||
mkdir build | ||
cd build | ||
cmake .. -DDISABLE_DOCS=on -DDISABLE_BENCHMARKS=on -DDISABLE_TESTS=on | ||
make run | ||
cmake .. -DDISABLE_DOCS=ON -DDISABLE_BENCHMARKS=ON -DDISABLE_TESTS=ON | ||
make run_mcmc | ||
cd .. | ||
``` | ||
|
||
|
@@ -97,3 +95,4 @@ Documentation is available at https://bayesmix.readthedocs.io. | |
# Contributions are welcome! | ||
|
||
Please check out [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to collaborate with us. | ||
You can also head to our [issues page](https://github.com/bayesmix-dev/bayesmix/issues) to check for useful enhancements needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
bayesmix/hierarchies/likelihoods | ||
|
||
Likelihoods | ||
=========== | ||
|
||
The ``Likelihood`` sub-module represents the likelihood we have assumed for the data in a given cluster. Each ``Likelihood`` class represents the sampling model | ||
|
||
.. math:: | ||
y_1, \ldots, y_k \mid \bm{\tau} \stackrel{\small\mathrm{iid}}{\sim} f(\cdot \mid \bm{\tau}) | ||
for a specific choice of the probability density function :math:`f`. | ||
|
||
------------------------- | ||
Main operations performed | ||
------------------------- | ||
|
||
A likelihood object must be able to perform the following operations: | ||
|
||
a. First of all, we require the ``lpdf()`` and ``lpdf\_grid()`` methods, which simply evaluate the loglikelihood in a given point or in a grid of points (also in case of a \emph{dependent} likelihood, i.e., with covariates associated to each observation) [``lpdf()`` and ``lpdf_grid``] | ||
b. In case you want to rely on a Metropolis-like updater, the likelihood needs to evaluation of the likelihood of the whole cluster starting from the vector of unconstrained parameters [``cluster_lpdf_from_unconstrained()``]. Observe that the ``AbstractLikelihood`` class provides two such methods, one returning a ``double`` and one returning a ``stan::math::var``. The latter is used to automatically compute the gradient of the likelihood via Stan's automatic differentiation, if needed. In practice, users do not need to implement both methods separately and can implement only one templated method | ||
c. manage the insertion and deletion of a datum in the cluster [``add_datum`` and ``remove_datum``] | ||
d. update the summary statistics associated to the likelihood [``update_summary_statistics``]. Summary statistics (when available) are used to evaluate the likelihood function on the whole cluster, as well as to perform the posterior updates of :math:`\bm{\tau}`. This usually gives a substantial speedup | ||
|
||
-------------- | ||
Code structure | ||
-------------- | ||
|
||
In principle, the ``Likelihood`` classes are responsible only of evaluating the log-likelihood function given a specific choice of parameters :math:`\bm{\tau}`. | ||
Therefore, a simple inheritance structure would seem appropriate. However, the nature of the parameters :math:`\bm{\tau}` can be very different across different models (think for instance of the difference between the univariate normal and the multivariate normal paramters). As such, we employ CRTP to manage the polymorphic nature of ``Likelihood`` classes. | ||
|
||
The class ``AbstractLikelihood`` defines the API, i.e. all the methods that need to be called from outside of a ``Likelihood`` class. | ||
A template class ``BaseLikelihood`` inherits from ``AbstractLikelihood`` and implements some of the necessary virtual methods, which need not be implemented by the child classes. | ||
|
||
Instead, child classes **must** implement: | ||
|
||
a. ``compute_lpdf``: evaluates :math:`k(x \mid \theta_h)` | ||
b. ``update_sum_stats``: updates the summary statistics when an observation is allocated or de-allocated from the hierarchy | ||
c. ``clear_summary_statistics``: clears all the summary statistics | ||
d. ``is_dependent``: defines if the given likelihood depends on covariates | ||
e. ``is_multivariate``: defines if the given likelihood is for multivariate data | ||
|
||
In case the likelihood needs to be used in a Metropolis-like updater, child classes **should** also implement: | ||
|
||
f. ``cluster_lpdf_from_unconstrained``: evaluates :math:`\prod_{i: c_i = h} k(x_i \mid \tilde{\theta}_h)`, where :math:`\tilde{\theta}_h` is the vector of unconstrained parameters. | ||
|
||
---------------- | ||
Abstract Classes | ||
---------------- | ||
|
||
.. doxygenclass:: AbstractLikelihood | ||
:project: bayesmix | ||
:members: | ||
.. doxygenclass:: BaseLikelihood | ||
:project: bayesmix | ||
:members: | ||
|
||
---------------------------------- | ||
Classes for Univariate Likelihoods | ||
---------------------------------- | ||
|
||
.. doxygenclass:: UniNormLikelihood | ||
:project: bayesmix | ||
:members: | ||
:protected-members: | ||
.. doxygenclass:: UniLinRegLikelihood | ||
:project: bayesmix | ||
:members: | ||
:protected-members: | ||
.. doxygenclass:: LaplaceLikelihood | ||
:project: bayesmix | ||
:members: | ||
:protected-members: | ||
|
||
------------------------------------ | ||
Classes for Multivariate Likelihoods | ||
------------------------------------ | ||
|
||
.. doxygenclass:: MultiNormLikelihood | ||
:project: bayesmix | ||
:members: | ||
:protected-members: | ||
.. doxygenclass:: FALikelihood | ||
:project: bayesmix | ||
:members: | ||
:protected-members: |
Oops, something went wrong.