INLA_DIST
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
PostTheta Class Reference

Computes the Posterior of the hyperparameters theta. More...

#include <PostTheta.h>

Public Member Functions

 PostTheta (int ns, int nt, int nb, int no, MatrixXd B, Vect y, Vect theta_prior, Vect mu_initial, string likelihood, Vect extraCoeffVecLik, string solver_type, const bool constr, const MatrixXd Dxy, const bool validate, const Vect w)
 constructor for regression model (no random effects).
 
 PostTheta (int ns, int nt, int nb, int no, SpMat Ax, Vect y, SpMat c0, SpMat g1, SpMat g2, Vect theta_prior, Vect mu_initial, string likelihood, Vect extraCoeffVecLik, string solver_type, int dim_spatial_domain, string manifold, const bool constr, const MatrixXd Dx, const MatrixXd Dxy, const bool validate, const Vect w)
 constructor for spatial model (order 2).
 
 PostTheta (int ns, int nt, int nb, int no, SpMat Ax, Vect y, SpMat c0, SpMat g1, SpMat g2, SpMat g3, SpMat M0, SpMat M1, SpMat M2, Vect theta_prior, Vect mu_initial, string likelihood, Vect extraCoeffVecLik, string solver_type, int dim_spatial_domain, string manifold, const bool constr, const MatrixXd Dx, const MatrixXd Dxy, const bool validate, const Vect w)
 constructor for spatial temporal model.
 
 PostTheta (int ns, int nt, int nss, int nb, int no, SpMat Ax, Vect y, SpMat c0, SpMat g1, SpMat g2, SpMat g3, SpMat M0, SpMat M1, SpMat M2, Vect theta_prior_param, Vect mu_initial, string likelihood, Vect extraCoeffVecLik, string solver_type, int dim_spatial_domain, string manifold, const bool constr, const MatrixXd Dx, const MatrixXd Dxy, const bool validate, const Vect w)
 constructor for spatial temporal model w/ add. spatial field
 
double operator() (Vect &theta, Vect &grad)
 structure required by BFGS solver, requires : theta, gradient theta
 
double compute_error_bfgs (Vect &theta)
 
void computeG (Vect &theta)
 overwriting G every time, not explicitly listed, better way to do this? needs to be stored after every iteration for smart hessian ...

 
int get_fct_count ()
 
void convert_theta2interpret (Vect &theta, Vect &theta_interpret)
 
void convert_interpret2theta (Vect &theta_interpret, Vect &theta)
 
void convert_theta2interpret_spatTemp (double lgamE, double lgamS, double lgamT, double &sigU, double &ranS, double &ranT)
 convert hyperparameters theta from the model parametrisation to the interpretable parametrisation ie. from log(gamma_E, gamma_s, gamma_t) to log(sigma.u, rangeS, rangeT)
 
void convert_interpret2theta_spatTemp (double sigU, double ranS, double ranT, double &lgamE, double &lgamS, double &lgamT)
 convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie. from log(sigma.u, rangeS, rangeT) to log(gamma_E, gamma_s, gamma_t)
 
void convert_interpret2theta_spat (double lranS, double lsigU, double &lgamS, double &lgamE)
 convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie. from log(rangeS, sigma.u) to log(gamma_s, gamma_E) for spatial model order 2
 
void convert_theta2interpret_spat (double lgamS, double lgamE, double &lranS, double &lsigU)
 convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie. from log(rangeS, sigma.u) to log(gamma_s, gamma_E) for spatial model order 2
 
void get_mu (Vect &theta, Vect &mu_)
 get conditional mean mu for theta – Gaussian case.
 
Vect get_grad ()
 returns current gradient of theta.
 
void get_Qprior (Vect theta, SpMat &Qprior)
 
MatrixXd get_Covariance (Vect theta, double eps)
 Compute Covariance matrix of hyperparameters theta, at theta.
 
MatrixXd get_Cov_interpret_param (Vect interpret_theta, double eps)
 
double f_eval (Vect &theta)
 
void get_marginals_f (Vect &theta, Vect &mu, Vect &vars)
 Compute the marginal variances of the latent parameters at theta. Using selected inversion procedure.
 
void get_fullFact_marginals_f (Vect &theta, SpMat &Qinv)
 Compute the marginal variances of the latent parameters at theta. Using selected inversion procedure.
 
void compute_fullInverseQ (Vect &theta, MatrixXd &Qinv)
 
MatrixXd hess_eval (Vect theta, double eps)
 computes the hessian at theta using second order finite difference. Is used be get_Covariance.
 
MatrixXd hess_eval_interpret_theta (Vect interpret_theta, double eps)
 
void check_pos_def (MatrixXd &hess)
 check if Hessian positive definite (matrix assumed to be dense & small since dim(theta) small)
 
double eval_post_theta (Vect &theta, Vect &mu)
 Core function. Evaluate posterior of theta. mu are latent parameters.
 
void eval_log_gaussian_prior_hp (Vect &theta_param, Vect &theta_prior_param, double &log_prior)
 evaluate log prior of the hyperparameters using original theta value
 
void eval_log_pc_prior_hp (double &log_sum, Vect &lambda, Vect &theta_interpret)
 evaluate log prior using PC prior
 
void update_mean_constr (const MatrixXd &D, Vect &e, Vect &sol, MatrixXd &V, MatrixXd &W, MatrixXd &U, Vect &updated_sol)
 
void eval_log_dens_constr (Vect &x, Vect &mu, SpMat &Q, double &log_det_Q, const MatrixXd &D, MatrixXd &W, double &val_log_dens)
 
void eval_log_prior_lat (Vect &theta, Vect &mu, double &val)
 evaluate log prior of random effects
 
void eval_likelihood (Vect &theta, Vect &mu, double &log_det, double &val)
 compute log likelihood : log_det tau*no and value -theta*yTy
 
void construct_Q_spatial (Vect &theta, SpMat &Qs)
 spatial model : SPDE discretisation – matrix construction
 
void construct_Q_spat_temp (Vect &theta, SpMat &Qst)
 spatial temporal model : SPDE discretisation. DEMF(1,2,1) model.
 
void construct_Qprior (Vect &theta, SpMat &Qx)
 
void construct_Q (Vect &theta, Vect &mu, SpMat &Q)
 construct precision matrix. Calls spatial, spatial-temporal, etc.
 
void construct_b (Vect &theta, Vect &rhs)
 Assemble right-handside.
 
void eval_denominator (Vect &theta, double &val, SpMat &Q, Vect &rhs, Vect &mu)
 Evaluate denominator: conditional probability of Qx|y.
 
double cond_LogPriorLat (SpMat &Qprior, Vect &x)
 evaluate Gaussian log prior (without log determinant!!), mean assumed to be zero
 
double cond_LogPoisLik (Vect &eta)
 evaluate log Poisson likelihood
 
double cond_negLogPoisLik (Vect &eta)
 evaluate negative log Poisson likelihood
 
Vect grad_cond_negLogPoisLik (Vect &eta)
 evaluate analytical negative gradient log Poisson likelihood
 
Vect diagHess_cond_negLogPoisLik (Vect &eta)
 evaluate analytical negative diagonal Hessian of log Poisson likelihood
 
double cond_negLogPois (SpMat &Qprior, Vect &x)
 evaluate negative condiational log Poisson + Gaussian prior
 
void link_f_sigmoid (Vect &x, Vect &sigmoidX)
 link function. vectorized evaluation of sigmoid function for each entry
 
double cond_negLogBinomLik (Vect &eta)
 evaluate negative log Binomial likelihood
 
double cond_negLogBinom (SpMat &Qprior, Vect &x)
 evaluate negative condiational log Poisson + Gaussian prior
 
double cond_negLogDist (SpMat &Qprior, Vect &x, function< double(Vect &, Vect &)> lik_func)
 evaluate negative condiational log likelihood + Gaussian prior
 
void FD_gradient (Vect &eta, Vect &grad)
 compute finite difference gradient. 1st order central difference. currently stepsize h fixed.
 
void FD_diag_hessian (Vect &eta, Vect &diag_hess)
 compute finite difference diagonal of hessian. 2nd order central difference. currently stepsize h fixed.
 
void NewtonIter (Vect &theta, Vect &x, SpMat &Q, double &log_det)
 Newton iteration to find optimum of conditional distribution latent parameters of prior & likelihood.
 
void record_times (std::string file_name, int iter_count, double t_Ftheta_ext, double t_thread_nom, double t_priorHyp, double t_priorLat, double t_priorLatAMat, double t_priorLatChol, double t_likel, double t_thread_denom, double t_condLat, double t_condLatAMat, double t_condLatChol, double t_condLatSolve)
 
 ~PostTheta ()
 class destructor. Frees memory allocated by PostTheta class.
 

Private Attributes

int MPI_size
 
int MPI_rank
 
int threads_level1
 
int threads_level2
 
int ns
 
int nt
 
int nss
 
int nb
 
int no
 
int nst
 
int nu
 
int n
 
size_t nnz_Qst
 
size_t nnz_Qs
 
int dim_th
 
int dim_spatial_domain
 
string manifold
 
int dim_grad_loop
 
int num_solvers
 
SolversolverQ
 
SolversolverQst
 
int threadID_solverQst
 
int threadID_solverQ
 
string likelihood
 
Vect extraCoeffVecLik
 
string solver_type
 
std::string prior
 
int fct_count
 
int iter_count
 
int iter_acc
 
Vect y
 
Vect theta_prior_param
 
Vector3i dimList
 
SpMat Ax
 
MatrixXd B
 
SpMat c0
 
SpMat g1
 
SpMat g2
 
SpMat g3
 
SpMat M0
 
SpMat M1
 
SpMat M2
 
SpMat Qb
 
SpMat Qu
 
SpMat Qst
 
SpMat Qs
 
SpMat Qx
 
SpMat Qxy
 
double yTy
 
Vect BTy
 
Vect AxTy
 
SpMat AxTAx
 
Vect mu_initial
 
Vect mu
 
Vect mu_midpoint
 
MatrixXd mu_matrix
 
Vect t_grad
 
double min_f_theta
 
double w_sum
 
int no_f_eval
 
ArrayXi task_to_rank_list_grad
 
MatrixXd G
 
const bool constr
 
const MatrixXd Dx
 
const MatrixXd Dxy
 
const bool validate
 
const Vect w
 
bool printed_eps_flag = false
 
double t_priorLatChol
 
double t_condLatChol
 
double t_condLatSolve
 
double t_bfgs_iter
 

Detailed Description

Computes the Posterior of the hyperparameters theta.

Computes the posterior of theta for a given theta and its gradient using a central finite difference approximation. Can additionally compute an approximation to the Hessian.

Constructor & Destructor Documentation

◆ PostTheta() [1/4]

PostTheta::PostTheta ( int  ns,
int  nt,
int  nb,
int  no,
MatrixXd  B,
Vect  y,
Vect  theta_prior,
Vect  mu_initial,
string  likelihood,
Vect  extraCoeffVecLik,
string  solver_type,
const bool  constr,
const MatrixXd  Dxy,
const bool  validate,
const Vect  w 
)

constructor for regression model (no random effects).

Parameters
[in]ns_number of spatial grid points per time step.
[in]nt_number of temporal time steps.
[in]nb_number of fixed effects.
[in]no_number of observations.
[in]B_covariate matrix.
[in]y_vector with observations.
Note
B = B_ or is its own copy?

◆ PostTheta() [2/4]

PostTheta::PostTheta ( int  ns,
int  nt,
int  nb,
int  no,
SpMat  Ax,
Vect  y,
SpMat  c0,
SpMat  g1,
SpMat  g2,
Vect  theta_prior,
Vect  mu_initial,
string  likelihood,
Vect  extraCoeffVecLik,
string  solver_type,
int  dim_spatial_domain,
string  manifold,
const bool  constr,
const MatrixXd  Dx,
const MatrixXd  Dxy,
const bool  validate,
const Vect  w 
)

constructor for spatial model (order 2).

Parameters
[in]ns_number of spatial grid points per time step.
[in]nt_number of temporal time steps.
[in]nb_number of fixed effects.
[in]no_number of observations.
[in]Ax_covariate matrix.
[in]y_vector with observations.
[in]c0_diagonalised mass matrix.
[in]g1_stiffness matrix.
[in]g2_defined as : g1 * c0^-1 * g1

◆ PostTheta() [3/4]

PostTheta::PostTheta ( int  ns,
int  nt,
int  nb,
int  no,
SpMat  Ax,
Vect  y,
SpMat  c0,
SpMat  g1,
SpMat  g2,
SpMat  g3,
SpMat  M0,
SpMat  M1,
SpMat  M2,
Vect  theta_prior,
Vect  mu_initial,
string  likelihood,
Vect  extraCoeffVecLik,
string  solver_type,
int  dim_spatial_domain,
string  manifold,
const bool  constr,
const MatrixXd  Dx,
const MatrixXd  Dxy,
const bool  validate,
const Vect  w 
)

constructor for spatial temporal model.

constructor for spatial model (order 2).

Parameters
[in]ns_number of spatial grid points per time step.
[in]nt_number of temporal time steps.
[in]nb_number of fixed effects.
[in]no_number of observations.
[in]Ax_covariate matrix.
[in]y_vector with observations.
[in]c0_diagonalised mass matrix space.
[in]g1_stiffness matrix space.
[in]g2_defined as : g1 * c0^-1 * g1
[in]g3_defined as : g1 * (c0^-1 * g1)^2
[in]M0_diagonalised mass matrix time.
[in]M1_diagonal matrix with diag(0.5, 0, ..., 0, 0.5) -> account for boundary
[in]M2_stiffness matrix time.
[in]theta_priorprior hyperparameters
[in]solver_typelinear solver: currently PARDISO, BTA
[in]dim_spatial_domaindimension spatial field 1D/2D ...
[in]manifoldplane: "", "sphere", can add more later
[in]constrconstraints, mainly sum-to-zero

◆ PostTheta() [4/4]

PostTheta::PostTheta ( int  ns,
int  nt,
int  nss,
int  nb,
int  no,
SpMat  Ax,
Vect  y,
SpMat  c0,
SpMat  g1,
SpMat  g2,
SpMat  g3,
SpMat  M0,
SpMat  M1,
SpMat  M2,
Vect  theta_prior_param,
Vect  mu_initial,
string  likelihood,
Vect  extraCoeffVecLik,
string  solver_type,
int  dim_spatial_domain,
string  manifold,
const bool  constr,
const MatrixXd  Dx,
const MatrixXd  Dxy,
const bool  validate,
const Vect  w 
)

constructor for spatial temporal model w/ add. spatial field

constructor for both spatial models (order 2).

Parameters
[in]ns_number of spatial grid points per time step.
[in]nt_number of temporal time steps.
[in]nss_number of spatial grid points in add. spatial field
[in]nb_number of fixed effects.
[in]no_number of observations.
[in]Ax_covariate matrix.
[in]y_vector with observations.
[in]c0_diagonalised mass matrix space.
[in]g1_stiffness matrix space.
[in]g2_defined as : g1 * c0^-1 * g1
[in]g3_defined as : g1 * (c0^-1 * g1)^2
[in]M0_diagonalised mass matrix time.
[in]M1_diagonal matrix with diag(0.5, 0, ..., 0, 0.5) -> account for boundary
[in]M2_stiffness matrix time.

Member Function Documentation

◆ check_pos_def()

void PostTheta::check_pos_def ( MatrixXd &  hess)

check if Hessian positive definite (matrix assumed to be dense & small since dim(theta) small)

Parameters
[in,out]updateshessian to only the diagonal entries if not positive definite.

◆ cond_LogPoisLik()

double PostTheta::cond_LogPoisLik ( Vect &  eta)

evaluate log Poisson likelihood

Parameters
[in]etaVector. linear predictor eta = A*x
[out]f_valdouble. evaluated log density

◆ cond_LogPriorLat()

double PostTheta::cond_LogPriorLat ( SpMat &  Qprior,
Vect &  x 
)

evaluate Gaussian log prior (without log determinant!!), mean assumed to be zero

Parameters
[in]Qpriorprecision matrix
[in]xcurrent x vector
[out]f_valevaluated log density

◆ cond_negLogBinom()

double PostTheta::cond_negLogBinom ( SpMat &  Qprior,
Vect &  x 
)

evaluate negative condiational log Poisson + Gaussian prior

Parameters
[in]extraCoeffVecLikVector. ntrials.
[in]QpriorSpMat. precision matrix.
[in]xVector. current vector x.
[out]f_valdouble. evaluated negative log density

◆ cond_negLogBinomLik()

double PostTheta::cond_negLogBinomLik ( Vect &  eta)

evaluate negative log Binomial likelihood

Parameters
[in]extraCoeffVecLikVector. ntrials.
[in]etaVector. linear predictor eta = A*x.
[out]f_valdouble. evaluated negative log density.

◆ cond_negLogDist()

double PostTheta::cond_negLogDist ( SpMat &  Qprior,
Vect &  x,
function< double(Vect &, Vect &)>  lik_func 
)

evaluate negative condiational log likelihood + Gaussian prior

Parameters
[in]extraCoeffVecLikVector.
[in]QpriorSpMat. precision matrix.
[in]xVector. current vector x.
[in]lik_funcfunction. defines the likelihood
[out]f_valdouble. evaluated negative log density

◆ cond_negLogPois()

double PostTheta::cond_negLogPois ( SpMat &  Qprior,
Vect &  x 
)

evaluate negative condiational log Poisson + Gaussian prior

Parameters
[in]QpriorSpMat. precision matrix.
[in]xVector. current vector x.
[out]f_valdouble. evaluated negative log density

◆ cond_negLogPoisLik()

double PostTheta::cond_negLogPoisLik ( Vect &  eta)

evaluate negative log Poisson likelihood

Parameters
[in]etaVector. linear predictor eta = A*x
[out]f_valdouble. evaluated negative log density

◆ construct_b()

void PostTheta::construct_b ( Vect &  theta,
Vect &  rhs 
)

Assemble right-handside.

Parameters
[in]thetacurrent theta vector
[in,out]rhsright-handside /todo Could compute Ax^T*y once, and only multiply with appropriate exp_theta.

◆ construct_Q()

void PostTheta::construct_Q ( Vect &  theta,
Vect &  mu,
SpMat &  Q 
)

construct precision matrix. Calls spatial, spatial-temporal, etc.

Parameters
[in]thetacurrent theta vector
[in]mumode latent parameters
[in,out]Qfills precision matrix

◆ construct_Q_spat_temp()

void PostTheta::construct_Q_spat_temp ( Vect &  theta,
SpMat &  Qst 
)

spatial temporal model : SPDE discretisation. DEMF(1,2,1) model.

Parameters
[in]thetacurrent theta vector
[in,out]Qstfills spatial-temporal precision matrix

◆ construct_Q_spatial()

void PostTheta::construct_Q_spatial ( Vect &  theta,
SpMat &  Qs 
)

spatial model : SPDE discretisation – matrix construction

Parameters
[in]thetacurrent theta vector
[in,out]Qsfills spatial precision matrix

◆ convert_interpret2theta_spat()

void PostTheta::convert_interpret2theta_spat ( double  lranS,
double  lsigU,
double &  lgamS,
double &  lgamE 
)

convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie. from log(rangeS, sigma.u) to log(gamma_s, gamma_E) for spatial model order 2

Parameters
[in]log(ranS)spatial range
[in]log(sigma.u)precision of random effects
[in,out]log(gamma_s)
[in,out]log(gamma_E)

◆ convert_interpret2theta_spatTemp()

void PostTheta::convert_interpret2theta_spatTemp ( double  sigU,
double  ranS,
double  ranT,
double &  lgamE,
double &  lgamS,
double &  lgamT 
)

convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie. from log(sigma.u, rangeS, rangeT) to log(gamma_E, gamma_s, gamma_t)

Parameters
[in]log(sigma.u)precision of random effects
[in]log(ranS)spatial range
[in]log(ranT)temporal range
[in,out]log(gamma_E)
[in,out]log(gamma_s)
[in,out]log(gamma_t)

◆ convert_theta2interpret_spat()

void PostTheta::convert_theta2interpret_spat ( double  lgamS,
double  lgamE,
double &  lranS,
double &  lsigU 
)

convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie. from log(rangeS, sigma.u) to log(gamma_s, gamma_E) for spatial model order 2

Parameters
[in]log(gamma_s)
[in]log(gamma_E)
[in,out]log(ranS)spatial range
[in,out]log(sigma.u)precision of random effects

◆ convert_theta2interpret_spatTemp()

void PostTheta::convert_theta2interpret_spatTemp ( double  lgamE,
double  lgamS,
double  lgamT,
double &  sigU,
double &  ranS,
double &  ranT 
)

convert hyperparameters theta from the model parametrisation to the interpretable parametrisation ie. from log(gamma_E, gamma_s, gamma_t) to log(sigma.u, rangeS, rangeT)

Parameters
[in]log(gamma_E)
[in]log(gamma_s)
[in]log(gamma_t)
[in,out]log(sigma.u)precision of random effects
[in,out]log(ranS)spatial range
[in,out]log(ranT)temporal range

◆ diagHess_cond_negLogPoisLik()

Vect PostTheta::diagHess_cond_negLogPoisLik ( Vect &  eta)

evaluate analytical negative diagonal Hessian of log Poisson likelihood

Parameters
[in]etaVector. linear predictor eta = A*x
[out]diagHessVect. diagonal of Hessian (off-diagonal entries are zero)

◆ eval_denominator()

void PostTheta::eval_denominator ( Vect &  theta,
double &  val,
SpMat &  Q,
Vect &  rhs,
Vect &  mu 
)

Evaluate denominator: conditional probability of Qx|y.

Parameters
[in]thetacurrent theta vector
[in,out]log_detfill log determinant of conditional distribution of denominator
[in,out]valfill value with mu*Q*mu
[in,out]Qconstruct precision matrix
[in,out]rhsconstruct right-handside
[in,out]muinsert mean of latent parameters

◆ eval_likelihood()

void PostTheta::eval_likelihood ( Vect &  theta,
Vect &  mu,
double &  log_det,
double &  val 
)

compute log likelihood : log_det tau*no and value -theta*yTy

Parameters
[in]thetacurrent theta vector
[in,out]log_detinserts log determinant of log likelihood.
[in,out]valinserts the value of -theta*yTy

◆ eval_log_gaussian_prior_hp()

void PostTheta::eval_log_gaussian_prior_hp ( Vect &  theta_param,
Vect &  theta_prior_param,
double &  log_prior 
)

evaluate log prior of the hyperparameters using original theta value

Parameters
[in]thetaicurrent theta_i value
[in]thetai_originaloriginal theta_i value
[in,out]logprior is being updated.

variance / precision of 1 : no normalising constant. computed through -0.5 * (theta_i* - theta_i)*(theta_i*-theta_i)

◆ eval_log_pc_prior_hp()

void PostTheta::eval_log_pc_prior_hp ( double &  log_sum,
Vect &  lambda,
Vect &  theta_interpret 
)

evaluate log prior using PC prior

Parameters
[in,out]logsum
[in]lambda: parameters for penalised complexity prior
[in]theta_interpretcurrent theta value in interpretable scale

complicated prior. check appropriate references for details.

◆ eval_log_prior_lat()

void PostTheta::eval_log_prior_lat ( Vect &  theta,
Vect &  mu,
double &  val 
)

evaluate log prior of random effects

Parameters
[in]thetacurrent theta vector
[in,out]log_detinserts log determinant.
Todo
construct spatial matrix (at the moment this is happening twice. FIX)

◆ eval_post_theta()

double PostTheta::eval_post_theta ( Vect &  theta,
Vect &  mu 
)

Core function. Evaluate posterior of theta. mu are latent parameters.

Parameters
[in]thetahyperparameter vector
[in,out]muvector of the conditional mean
Returns
f(theta) value

◆ FD_diag_hessian()

void PostTheta::FD_diag_hessian ( Vect &  eta,
Vect &  diag_hess 
)

compute finite difference diagonal of hessian. 2nd order central difference. currently stepsize h fixed.

Parameters
[in]extraCoeffVecLikVector.
[in]etaVector. linear predictor eta = A*x.
[in]lik_funcfunction. defines the likelihood
[in,out]diag_hessVector. diagonal of Hessian.

◆ FD_gradient()

void PostTheta::FD_gradient ( Vect &  eta,
Vect &  grad 
)

compute finite difference gradient. 1st order central difference. currently stepsize h fixed.

Parameters
[in]extraCoeffVecLikVector.
[in]etaVector. linear predictor eta = A*x.
[in]lik_funcfunction. defines the likelihood
[in,out]gradVector. gradient.

◆ get_Covariance()

MatrixXd PostTheta::get_Covariance ( Vect  theta,
double  eps 
)

Compute Covariance matrix of hyperparameters theta, at theta.

computes the hessian of f(theta) using a second order finite difference stencil and then inverts the hessian. Gaussian assumption.

Parameters
[in]thetahyperparameter Vector
Returns
cov covariance matrix of the hyperparameters

◆ get_fullFact_marginals_f()

void PostTheta::get_fullFact_marginals_f ( Vect &  theta,
SpMat &  Qinv 
)

Compute the marginal variances of the latent parameters at theta. Using selected inversion procedure.

Parameters
[in]Vectortheta.
[in,out]Vectorwith selected inverse for all non-zero entries of Q.

◆ get_grad()

Vect PostTheta::get_grad ( )

returns current gradient of theta.

Returns
gradient_theta

◆ get_marginals_f()

void PostTheta::get_marginals_f ( Vect &  theta,
Vect &  mu,
Vect &  vars 
)

Compute the marginal variances of the latent parameters at theta. Using selected inversion procedure.

Parameters
[in]Vectortheta.
[in,out]Vectorwith marginals of f.

◆ get_mu()

void PostTheta::get_mu ( Vect &  theta,
Vect &  mu_ 
)

get conditional mean mu for theta – Gaussian case.

Parameters
[in]thetahyperparameter vector
[in,out]mu_vector of the conditional mean

◆ grad_cond_negLogPoisLik()

Vect PostTheta::grad_cond_negLogPoisLik ( Vect &  eta)

evaluate analytical negative gradient log Poisson likelihood

Parameters
[in]etaVector. linear predictor eta = A*x
[out]gradVect. gradient.

◆ hess_eval()

MatrixXd PostTheta::hess_eval ( Vect  theta,
double  eps 
)

computes the hessian at theta using second order finite difference. Is used be get_Covariance.

Parameters
[in]thetahyperparameter vector
Returns
Dense Matrix with Hessian.
Todo
not yet parallelised ....

◆ link_f_sigmoid()

void PostTheta::link_f_sigmoid ( Vect &  x,
Vect &  sigmoidX 
)

link function. vectorized evaluation of sigmoid function for each entry

Parameters
[in]xVector. current vector x.
[in,out]sigmoidXVector. sigmoid(x) element-wise.

◆ NewtonIter()

void PostTheta::NewtonIter ( Vect &  theta,
Vect &  x,
SpMat &  Q,
double &  log_det 
)

Newton iteration to find optimum of conditional distribution latent parameters of prior & likelihood.

Parameters
[in]thetahyperparameters. can be an empty vector.
[in,out]xlatent parameters. contains initial guess of mode on entry and found mode on exit.
[in,out]QSpMat. precision matrix.
[in,out]xlog det of Q.

◆ operator()()

double PostTheta::operator() ( Vect &  theta,
Vect &  grad 
)

structure required by BFGS solver, requires : theta, gradient theta

Note
Gradient call is already parallelised using nested OpenMP. --> there are l1 threads (usually 8, one for each function evaluation), that themselves then split into another e.g. 8 threads, when calling PARDISO to factorise the system. --> somehow introduce additional parallelism to compute f(theta), possible to do in parallel

Member Data Documentation

◆ Ax

SpMat PostTheta::Ax
private

sparse matrix of size no x (nu+nb). Projects observation locations onto FEM mesh and includes covariates at the end.

◆ AxTAx

SpMat PostTheta::AxTAx
private

conmpute t(Ax)*Ax once. spat/spat temp model

◆ AxTy

Vect PostTheta::AxTy
private

compute t(Ax)*y once. spat/spat temp model

◆ B

MatrixXd PostTheta::B
private

if space (-time) model included in last columns of Ax. For regression only B exists.

◆ BTy

Vect PostTheta::BTy
private

compute t(B)*y once. regression model only

◆ c0

SpMat PostTheta::c0
private

Diagonal mass matrix spatial part.

◆ constr

const bool PostTheta::constr
private

true if there is a sum to zero constraint

◆ dim_grad_loop

int PostTheta::dim_grad_loop
private

dimension of gradient loop

◆ dim_th

int PostTheta::dim_th
private

dimension of hyperparameter vector theta

◆ Dx

const MatrixXd PostTheta::Dx
private

constraint vector, sum to zero constraint

◆ Dxy

const MatrixXd PostTheta::Dxy
private

constraint vector, sum to zero constraint

◆ fct_count

int PostTheta::fct_count
private

count total number of function evaluations

◆ G

MatrixXd PostTheta::G
private

orthonormal basis for finite difference stencil is Identity if smart gradient disabled

◆ g1

SpMat PostTheta::g1
private

stiffness matrix space.

◆ g2

SpMat PostTheta::g2
private

defined as : g1 * c0^-1 * g1

◆ g3

SpMat PostTheta::g3
private

defined as : g1 * (c0^-1 * g1)^2.

◆ iter_count

int PostTheta::iter_count
private

count total number of operator() call

◆ likelihood

string PostTheta::likelihood
private

assumed likelihood of the observations

◆ M0

SpMat PostTheta::M0
private

diagonalised mass matrix time.

◆ M1

SpMat PostTheta::M1
private

diagonal matrix with diag(0.5, 0, ..., 0, 0.5) -> account for boundary

◆ M2

SpMat PostTheta::M2
private

stiffness matrix time.

◆ manifold

string PostTheta::manifold
private

in R^d or on the sphere

◆ min_f_theta

double PostTheta::min_f_theta
private

minimum of function

◆ MPI_rank

int PostTheta::MPI_rank
private

personal mpi rank

◆ MPI_size

int PostTheta::MPI_size
private

number of mpi ranks

◆ mu

Vect PostTheta::mu
private

conditional mean

◆ mu_matrix

MatrixXd PostTheta::mu_matrix
private

store all mu values from previous iteration, dim(mu_matrix) = (n, 2*dim_th+1)

◆ mu_midpoint

Vect PostTheta::mu_midpoint
private

conditional mean, at mid point \theta^k

◆ n

int PostTheta::n
private

total number of unknowns, i.e. ns*nt + nb

◆ nb

int PostTheta::nb
private

number of fixed effects

◆ no

int PostTheta::no
private

number of observations

◆ no_f_eval

int PostTheta::no_f_eval
private

number of function evaluations per iteration

◆ ns

int PostTheta::ns
private

number of spatial grid points per timestep

◆ nss

int PostTheta::nss
private

size of add. spatial field, not def = 0

◆ nst

int PostTheta::nst
private

ns*nt, equal to nu if nss =0

◆ nt

int PostTheta::nt
private

number of temporal time steps

◆ nu

int PostTheta::nu
private

number of random effects, that ns*nu

◆ num_solvers

int PostTheta::num_solvers
private

number of pardiso solvers

◆ prior

std::string PostTheta::prior
private

type of pripr to be used

◆ Qb

SpMat PostTheta::Qb
private

setup indices once. Only prior fixed effects.

◆ Qu

SpMat PostTheta::Qu
private

setup indices once. Only prior random effects

◆ Qx

SpMat PostTheta::Qx
private

setup indices once. Includes Prior RE + FE.

◆ Qxy

SpMat PostTheta::Qxy
private

setup indices for Qxy once.

◆ t_grad

Vect PostTheta::t_grad
private

gradient of theta

◆ theta_prior_param

Vect PostTheta::theta_prior_param
private

vector with prior values. Constructs normal distribution with sd = 1 around these values.

◆ threads_level1

int PostTheta::threads_level1
private

number of threads on first level

◆ w_sum

double PostTheta::w_sum
private

only used if validate is true

◆ y

Vect PostTheta::y
private

vector of observations y. has length no.

◆ yTy

double PostTheta::yTy
private

compute t(y)*y once.


The documentation for this class was generated from the following files: