Skip to content

Conversation

@ColCarroll
Copy link
Member

Started refactoring Hamiltonian methods into a common base class. This lets HamiltonianMC share some theano machinery from NUTS, and provides a ~2x speedup using the benchmark from #1570. The same PR also shows that I haven't changed either algorithm at all.

My larger plan is to use the approach from @betanalpha's exhaustive monte carlo paper (#1497) to provide different theano functions for expanding trajectory, checking trajectory, and checking termination so that HMC, NUTS, and XHMC can share (optimized) machinery, and perhaps there can be easy experiments with further mixing of methods. I'm hoping to have a PR soon where BaseHMC implements algorithm 2 from the paper as astep, so that the implementation of NUTS and HamiltonianMC is only an __init__ which prepares the appropriate functions.

Also, note that this will be merged into 3.1, not 3.0.

fonnesbeck and others added 4 commits November 28, 2016 05:36
…tting (e.g. nanguardmode) for Theano functions
* Started to write Base class for pymc3.models

* mode `add_var` to public api

* Added some docstrings

* Added some docstrings

* added getitem and fixed a typo

* added assertion check

* added resolve var method

* decided not to add resolve method

* Added linear component

* Docs fix

* patsy's intercept is inited properly now

* refactored code

* updated docs

* added possibility to init coefficients with random variables

* added glm

* refactored api, fixed formula init

* refactored linear model, extended acceptable types

* moved useful matrix and labels creation to utils file

* code style

* removed redundant evaluation of shape

* refactored resolver for constructing matrix and labels

* changed error message

* changed signature of init

* simplified utils any_to_tensor_and_labels code

* tests for `any_to_tensor_and_labels`

* added docstring for `any_to_tensor_and_labels` util

* forgot to document return type in `any_to_tensor_and_labels`

* refactored code for dict

* dict tests fix(do not check labels there)

* added access to random vars of model

* added a shortcut for all variables so there is a unified way to get them

* added default priors for linear model

* update docs for linear

* refactored UserModel api, made it more similar to pm.Model class

* Lots of refactoring, tests for base class, more plain api design

* deleted unused module variable

* fixed some typos in docstring

* Refactored pm.Model class, now it is ready for inheritance

* Added documentation for Model class

* Small typo in docstring

* nested contains for treedict (needed for add_random_variable)

* More accurate duplicate implementation of treedict/treelist

* refactored treedict/treelist

* changed `__imul__` of treelist

* added `root` property and `isroot` indicator for base model

* protect `parent` and `model` attributes from violation

* travis' python2 did not fail on bad syntax(maybe it's too new), fixed

* decided not to use functools wrapper

 Unfortunately functools wrapper fails
 when decorating built-in methods so I
 need to fix that improper behaviour.
 Some bad but needed tricks were implemented

* Added models package to setup script

* Refactor utils

* Fix some typos in pm.model
@ColCarroll
Copy link
Member Author

Ah frig, I think we need to rebase 3.1 off master, then I will rebase this. Happy for thoughts in the meantime.

"""
Parameters
----------
vars : list of theano variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to indent that level.

@twiecki
Copy link
Member

twiecki commented Dec 3, 2016

I skimmed over it, looks like a good refactor. Seems like you didn't touch much of the math, correct?

@ColCarroll
Copy link
Member Author

No math changes -- I brought a test case in from master to make sure the sampling stayed exactly the same. The only change an end user will see from this is the performance speedup in HamiltonianMC.

@twiecki
Copy link
Member

twiecki commented Dec 5, 2016

Sorry, I rebased the 3.1 branch off of master and resolved a conflict, looks like you'll have to rebase this one.

@twiecki
Copy link
Member

twiecki commented Dec 5, 2016

I attempted to do the merge myself, can you see if I messed anything up: ea82ebd 140a80c

@twiecki twiecki closed this Dec 5, 2016
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