baudren / montepython_public

Public repository for the Monte Python Code
MIT License
65 stars 115 forks source link

Parameter scaling #106

Open mpauly opened 6 years ago

mpauly commented 6 years ago

Hi, I seem to run into a few problems related to parameter scaling. Specifically these problems seem to be caused by 677195a9628338b8ee8eeb3582cbd6477e6da37d - in analyse.py info.scales contains only 1 on the diagonal if analysed with a .plot file that does not redefine scales. Due to this bestfit files and covariance matrices generated with the analyze command (without a .plot file that redefines scales) are not able to seed a new montepython run. Am I doing something wrong or is this indeed a bug? Cheers, Martin

brinckmann commented 6 years ago

Hi Martin, Sorry I didn't get around to replying. Yes, this is indeed a bug. I proposed a fix to Deanna when you met her last month, but I realized it wasn't good enough to be a robust fix and I didn't find time to come up with a proper fix yet. If you have a robust fix you're welcome to post it, otherwise I'll get around to it sometime soon, I hope. Best, Thejs

brinckmann commented 6 years ago

Below is a bug fix that should work and will be included in the next public version. Note this bug also affects the flag --update, as the code does not correctly load the updated covmats.

In the function "extract_parameter_names" replace

    scales = []

With

    scales = []
    rescales = []

And

                        # Take care of the scales
                        scale = array[4]
                        rescale = 1.
                        if name in info.new_scales.iterkeys():
                            scale = info.new_scales[name]
                            rescale = info.new_scales[name]/array[4]
                        scales.append(rescale)

With

                        # Take care of the scales                                                                                                                                                                                           
                        scale = array[4]
                        rescale = 1.
                        if name in info.new_scales.iterkeys():
                            rescale = info.new_scales[name]/array[4]
                        scales.append(scale)
                        rescales.append(rescale)

Also

    scales = np.diag(scales)

With

    scales = np.diag(scales)
    rescales = np.diag(rescales)

And

    info.scales = scales

With

    info.scales = scales
    info.rescales = rescales

And finally in the "function remove_bad_points"

    # Applying now new rules for scales, if the name is contained in the                                                                                                                                                                    
    # referenced names                                                                                                                                                                                                                      
    for name in info.new_scales.iterkeys():
        try:
            index = info.ref_names.index(name)
            for i in xrange(len(spam)):
                spam[i][:, index+2] *= 1./info.scales[index, index]

With

    # Applying now new rules for scales, if the name is contained in the                                                                                                                                                                    
    # referenced names                                                                                                                                                                                                                      
    for name in info.new_scales.iterkeys():
        try:
            index = info.ref_names.index(name)
            for i in xrange(len(spam)):
                spam[i][:, index+2] *= 1./info.rescales[index, index]