Skip to content

Expand sampler-stats.ipynb example #1866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 7, 2017
Merged

Expand sampler-stats.ipynb example #1866

merged 6 commits into from
Mar 7, 2017

Conversation

junpenglao
Copy link
Member

@junpenglao junpenglao commented Mar 6, 2017

include model diagnose similar to case study example in Stan

@twiecki
Copy link
Member

twiecki commented Mar 6, 2017

@junpenglao This is great, thanks for the port. I think it would be better to have it as a separate NB though which links to the stats one.

@junpenglao
Copy link
Member Author

@twiecki No problem;-)

@fonnesbeck
Copy link
Member

fonnesbeck commented Mar 6, 2017

Thanks for this. Could you add some descriptive annotation to the notebook in markdown blocks? All of our notebook examples should be self-explanatory so that the user knows how to interpret the inputs and outputs of the model. This one in particular will be unfamiliar to many, so descriptive text will be helpful.

See some of the other notebooks for examples.

@twiecki
Copy link
Member

twiecki commented Mar 6, 2017

Depending on the license of the STAN docs we can also copy&paste the text.

@twiecki
Copy link
Member

twiecki commented Mar 6, 2017

CC-BY 4.0 license, so should be good.

@fonnesbeck
Copy link
Member

Also, please add axis labels to all plots.

@junpenglao
Copy link
Member Author

@fonnesbeck Sure.
BTW, is doing step = pm.NUTS(k=.85) the same as setting the adapt_delta=0.85 in Stan?
In a way, it is quite interesting that in PyMC3, the pathological samples from the trace is not necessary at the funnel (unlike Stan), and the sampler is generally doing a better job exploring the high curvature area even for a poorly parameterized model (at least in this example). I am not sure if this generalised to other models, but it might also mean that diagnosing biased inference is more difficult in PyMC3.

@fonnesbeck
Copy link
Member

fonnesbeck commented Mar 6, 2017

No, adapt_delta in pystan corresponds to target_accept in PyMC3.

adapt_kappa corresponds to k.

@fonnesbeck
Copy link
Member

Looks good from here

@twiecki
Copy link
Member

twiecki commented Mar 7, 2017

@junpenglao Looks great. Can you fix the pep8 issues in the model:

with pm.Model() as Centered_eight:
    mu = pm.Normal('mu',mu=0,sd=5)
    tau = pm.HalfCauchy('tau',beta=5)
    theta = pm.Normal('theta',mu=mu,sd=tau,shape = J)
    obs = pm.Normal('obs',mu=theta,sd=sigma,observed = y)

(spaces after , and no spaces around kwargs).

You can also link to my blog post on the same issue: http://twiecki.github.io/blog/2017/02/08/bayesian-hierchical-non-centered/

Good question regarding the divergences not being close to the funnel. @aseyboldt any ideas?

@twiecki
Copy link
Member

twiecki commented Mar 7, 2017

Also, lets explicitly ask @betanalpha if he's fine with us porting his blog post.

@junpenglao
Copy link
Member Author

Thanks for the patient answers I am complete newbie :-)
@twiecki Fixing the styling now. I already cited your post but will now make it more apparent.
Also, I am sending @betanalpha an email now.

@betanalpha
Copy link

The code in the case study is BSD (3 clause), the text is CC BY-NC 4.0.

@twiecki
Copy link
Member

twiecki commented Mar 7, 2017

@junpenglao Did you change docs/source/notebooks/sampler-stats.ipynb? If not, should not show up in the diff.

@twiecki
Copy link
Member

twiecki commented Mar 7, 2017

@junpenglao Also need to add this to docs/source/examples.rst, probably under how-to.

@fonnesbeck
Copy link
Member

Just a picky thing: maybe use a Markdown quote block (>) for the direct quotes from Betancourt's paper/blog post. It will look better, and be more visually apparent that it is a quote.

1, add example to examples.rst
2, original content in Markdown code block
@junpenglao
Copy link
Member Author

@junpenglao Did you change docs/source/notebooks/sampler-stats.ipynb? If not, should not show up in the diff.

I did not - but ipynb picked up the change when I ran the notebook.

@junpenglao Also need to add this to docs/source/examples.rst, probably under how-to.

Cool.

Just a picky thing: maybe use a Markdown quote block (>) for the direct quotes from Betancourt's paper/blog post. It will look better, and be more visually apparent that it is a quote.

Done.

@twiecki twiecki merged commit 202496f into pymc-devs:master Mar 7, 2017
@twiecki
Copy link
Member

twiecki commented Mar 7, 2017

Thanks for the great contribution @junpenglao.

davidbrochart pushed a commit to davidbrochart/pymc3 that referenced this pull request Mar 27, 2017
* Expand sampler-stats.ipynb example

include model diagnose from case study example in Stan http://mc-stan.org/documentation/case-studies/divergences_and_bias.html

* Sampler Diagnose for NUTS

* descriptive annotation and axis labels

* Fix typos

* PEP8 styling

* minor updates

1, add example to examples.rst
2, original content in Markdown code block
twiecki pushed a commit that referenced this pull request Mar 27, 2017
* Added live_traceplot function

* Cosmetic change

* Changed the API to pm.sample(..., live_plot=True)

* Don't include `-np.inf` in calculating average ELBO (#1880)

* Adds an infmean for advi reporting

* fixing typo

* Add tutorial to detect sampling problems (#1866)

* Expand sampler-stats.ipynb example

include model diagnose from case study example in Stan http://mc-stan.org/documentation/case-studies/divergences_and_bias.html

* Sampler Diagnose for NUTS

* descriptive annotation and axis labels

* Fix typos

* PEP8 styling

* minor updates

1, add example to examples.rst
2, original content in Markdown code block

* Make install scripts idempotent (#1879)

* DOC Change heading names.

* Add examples of censored data models (#1870)

* Raise TypeError on non-data values of observed (#1872)

* Raise TypeError on non-data values of observed

* Added check for observed TypeError

* Make exponential mode have the correct shape

* Fix support of LKJCorr

* Added tutorial notebook on updating priors

* Fixed y-axis bug in forestplot; added transform argument to summary

* Style cleanup

* Made small changes and executed the notebook

* Added probit and invprobit functions

* Added carriage return to end of file

* Fixed indentation

* Changed probit test to use assert_allclose

* Fix tests for LKJCorr

* Added warning for ignoring init arguments in sample

* Kill stray tab

* Improve performance of transformations

* DOC Add new features

* Bump version.

* Added docs and scripts to MANIFEST

* WIP: Implement opvi (#1694)

* migrate useful functions from previous PR

(cherry picked from commit 9f61ab4)

* opvi draft

(cherry picked from commit d0997ff)

* made some test work

(cherry picked from commit b1a87d5)

* refactored approximation to support aevb (without test)

* refactor opvi

delete unnecessary methods from operator, change method order

* change log_q_local computation

* add full rank approximation

* add more_params argument to ObjectiveFunction.updates (aevb case)

* refactor density computation in full rank approximation

* typo: cast dict values to list

* typo: cast dict values to list

* typo: undefined T in dist_math

* refactor gradient scaling as suggested in approximateinference.org/accepted/RoederEtAl2016.pdf

* implement Langevin-Stein (LS) operator

* fix docstring

* add blank line in docs

* refactor ObjectiveFunction

* add not working LS Op test

* experiments with not working LS Op

* change activations

* refactor networks

* add step_function

* remove Langevin Stein, done refactoring

* remove Langevin Stein, done refactoring

* change optimizers

* refactor init params

* implement tests

* implement Inference

* code style

* test fix

* add minibatch test (fails now)

* add more tests for minibatch training

* add logdet to FullRank approximation

* add conversion of arrays to floatX

* tiny changes

* change number of iterations

* fix test and pylint check

* memoize functions in Objective function

* Optimize code a lot

* a bit more efficient pickling

* add docs

* Add MeanField -> FullRank parameter transfer

* refactor MeanField and FullRank a bit

* fix FullRank bug with shapes in random

* refactor Model.flatten (CC @taku-y)

* add `approximate` to inference

* rename approximate->fit

* change abbreviations

* Fix bug with scaling input variable in aevb

* fix theano bottleneck in graph

* more efficient scaling for local vars

* fix typo in local Q

* add aevb test

* refactor memoize to work with my objects

* add tests for numpy view usage

* pickle-hash fix

* pickle-hash fix again

* add node sampling + make up some code

* add notebook with example

* sample_proba explained

* Revert "small fix for multivariate mixture models"

* Added message about init only working with auto-assigned step methods

* doc(DiagInferDiv): formatting fix in blog post quote. Closes #1895. (#1909)

* delete unnecessary text and add some benchmarks (#1901)

* Add LKJCholeskyCov

* Added newline to MANIFEST

* Replaced package list with find_packages in setup.py; removed examples/data/__init__.py

* Fix log jacobian in LKJCholeskyCov

* Updated version to rc2

* Fixed stray version string

* Fix indexing traces with steps greater one

* refactor variational module, add histogram approximation (#1904)

* refactor module, add histogram

* add more tests

* refactor some code concerning AEVB histogram

* fix test for histogram

* use mean as deterministic point in Histogram

* remove unused import

* change names of shortcuts

* add names to shared params

* add new line at the end of `approximations.py`

* Add documentation for LKJCholeskyCov

* SVGD problems (#1916)

* fix some svgd problems

* switch -> ifelse

* except in record

* Histogram docs (#1914)

* add docs

* delete redundant code

* add usage example

* remove unused import

* Add expand_packed_triangular

* improve aesthetics

* Bump theano to 0.9.0rc4 (#1921)

* Add tests for LKJCholeskyCov

* Histogram: use only free RVs from trace (#1926)

* use only free RVs from trace

* use memoize in Histogram.histogram_logp

* Change tests for histogram

* Bump theano to be at least 0.9.0

* small fix to prevent a TypeError with the ufunc true_divide

* Fix tests for py2

* Add floatX wrappers in test_advi

* Changed the API to pm.sample(..., live_plot=True)

* Better formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants