예제 #1
0
파일: Cube.py 프로젝트: jennetd/superpy
def PrintInfo():
    """ Function to write an info file, for use with plotting,
    and for saving Multinest options, likelihood functions and
    priors.
    """
    # Import variable inside function, to avoid circular module
    # imports.
    import MNOptions as MN
    import Priors
    import Likelihood

    infofile = MN.outputfiles_basename + '.info'
    info = open(infofile, 'w')

    info.write('''# SuperPy info file, with cube indicies.
# This info file can be used for plot labels.\n''')

    for key, value in label.iteritems():
        # Add 1 to the keys, so that labelling begins at 1, rather than 0.
        # This is identical to the SuperBayeS info file convention.
        key = str(int(key) + 1)
        info.write('''lab%s=%s\n''' % (key, value))

    # Write the prior types and arguements.
    info.write('''# Priors.\n''')
    for key in Priors.CNMSSMModelTracker().param:
        info.write('''%s %s %s\n''' %
                   (key, Priors.CNMSSMModelTracker().param[key].type,
                    Priors.CNMSSMModelTracker().param[key].arg))

    # Write the likelihoods types and arguments.
    info.write('''# Likelihoods.\n''')
    for key in Likelihood.CNMSSMConstraintTracker().constraint:
        info.write(
            '''%s %s %s\n''' %
            (key, Likelihood.CNMSSMConstraintTracker().constraint[key].type,
             Likelihood.CNMSSMConstraintTracker().constraint[key].arg))

    # Write the MN parameters.
    info.write('''# MultiNest options.\n''')
    for vars in dir(MN):
        if not vars.startswith("__"):
            info.write('''%s %s\n''' % (vars, getattr(MN, vars)))
    info.close()
예제 #2
0
def myloglike(cube, ndim, nparams):
    """ MultiNest callback function.
    Calculate the model's predictions (by calling external programs),
    saves the extra parameters in the cube, and returns log likelihood to Multinest.

    Arguments:
    cube -- Unit hypercube from which model parameters are mapped.
    ndim -- Number of model paramers.
    nparams -- Total number of parameters in the cube.

    Returns: The total log likelihood for the model parameter
    point under consideration.

    """
    # Set up constraints class.
    Constraints = CNMSSMConstraintTracker()

    # Copy cube to constraints, so it can work out predictions etc.
    for i, name in enumerate(
            sorted(Priors.CNMSSMModelTracker().param.keys(), key=str.lower)):
        Constraints.param[name] = cube[i]

    # Set predictions and loglikes.
    Constraints.SetPredictions()
    Constraints.SetLogLike()

    # Copy constraints to cube.
    for name in sorted(Constraints.constraint.keys(), key=str.lower):
        Cube.AddCube(cube, Constraints.constraint[name].theory, Cube.label,
                     name)

    # Copy associated chi2s to cube. Better to print chi2 than loglike,
    # beceause MultiNest prints chi2 and they can be treated in the
    # same way when plotting.
    for name in sorted(Constraints.constraint.keys(), key=str.lower):
        Cube.AddCube(cube, -2 * Constraints.constraint[name].loglike,
                     Cube.label, 'chi2:' + name)

    # Copy SLHA masses to the cube.
    for key in Constraints.masses:
        Cube.AddCube(cube, Constraints.masses[key], Cube.label,
                     'Mass:' + str(key))

    # Copy mu-parameter to the cube.
    Cube.AddCube(cube, Constraints.mu, Cube.label, 'mu')

    # Copy neutralino mixing to the cube.
    for key in Constraints.neutralino:
        Cube.AddCube(cube, Constraints.neutralino[key], Cube.label,
                     'NMIX:' + str(key))

    # Print-out cube for debugging.
    print 'Predictions:'
    for label, param in zip(Cube.label.itervalues(), cube):
        print label, param
    print 'Total loglike', Constraints.loglike

    # Start cube count from 0 again.
    Cube.AddCube.reset()

    # Print an info file for the cube.
    # Decorator insures this is printed only once.
    # Point must be physical, else the info will be incomplete.
    if Constraints.physical:
        Cube.PrintInfo()

    # Return the log likelihood to MultiNest.
    return Constraints.loglike
예제 #3
0
import Likelihood  # For setting callback function and number of constraints.

# Make chains directory for MultiNest.
if not os.path.exists("chains"):
    os.mkdir("chains")

# File names - best to convert to absolute path here.
outputfiles_basename = os.path.abspath('./chains/CNMSSM')

# These are the settings that are passed to MultiNest.
# Loglike callback function.
LogLikelihood = Likelihood.myloglike
# Prior callback function.
Prior = Priors.myprior
# Number of model parameters.
n_dims = len(Priors.CNMSSMModelTracker().param)
# Total number of parameters in cube.
# This is model parameters + constraints + chi2 from constraints + 33
# sparticle/particle masses + mu + neutralino mixing.
# For NMSSM, neutralino mixing matrix is 5 by 5.
# For NMSSM, 2 extra masses for singlet and singlino.
n_params = n_dims + 2 * \
    len(Likelihood.CNMSSMConstraintTracker().constraint) + 33 + 2 + 1 + 25
# Which parameters to mode cluster, first n.
n_clustering_params = 2
# Should be a vector of 1s and 0s - 1 = wrapped, 0 = unwrapped.
wrapped_params = None
# Whether to separate modes.
multimodal = True
const_efficiency_mode = False
n_live_points = 10