Skip to content

Commit

Permalink
Merge pull request #19 from UM-Bridge/marlenaweidenauer-patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
linusseelinger committed Jun 2, 2023
2 parents 07ac377 + 39fb326 commit 4374ea1
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion clients/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,52 @@ idata = tda.to_inference_data(my_chains, burnin=1000)
az.summary(idata)
```

[Full example sources here.](https://github.com/UM-Bridge/umbridge/blob/main/clients/python/tinyDA-client.ipynb)
[Full example sources here.](https://github.com/UM-Bridge/umbridge/blob/main/clients/python/tinyDA-client.ipynb)

## emcee client

emcee is a python implementation of the affine-invariant ensemble sampler for Markov chain Monte Carlo (MCMC). It supports UM-Bridge models and can be installed from pip just like UM-Bridge.

```
pip install umbridge emcee
```

A basic emcee example using an UM-Bridge model is shown below.

```
import emcee
from umbridge.emcee import UmbridgeLogProb
import arviz as az
import argparse
import numpy as np
import matplotlib.pyplot as plt
if __name__ == "__main__":
# Read URL from command line argument
parser = argparse.ArgumentParser(description='Minimal emcee sampler demo.')
parser.add_argument('url', metavar='url', type=str,
help='the ULR on which the model is running, for example http://localhost:4242')
args = parser.parse_args()
print(f'Connecting to host URL {args.url}')
log_prob = UmbridgeLogProb(args.url, 'posterior')
nwalkers = 32
sampler = emcee.EnsembleSampler(nwalkers, log_prob.ndim, log_prob)
# run sampler
p0 = np.random.rand(nwalkers, log_prob.ndim)
state = sampler.run_mcmc(p0, 100)
# plot results
inference_data = az.from_emcee(sampler)
az.plot_pair(inference_data)
plt.tight_layout()
plt.savefig('emcee_inference.png')
print(az.summary(inference_data, round_to=2))
```

[Full example sources here.](https://github.com/UM-Bridge/umbridge/blob/main/clients/python/emcee-client.py)

0 comments on commit 4374ea1

Please sign in to comment.