예제 #1
0
def myprior(cube, ndim, nparams):
    """ MultiNest callback function. Sets the model parameters
    from the unit hypercube.
    Arguments:
    cube -- Unit hypercube from which model parameters are mapped.
    ndim -- Number of model paramers.
    nparams -- Total number of parameters in the cube .

    Returns:

    """
    # Set-up the paramters - CMSSM model.
    Model = CMSSMModelTracker()

    # Set the model parameters from the cube.
    Model.SetParams(cube)

    # Copy them to the cube so that they are printed, in alphabetical order.
    for name in sorted(Model.param.keys(), key=str.lower):
        Cube.AddCube(cube, Model.param[name].value, Cube.label, name)

    # Print-out cube model parameters for debugging.
    print '*****************************************************'
    print 'Parameters:'
    for i in range(Cube.AddCube.count() + 1):  # Count begins at 0 - need +1.
        print Cube.label[i], cube[i]
예제 #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