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"], hyperparameters["sigma_v_scale"])])
""" 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)
""" 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])
parameters = zeros((L, size)) for ell in range(L): ##same as random.normal #if ell==0: parameters[ell, :] = random.exponential(scale = 1.0 / hyperparameters["b1_rate"], size = size) #else: # parameters[ell, :] = norm.rvs(size = size, loc = hyperparameters["b_mean"], scale = hyperparameters["b_sd"]) return parameters ## Prior hyperparameters modeltheta = ParameterModel(name = "Nested LGSSM model theta", dimension = L) modeltheta.setHyperparameters(hyperparameters) modeltheta.setPriorlogdensity(logdprior) modeltheta.setPriorgenerator(rprior) modeltheta.setParameterNames(["expression(B)"]) #transType = ["log"] transType = [] for m in range(L): transType.append("log") modeltheta.setTransformation(transType) #(["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)
"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, \ "rho1_mean": 0, "rho1_sd": 5, \ "rho2_mean": 0, "rho2_sd": 5, } modeltheta = ParameterModel(name = "SV multi-factor", dimension = 9) 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])", "expression(rho[1])", "expression(rho[2])"]) modeltheta.setTransformation(["none", "none", "log", "log", "log", "log", "logit", "none", "none"]) 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", \ "priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["rho1_sd"], \ "priorfunction <- function(x) dnorm(x, sd = %.5f)" % hyperparameters["rho2_sd"]])