Example #1
0
            hyperparameters["sigma_w_scale"], size = size)
    sigma_v = 1 / gamma.rvs(hyperparameters["sigma_v_shape"], scale = hyperparameters["sigma_v_scale"], size = size)
    parameters = zeros((2, size))
    parameters[0, :] = sigma_w
    parameters[1, :] = sigma_v
    return parameters

## Prior hyperparameters
hyperparameters = { \
        "sigma_w_shape": 1, \
        "sigma_w_scale": 1, \
        "sigma_v_shape": 1, \
        "sigma_v_scale": 1}

modeltheta = ParameterModel(name = "Periodic Gaussian model theta", dimension = 2)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["expression(sigma[w]^2)", "expression(sigma[v]^2)"])
modeltheta.setTransformation(["log", "log"])
modeltheta.setRtruevalues([10, 1])
InverseGammaTemplate = """
priorfunction <- function(x){
    shape <- %.5f 
    scale <- %.5f
    return(scale**shape / gamma(shape) * x**(- shape - 1) * exp(-scale / x))
}
"""
modeltheta.setRprior([InverseGammaTemplate %
    (hyperparameters["sigma_w_shape"], hyperparameters["sigma_w_scale"]), \
InverseGammaTemplate % (hyperparameters["sigma_v_shape"],
Example #2
0
    """ Takes transformed parameters.  When the parameter is transformed, 
    a jacobian appears in the formula.
    """
    # the following is the log density of Y = logit(U) when U is Uniform(0,1)
    rho_part = safelogdlogit(array([parameters[0]]))
    return rho_part[0]

def rprior(size, hyperparameters):
    """ returns untransformed parameters """
    rho = random.uniform(size = size, low = 0.01, high = 0.99) 
    parameters = zeros((1, size))
    parameters[0, :] = rho
    return parameters

## Prior hyperparameters
modeltheta = ParameterModel(name = "Simplest model theta", dimension = 1)
modeltheta.setHyperparameters({})
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["expression(rho)"])
modeltheta.setTransformation(["logit"])
uniformprior = \
"""
priorfunction <- function(x){
    return(1)
}
"""
modeltheta.setRprior([uniformprior])