JohannesBuchner / PyMultiNest

Pythonic Bayesian inference and visualization for the MultiNest Nested Sampling Algorithm and PyCuba's cubature algorithms.
http://johannesbuchner.github.io/PyMultiNest/
Other
195 stars 88 forks source link

pymultinest_demo.py --- problem with Python graphics #39

Closed pasaric closed 10 years ago

pasaric commented 10 years ago

Dear Johannes Buchner,

thank you very much for your effort on PyMultiNest. I am Zoran Pasaric, working at Geophysical Institute, Faculty of Science, University of Zagreb, Croatia. I am mathematician by education, but working for a long time in oceanography and climatology. I am proficient in Matlab and (have been proficient) in Fortran 77, but have working understanding of Fortran 95. I have reasonable knowledge on bash an Linux (currently Ubuntu 14.04). Regarding Python, I am totally new, but eager to learn.

I tried various recipes offered on your pages to install PyMultiNest, but with only partial success. Thus, I was able to compile and run MultiNest (MultiNest_v3.6_CMake) using Intel compiler, v. 13.0.1 (gfortran seems to be very strict, so the cwrapper.f90 did not compile).

I was able to install PyMultyNest and to perform python -c 'import pymultinest'

Then python ../pymultinest_demo_minimal.py as well as ipython ../pymultinest_demo_minimal.py works OK. So, the fortran interface seem to work.

However, if I try

rm chains/* python ../pymultinest_demo.py

I get ------------------------------ ANALYSIS ------------------------------ Global Evidence:

2.357900664501498e+02 +- 7.869582834473685e-02

after which problems with graphics occur. Namely, I get some graphics, with only one figure (1-phys_live.points.pdf), with somewhat strange behavior which seems is not fully reproducible. A lot of messages is displayed on the screen, including

Syntax Error: XObject 'M0' is unknown Syntax Error (148868): Unexpected end of file in flate stream Syntax Error: Leftover args in content stream

or

Syntax Error: XObject 'M0' is unknown Syntax Error: ExtGState 'A2' is unknown

At the and I get

RuntimeError: main thread is not in main loop.

So, this seems to be the (my) python problem. I would be very grateful for any hint. I can provide the traceback and/or screen shots of the produced graphics if you think this could be helpful.

Thanks again for any suggestion. Best regards,

Zoran Pasaric

JohannesBuchner commented 10 years ago

Hello Zoran,

If cwrapper does not compile, that is usually because gcc/gfortran is old. Try to update.

Regarding the graphics error messages: pymultinest_demo.py launches your default pdf viewer to show a pdf file it continuously writes to. The pdf viewer (evince for you I guess) will reload that file. However, when there are partially written files, it will write out error messages such as the ones you see. On the next iteration when it notices the file has changed again, it will try again. So it is not necessarily a problem.

You got the library to run, which is the main thing. Using the minimal demo and the multinest_marginals.py script should be all you need -- the "watcher" is just some bells and whistles, but not necessary.

Cheers, Johannes

pasaric commented 10 years ago

Hello Johannes,

Thank you for extremely fast answer. The gcc and gfortran versions are: gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2 GNU Fortran (Ubuntu 4.8.2-19ubuntu1) 4.8.2 Actually, a hope to compile cwrapper was a trigger for me, few days ago, to make a (long needed) upgrade of my Ubuntu (from 10.04 to 14.04). However, for the time being, I can live with Intel.

But, if I try

python ../multinest_marginals.py chains/1-

i get

Traceback (most recent call last): File "../multinest_marginals.py", line 25, in parameters = json.load(file(prefix + 'params.json')) IOError: [Errno 2] No such file or directory: 'chains/1-params.json'

and this is the contents of chains:

1-ev.dat 1-IS.ptprob 1-post_equal_weights.dat 1-summary.txt 1-IS.iterinfo 1-live.points 1-resume.dat 1-.txt 1-IS.points 1-phys_live.points 1-stats.dat

Am I missing something obvious?

Thanks again,

Zoran

JohannesBuchner commented 10 years ago

Yeah, so the minimal script misses out a part to write out the parameter names -- multinest_marginals.py needs that file. Here is the relevant part to copy:

import json
# store name of parameters, always useful
a = pymultinest.Analyzer(n_params = n_params)
with file('%sparams.json' % a.outputfiles_basename, 'w') as f:
     json.dump(parameters, f, indent=2)
pasaric commented 10 years ago

Thanks! With your assistance I did make significant move forward (after struggling several days). It seems it is a time for me to study your code in more detail (and learn some python).

I expected to see some isolines (ellipses) of posterior distribution, which is 2D in the default, test case. Instead I got histograms and stairs. Suppose this is a matter of how the input parameters (that control graphical output) are defined? Is there on the web examples of all types of figures that pymultinest can produce?

A few more (marginal) questions:

The python ../multinest_marginals.py chains/1- works OK, and produces figures 1-marg.png and 1-marg.pdf. At the same time, used interactively from ipython, i.e. run ../multinest_marginals.py chains/1- I get In [28]: can't invoke "event" command: application has been destroyed while executing "event generate $w <>" (procedure "ttk::ThemeChanged" line 6) invoked from within "ttk::ThemeChanged" Do you have any hint on this?

What pdf viewer would be OK for pymultinest_demo.py? xpdf? Do you know what version of gfortran is capable to compile cwrapper?

Thanks again for your time.

Cheers,

Zoran

JohannesBuchner commented 10 years ago

See http://ccpforge.cse.rl.ac.uk/gf/project/multinest/forum/?_forum_action=ForumMessageBrowse&thread_id=22061&action=ForumBrowse&forum_id=198

I use evince.

pasaric commented 10 years ago

The URL seems to be invalid?

pasaric commented 10 years ago

Sorry, I did not realize that URL is simply printed twice.

JohannesBuchner commented 10 years ago

Sorry, my bad

pasaric commented 10 years ago

You mention that regarding cwrapper, gfortran 4.7.0 works. I am a bit confused, since I experience problems with gfortran 4.8.2? Is there some specific gfortran options which should be specified?

I am also using evince under new (maybe too new) Ubunutu 14.04. Does your evince works 'as is', or you had to somehow customize it?