probcomp / Venturecxx

Primary implementation of the Venture probabilistic programming system
http://probcomp.csail.mit.edu/venture/
GNU General Public License v3.0
28 stars 6 forks source link

Resuscitate the model prelude #213

Open axch opened 8 years ago

axch commented 8 years ago

Right now we have 26 "standard" definitions of compound procedures stored in a concept called the "model prelude". The issues with this are:

It therefore seems appropriate to

Note: The model prelude is heavier-weight than the inference prelude because it is traced in a full PET, as many times as there are particles, whereas the inference prelude is evaluated in the untraced backend and only once.

axch commented 8 years ago

The story on performance:

|                               | No prelude | Small prelude | Full prelude | Units |
|-------------------------------+------------+---------------+--------------+-------|
| Lite all tests                |   1165.324 |               |     1950.859 | sec   |
| Lite test_ripl.py             |    283.842 |               |      258.032 | sec   |
|-------------------------------+------------+---------------+--------------+-------|
| Puma make ripl                |       4.52 |          13.7 |         17.0 | msec  |
| Lite make ripl                |       4.59 |          15.9 |         19.7 | msec  |
| Puma infer resample 30        |       15.3 |          20.5 |         23.3 | msec  |
| Lite infer resample 30        |       14.0 |          46.9 |         61.3 | msec  |
|-------------------------------+------------+---------------+--------------+-------|
| Puma infer reset_to_prior     |        461 |               |          481 | usec  |
| Lite infer reset_to_prior     |        634 |               |          633 | usec  |
| Puma reinit_inference_problem |        105 |               |          861 | usec  |
| Lite reinit_inference_problem |        288 |               |         3430 | usec  |
|-------------------------------+------------+---------------+--------------+-------|

"Small Prelude" means commenting out the three definitions that have to do with rms error computations, which carry relatively large code bodies for the generality of their usefulness.

The timings are obtained with Python's timeit module, as follows:

- Lite ripl
  python -m timeit -n 100 -s "import venture.shortcuts as s; r = s.make_lite_church_prime_ripl()" "s.make_lite_church_prime_ripl()"
- Lite resample 30
  python -m timeit -n 100 -s "import venture.shortcuts as s; r = s.make_lite_church_prime_ripl(); r.assume('x', '(normal 0 1)')" "r.infer('(resample 30)')"
- Lite infer reset_to_prior
  python -m timeit -s "import venture.shortcuts as s; r = s.make_lite_church_prime_ripl(); r.assume('x', '(normal 0 1)')" "r.infer('reset_to_prior')"
- Lite reinit inference problem
  python -m timeit -s "import venture.shortcuts as s; r = s.make_lite_church_prime_ripl(); r.assume('x', '(normal 0 1)')" "r.sivm.core_sivm.engine.reinit_inference_problem()"
axch commented 8 years ago

This is after whittling the prelude down to 15 definitions, the removal of any of which would (formally) constitute a retrogression, as we do not in fact currently have them available as primitives.

axch commented 8 years ago

Taylor says, "We really ought to solve the problem of the existence of library definitions slowing inference to a crawl, because people will eventually want there to be libraries."

axch commented 8 years ago

Will also want new_model to install the model prelude into the new model, if it is on.

lenaqr commented 8 years ago

Seeing as #225 is blocked on this, I have a suggestion.

Currently load_plugin searches a number of paths, including a standard plugins directory in this repo. Would it be possible to introduce a load_script that searches the same paths (or maybe a different one) and have that be a place to put standard library functions like this?

This would also be a way to have separate piles of library code that does different things, so you don't have to pull in a whole bunch of unrelated stuff just to get ref and deref, since bloat was a concern with the old model prelude.