eggplantbren / DNest4

Diffusive Nested Sampling
MIT License
62 stars 22 forks source link

MC acceptance above one #27

Closed davidkleiven closed 6 years ago

davidkleiven commented 6 years ago

Hi, when I try to run the straight line example (python version) I get the following plot mc_acc_straight_line From the code the the lowest plot should be

levels[m]["accept"]/levels[m]["tries"]

so intuitively I would expect this to be a number between zero and one. My levels.txt files:

# log_X log_likelihood tiebreaker accepts tries exceeds visits
0.000000000000000000e+00 -1.797693134862315708e+308 0.000000000000000000e+00 6663 65021 64096 65021
-9.320907461421843454e-01 -1.749548206028707623e+08 7.795952521804472291e-02 38725 65263 27459 51512
-1.961480454579990873e+00 -7.090954872909059304e+03 3.712745756088198235e-02 20337 65240 43565 15800
-2.961163254942303702e+00 -4.855955034352015218e+02 7.277952412568250429e-01 8506 65158 56951 31507
-3.922006542673133200e+00 -3.284338445411593170e+02 2.378482294687733756e-03 604 64979 59557 44329
-4.894153694783229369e+00 -3.003078811896248226e+02 6.794595506886329517e-01 57596 65177 16272 47379
-5.767619056994849558e+00 -2.769564987772033646e+02 5.808150005686155692e-01 49014 65001 58981 3177
-6.787211705620835644e+00 -2.529338132609802301e+02 1.325988680728897862e-01 39177 65247 17309 47967
-7.657161659096917816e+00 -2.366950853781018509e+02 8.854486303168679351e-02 31586 206 51584 5065
-8.717490828306891260e+00 -2.194071224585905782e+02 6.961165282119203823e-01 24080 749 59274 42287
-9.687211881666033975e+00 -2.053333999774806671e+02 2.633039113273385468e-01 17731 642 26174 48791
-1.052014012233775730e+01 -1.944308450771352739e+02 7.086774342232374235e-02 12684 755 42448 12914
-1.164252823172497031e+01 -1.818501628319034182e+02 5.453455227779517855e-01 6229 817 36102 33485
-1.271744331596643640e+01 -1.726802094746875298e+02 1.452798424751584605e-01 65227 691 41911 26474
-1.374691369786420125e+01 -1.665984274276879660e+02 8.349636852127451103e-01 58996 614 56991 31617
-1.470776741496226592e+01 -1.632254965193020837e+02 2.302375955141304220e-01 54418 753 54584 46170
-1.570824590371078244e+01 -1.611577816882679031e+02 2.650222043896128810e-01 49454 808 61074 44102
-1.667249624742556335e+01 -1.600268133302136278e+02 5.384903420179038003e-01 44095 718 65450 53464
-1.763286425927335443e+01 -1.594315624985474926e+02 7.343026828493860458e-01 40058 440 14956 58039
-1.853183774749406965e+01 -1.591216632242262676e+02 3.138237975324571494e-01 35363 65502 6913 5736
-1.949135506592003608e+01 -1.589469510413382523e+02 3.147910860109549569e-01 31804 65400 59200 64288
-2.050191628089351781e+01 -1.588512384954648269e+02 3.213441996768060527e-01 27498 65354 44316 50236
-2.156339305503236048e+01 -1.588005126460745089e+02 5.574140749908829129e-01 23929 65340 36385 39107
-2.264740139644326078e+01 -1.587744460949023733e+02 2.224416291614284558e-01 19557 65295 59691 29866
-2.359146505214206258e+01 -1.587632270122196871e+02 7.447591844072662948e-01 16810 109 49466 53559
-2.463190509350078727e+01 -1.587567936621363174e+02 3.831551339219136376e-01 13381 251 48900 43529
-2.565668287001400216e+01 -1.587537370329235387e+02 1.187293924186407224e-01 10384 472 54660 43085
-2.665100985647396925e+01 -1.587522372612219215e+02 9.438965853890375346e-01 7391 662 18640 49057
-2.751709871697605436e+01 -1.587515238918745979e+02 2.569050943892401406e-01 5009 239 10875 12592
-2.847050189630177996e+01 -1.587510753461820059e+02 3.502633534631354184e-01 2681 65496 0 0

so one can clearly see that there are levels with more accepts than tries. Is this as it should be? In that case what is the interpretation of MH acceptance?

eggplantbren commented 6 years ago

Your interpretation is correct, and this shouldn't be happening. Are you using Python 2? It is not supported and I have seen strange behaviour from it before.

eggplantbren commented 6 years ago

I just reproduced it on Python 3. Will investigate

eggplantbren commented 6 years ago

I think this is beyond my pay grade. Hopefully @dfm can take a look.

davidkleiven commented 6 years ago

I am not sure if this helps, but when I was running with python3 and executed the dnest4.postprocess() while the code was running the code the plots looked fine until around 180 particles were saved. I included the plot I got before the strange thing happen early3

dfm commented 6 years ago

@eggplantbren: this looks like a problem with the levels.txt file (accept > tries), not the Python processing...

eggplantbren commented 6 years ago

When you're using a Python-based model, levels.txt appears to be created by some stuff in sampler.py and/or backends.py. It's not SamplerImpl.h - I put some diagnostic stuff in there to see what was going on, but it never got executed.

eggplantbren commented 6 years ago

Fixed with 7371e0f294051c45e0d18f1ca3dbd8584299a7e2. @dfm can reopen it if there's some reason my fix (using a longer unsigned integer type) is likely to cause any problems. I don't see why it would, and it seems to be working fine.

davidkleiven commented 6 years ago

Yes, it works fine! Thanks!

dfm commented 6 years ago

👍