Beispiel #1
0
## 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"],
    hyperparameters["sigma_v_scale"])])





    parameters = zeros((5, size))
    parameters[0, :] = mu
    parameters[1, :] = beta
    parameters[2, :] = xi
    parameters[3, :] = omega2
    parameters[4, :] = lamb
    return parameters

hyperparameters = { \
        "mu_mean": 0, "mu_sd": sqrt(2), \
        "beta_mean": 0, "beta_sd": sqrt(2), \
        "xi_rate": 0.2, "omega2_rate": 0.2, \
        "lambda_rate": 1}


modeltheta = ParameterModel(name = "SV one-factor", dimension = 5)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["expression(mu)", "expression(beta)", \
        "expression(xi)", "expression(omega^2)", "expression(lambda)"])
modeltheta.setTransformation(["none", "none", "log", "log", "log"])
modeltheta.setRprior(["priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["mu_sd"], \
                            "priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["beta_sd"], \
                            "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["xi_rate"], \
                            "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["omega2_rate"], \
                            "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["lambda_rate"]])



Beispiel #3
0
    """ returns untransformed parameters """
    parameters = zeros((L, size))
    parameters[0, :] = random.uniform(low=0,
                                      high=hyperparameters["high"],
                                      size=size)
    parameters[1, :] = random.uniform(low=0,
                                      high=hyperparameters["high"],
                                      size=size)
    #parameters[0, :] = random.exponential(scale = 1 / hyperparameters["b1_rate"], size = size)
    #parameters[ell, :] = norm.rvs(size = size, loc = hyperparameters["b_mean"], scale = hyperparameters["b_sd"])
    return parameters


## Prior hyperparameters
modeltheta = ParameterModel(name="logistic diffusion model theta", dimension=L)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["tau, sigma"])
modeltheta.setTransformation(["log", "log"])  #(["none", "none"])
#modeltheta.setRprior({}) #seems useless
#modeltheta.setRprior(["priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["b1_rate"],\
#    "priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["b_sd"]])
#modeltheta.setRprior(["priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["b1_rate"],\
#    "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["b1_rate"]])
set_argu = []
for m in range(L):
    set_argu.append("priorfunction <- function(x) dexp(x, rate = %.5f)" %
                    hyperparameters["b1_rate"])
modeltheta.setRprior(set_argu)
Beispiel #4
0
modeltheta = ParameterModel(name="Athletics records", dimension=3)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(
    ["expression(nu)", "expression(xi)", "expression(sigma)"])
modeltheta.setTransformation(["log", "log", "log"])

Rpriornu = "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters[
    "nu_rate"]
Rpriorxi = "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters[
    "xi_rate"]
Rpriorsigma = "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters[
    "sigma_rate"]
modeltheta.setRprior([Rpriornu, Rpriorxi, Rpriorsigma])

#modeltheta.plottingInstructions = ["No observations", "No evidence"]
#modeltheta.additionalPlots = """
#filteringDF <- data.frame(observations)
#filteringDF$year <- 1976:2010
#filteringDF$xfiltered <- filteredfirststate
#filteringDF$CIlow <- filteredCIlow
#filteringDF$CIhigh <- filteredCIhigh
#names(filteringDF) <- c("y1", "y2", "year", "x", "CIlow", "CIhigh")
#g <- ggplot(filteringDF, aes(x = year))
#g <- g + geom_line(aes(y = x), size = 1, linetype = 2, colour = "blue")
#g <- g + geom_line(aes(y = CIlow), size = 1, colour = "blue")
#g <- g + geom_line(aes(y = CIhigh), size = 1, colour = "blue")
#g <- g + geom_point(aes(y = y1), size = 4, colour = "green")
#g <- g + geom_point(aes(y = y2), size = 4, colour = "red")
Beispiel #5
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])


Beispiel #6
0
    parameters[1, :] = beta
    parameters[2, :] = xi
    parameters[3, :] = omega2
    parameters[4, :] = lamb
    parameters[5, :] = lambadd
    parameters[6, :] = w
    return parameters

hyperparameters = { \
        "mu_mean": 0, "mu_sd": sqrt(2), \
        "beta_mean": 0, "beta_sd": sqrt(2), \
        "xi_rate": 0.2, "omega2_rate": 0.2, \
        "lambda1_rate": 1, "lambdaadd_rate": 0.5}

modeltheta = ParameterModel(name="SV multi-factor", dimension=7)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["expression(mu)", "expression(beta)", \
        "expression(xi)", "expression(omega^2)", "expression(lambda[1])", "expression(lambda[2] - lambda[1])", \
        "expression(w[1])"])
modeltheta.setTransformation(
    ["none", "none", "log", "log", "log", "log", "logit"])
modeltheta.setRprior(["priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["mu_sd"], \
                      "priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["beta_sd"], \
                      "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["xi_rate"], \
                      "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["omega2_rate"], \
                      "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["lambda1_rate"], \
                      "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["lambdaadd_rate"], \
                      "priorfunction <- function(x) 1"])
hyperparameters = { \
        "nu_rate": 0.2, \
        "xi_rate": 0.5, \
        "sigma_rate": 0.2}

modeltheta = ParameterModel(name = "Athletics records", dimension = 3)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["expression(nu)", "expression(xi)", "expression(sigma)"])
modeltheta.setTransformation(["log", "log", "log"])

Rpriornu = "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["nu_rate"]
Rpriorxi = "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["xi_rate"]
Rpriorsigma = "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["sigma_rate"]
modeltheta.setRprior([Rpriornu, Rpriorxi, Rpriorsigma])



#modeltheta.plottingInstructions = ["No observations", "No evidence"]
#modeltheta.additionalPlots = """
#filteringDF <- data.frame(observations)
#filteringDF$year <- 1976:2010
#filteringDF$xfiltered <- filteredfirststate
#filteringDF$CIlow <- filteredCIlow
#filteringDF$CIhigh <- filteredCIhigh
#names(filteringDF) <- c("y1", "y2", "year", "x", "CIlow", "CIhigh")
#g <- ggplot(filteringDF, aes(x = year))
#g <- g + geom_line(aes(y = x), size = 1, linetype = 2, colour = "blue")
#g <- g + geom_line(aes(y = CIlow), size = 1, colour = "blue")
#g <- g + geom_line(aes(y = CIhigh), size = 1, colour = "blue")
                                      high=hyperparameters["high"],
                                      size=size)
    parameters[3, :] = random.uniform(low=0,
                                      high=hyperparameters["high"],
                                      size=size)
    #parameters[0, :] = random.exponential(scale = 1 / hyperparameters["b1_rate"], size = size)
    #parameters[ell, :] = norm.rvs(size = size, loc = hyperparameters["b_mean"], scale = hyperparameters["b_sd"])
    return parameters


## Prior hyperparameters
modeltheta = ParameterModel(name="logistic diffusion model theta", dimension=L)
modeltheta.setHyperparameters(hyperparameters)
modeltheta.setPriorlogdensity(logdprior)
modeltheta.setPriorgenerator(rprior)
modeltheta.setParameterNames(["tau, sigma, r, b"])
modeltheta.setTransformation(["log", "log", "none",
                              "log"])  #(["none", "none"])
#modeltheta.setRprior({}) #seems useless
#modeltheta.setRprior(["priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["b1_rate"],\
#    "priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["b_sd"]])
#modeltheta.setRprior(["priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["b1_rate"],\
#    "priorfunction <- function(x) dexp(x, rate = %.5f)" % hyperparameters["b1_rate"]])
set_argu = []
for m in range(L):
    set_argu.append("priorfunction <- function(x) dexp(x, rate = %.5f)" %
                    hyperparameters["b1_rate"])
modeltheta.setRprior(
    set_argu
)  #used by ParameterModel (generatee modeltheta), which does not seem useful anymore