21#include <Eigen/SparseCholesky>
23#include <unsupported/Eigen/KroneckerProduct>
28#include "PardisoSolver.h"
31#include "EigenCholSolver.h"
46typedef Eigen::SparseMatrix<double> SpMat;
47typedef Eigen::SparseMatrix<double, RowMajor> SpRmMat;
48typedef Eigen::VectorXd Vect;
78 int dim_spatial_domain;
86 int threadID_solverQst;
90 Vect extraCoeffVecLik;
153 ArrayXi task_to_rank_list_grad;
159 bool thetaDiff_initialized;
175 bool printed_eps_flag =
false;
178 std::string log_file_name;
183 double t_priorLatAMat;
186 double t_condLatAMat;
188 double t_thread_denom;
193 double t_priorLatChol;
194 double t_condLatChol;
195 double t_condLatSolve;
218 const bool validate,
const Vect w);
232 SpMat
Ax, Vect
y, SpMat
c0, SpMat
g1, SpMat
g2,
237 int dim_spatial_domain,
string manifold,
238 const bool constr,
const MatrixXd
Dx,
const MatrixXd
Dxy,
239 const bool validate,
const Vect w);
264 SpMat
Ax, Vect
y, SpMat
c0, SpMat
g1, SpMat
g2, SpMat
g3,
265 SpMat
M0, SpMat
M1, SpMat
M2,
270 int dim_spatial_domain,
string manifold,
271 const bool constr,
const MatrixXd
Dx,
const MatrixXd
Dxy,
272 const bool validate,
const Vect w);
293 SpMat
Ax, Vect
y, SpMat
c0, SpMat
g1, SpMat
g2, SpMat
g3,
294 SpMat
M0, SpMat
M1, SpMat
M2,
299 int dim_spatial_domain,
string manifold,
300 const bool constr,
const MatrixXd
Dx,
const MatrixXd
Dxy,
301 const bool validate,
const Vect w);
314 double compute_error_bfgs(Vect& theta);
329 void convert_theta2interpret(Vect& theta, Vect& theta_interpret);
331 void convert_interpret2theta(Vect& theta_interpret, Vect& theta);
386 void get_mu(Vect& theta, Vect& mu_);
403 void get_Qprior(Vect theta, SpMat& Qprior);
414 MatrixXd get_Cov_interpret_param(Vect interpret_theta,
double eps);
416 double f_eval(Vect& theta);
434 void compute_fullInverseQ(Vect& theta, MatrixXd& Qinv);
443 MatrixXd
hess_eval(Vect theta,
double eps);
445 MatrixXd hess_eval_interpret_theta(Vect interpret_theta,
double eps);
483 void update_mean_constr(
const MatrixXd& D, Vect& e, Vect& sol, MatrixXd& V, MatrixXd& W, MatrixXd& U, Vect& updated_sol);
485 void eval_log_dens_constr(Vect& x, Vect&
mu, SpMat&Q,
double& log_det_Q,
const MatrixXd& D, MatrixXd& W,
double& val_log_dens);
517 void construct_Qprior(Vect& theta, SpMat&
Qx);
616 double cond_negLogDist(SpMat &Qprior, Vect& x, function<
double(Vect&, Vect&)> lik_func);
641 void NewtonIter(Vect& theta, Vect& x, SpMat& Q,
double& log_det);
645 void record_times(std::string file_name,
int iter_count,
double t_Ftheta_ext,
double t_thread_nom,
double t_priorHyp,
646 double t_priorLat,
double t_priorLatAMat,
double t_priorLatChol,
double t_likel,
647 double t_thread_denom,
double t_condLat,
double t_condLatAMat,
double t_condLatChol,
double t_condLatSolve);
Definition Hyperparameters.h:26
Computes the Posterior of the hyperparameters theta.
Definition PostTheta.h:55
int dim_grad_loop
Definition PostTheta.h:80
int nst
Definition PostTheta.h:70
SpMat M0
Definition PostTheta.h:123
SpMat Qxy
Definition PostTheta.h:133
void convert_interpret2theta_spat(double lranS, double lsigU, double &lgamS, double &lgamE)
convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie....
Definition PostTheta.cpp:1430
int n
Definition PostTheta.h:72
void check_pos_def(MatrixXd &hess)
check if Hessian positive definite (matrix assumed to be dense & small since dim(theta) small)
Definition PostTheta.cpp:2141
void link_f_sigmoid(Vect &x, Vect &sigmoidX)
link function. vectorized evaluation of sigmoid function for each entry
Definition PostTheta.cpp:3384
void construct_Q_spatial(Vect &theta, SpMat &Qs)
spatial model : SPDE discretisation – matrix construction
Definition PostTheta.cpp:2864
void computeG(Vect &theta)
overwriting G every time, not explicitly listed, better way to do this? needs to be stored after ever...
MatrixXd hess_eval(Vect theta, double eps)
computes the hessian at theta using second order finite difference. Is used be get_Covariance.
Definition PostTheta.cpp:1660
void eval_log_prior_lat(Vect &theta, Vect &mu, double &val)
evaluate log prior of random effects
Definition PostTheta.cpp:2670
double min_f_theta
Definition PostTheta.h:148
SpMat AxTAx
Definition PostTheta.h:138
double operator()(Vect &theta, Vect &grad)
structure required by BFGS solver, requires : theta, gradient theta
Definition PostTheta.cpp:834
double eval_post_theta(Vect &theta, Vect &mu)
Core function. Evaluate posterior of theta. mu are latent parameters.
Definition PostTheta.cpp:2172
string manifold
Definition PostTheta.h:79
Vect theta_prior_param
Definition PostTheta.h:100
int ns
Definition PostTheta.h:65
int threads_level1
Definition PostTheta.h:61
double cond_negLogPois(SpMat &Qprior, Vect &x)
evaluate negative condiational log Poisson + Gaussian prior
Definition PostTheta.cpp:3371
void get_marginals_f(Vect &theta, Vect &mu, Vect &vars)
Compute the marginal variances of the latent parameters at theta. Using selected inversion procedure.
Definition PostTheta.cpp:1564
const MatrixXd Dxy
Definition PostTheta.h:166
void eval_denominator(Vect &theta, double &val, SpMat &Q, Vect &rhs, Vect &mu)
Evaluate denominator: conditional probability of Qx|y.
Definition PostTheta.cpp:3184
SpMat Qx
Definition PostTheta.h:132
void eval_log_pc_prior_hp(double &log_sum, Vect &lambda, Vect &theta_interpret)
evaluate log prior using PC prior
Definition PostTheta.cpp:2553
void get_mu(Vect &theta, Vect &mu_)
get conditional mean mu for theta – Gaussian case.
Definition PostTheta.cpp:1446
Vect get_grad()
returns current gradient of theta.
Definition PostTheta.cpp:1482
SpMat Qu
Definition PostTheta.h:129
int iter_count
Definition PostTheta.h:97
SpMat c0
Definition PostTheta.h:117
~PostTheta()
class destructor. Frees memory allocated by PostTheta class.
Definition PostTheta.cpp:3646
Vect AxTy
Definition PostTheta.h:137
void construct_Q(Vect &theta, Vect &mu, SpMat &Q)
construct precision matrix. Calls spatial, spatial-temporal, etc.
Definition PostTheta.cpp:3053
Vect y
Definition PostTheta.h:99
void FD_gradient(Vect &eta, Vect &grad)
compute finite difference gradient. 1st order central difference. currently stepsize h fixed.
Definition PostTheta.cpp:3427
int dim_th
Definition PostTheta.h:77
int MPI_size
Definition PostTheta.h:59
int nss
Definition PostTheta.h:67
int nu
Definition PostTheta.h:71
double w_sum
Definition PostTheta.h:150
SpMat Ax
Definition PostTheta.h:110
int nb
Definition PostTheta.h:68
SpMat M2
Definition PostTheta.h:126
void FD_diag_hessian(Vect &eta, Vect &diag_hess)
compute finite difference diagonal of hessian. 2nd order central difference. currently stepsize h fix...
Definition PostTheta.cpp:3470
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
Definition PostTheta.cpp:2543
Vect grad_cond_negLogPoisLik(Vect &eta)
evaluate analytical negative gradient log Poisson likelihood
Definition PostTheta.cpp:3351
SpMat Qb
Definition PostTheta.h:128
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....
Definition PostTheta.cpp:1324
Vect t_grad
Definition PostTheta.h:147
int no_f_eval
Definition PostTheta.h:152
Vect mu
Definition PostTheta.h:140
double cond_negLogBinom(SpMat &Qprior, Vect &x)
evaluate negative condiational log Poisson + Gaussian prior
Definition PostTheta.cpp:3403
int MPI_rank
Definition PostTheta.h:60
MatrixXd get_Covariance(Vect theta, double eps)
Compute Covariance matrix of hyperparameters theta, at theta.
Definition PostTheta.cpp:1494
Vect mu_midpoint
Definition PostTheta.h:141
Vect BTy
Definition PostTheta.h:136
void construct_Q_spat_temp(Vect &theta, SpMat &Qst)
spatial temporal model : SPDE discretisation. DEMF(1,2,1) model.
Definition PostTheta.cpp:2908
SpMat g3
Definition PostTheta.h:122
int nt
Definition PostTheta.h:66
int num_solvers
Definition PostTheta.h:81
MatrixXd mu_matrix
Definition PostTheta.h:144
double cond_LogPriorLat(SpMat &Qprior, Vect &x)
evaluate Gaussian log prior (without log determinant!!), mean assumed to be zero
Definition PostTheta.cpp:3325
MatrixXd B
Definition PostTheta.h:113
int fct_count
Definition PostTheta.h:96
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).
Definition PostTheta.cpp:7
double cond_negLogDist(SpMat &Qprior, Vect &x, function< double(Vect &, Vect &)> lik_func)
evaluate negative condiational log likelihood + Gaussian prior
Definition PostTheta.cpp:3417
Vect diagHess_cond_negLogPoisLik(Vect &eta)
evaluate analytical negative diagonal Hessian of log Poisson likelihood
Definition PostTheta.cpp:3366
const bool constr
Definition PostTheta.h:164
void NewtonIter(Vect &theta, Vect &x, SpMat &Q, double &log_det)
Newton iteration to find optimum of conditional distribution latent parameters of prior & likelihood.
Definition PostTheta.cpp:3519
double yTy
Definition PostTheta.h:135
SpMat g1
Definition PostTheta.h:118
SpMat g2
Definition PostTheta.h:119
std::string prior
Definition PostTheta.h:94
string likelihood
Definition PostTheta.h:89
double cond_negLogBinomLik(Vect &eta)
evaluate negative log Binomial likelihood
Definition PostTheta.cpp:3390
void convert_theta2interpret_spat(double lgamS, double lgamE, double &lranS, double &lsigU)
convert hyperparameters theta from the interpretable parametrisation to the model parametrisation ie....
Definition PostTheta.cpp:1411
void eval_likelihood(Vect &theta, Vect &mu, double &log_det, double &val)
compute log likelihood : log_det tau*no and value -theta*yTy
Definition PostTheta.cpp:2815
double cond_negLogPoisLik(Vect &eta)
evaluate negative log Poisson likelihood
Definition PostTheta.cpp:3343
int no
Definition PostTheta.h:69
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....
Definition PostTheta.cpp:1286
double cond_LogPoisLik(Vect &eta)
evaluate log Poisson likelihood
Definition PostTheta.cpp:3336
void construct_b(Vect &theta, Vect &rhs)
Assemble right-handside.
Definition PostTheta.cpp:3172
const MatrixXd Dx
Definition PostTheta.h:165
SpMat M1
Definition PostTheta.h:124
MatrixXd G
Definition PostTheta.h:155
void get_fullFact_marginals_f(Vect &theta, SpMat &Qinv)
Compute the marginal variances of the latent parameters at theta. Using selected inversion procedure.
abstract base solver class to enable to be able two switch between solvers (current options: PARDISO ...
Definition Solver.h:27