double BLSSS::log_model_prob(const Selector &g)const{ // borrowed from MLVS.cpp double num = vpri_->logp(g); if(num==BOOM::negative_infinity() || g.nvars() == 0) { // If num == -infinity then it is in a zero support point in the // prior. If g.nvars()==0 then all coefficients are zero // because of the point mass. The only entries remaining in the // likelihood are sums of squares of y[i] that are independent // of g. They need to be omitted here because they are omitted // in the non-empty case below. return num; } SpdMatrix ivar = g.select(pri_->siginv()); num += .5*ivar.logdet(); if(num == BOOM::negative_infinity()) return num; Vector mu = g.select(pri_->mu()); Vector ivar_mu = ivar * mu; num -= .5*mu.dot(ivar_mu); bool ok=true; ivar += g.select(suf().xtx()); Matrix L = ivar.chol(ok); if(!ok) return BOOM::negative_infinity(); double denom = sum(log(L.diag())); // = .5 log |ivar| Vector S = g.select(suf().xty()) + ivar_mu; Lsolve_inplace(L,S); denom-= .5*S.normsq(); // S.normsq = beta_tilde ^T V_tilde beta_tilde return num-denom; }
// The likelihood is \prod root(2pi)^-d |siginv|^{n/2} exp{-1/2 * trace(qform)} double MvReg::log_likelihood_ivar(const Matrix &Beta, const SpdMatrix &Siginv) const { double qform = trace(suf()->SSE(Beta) * Siginv); double n = suf()->n(); double normalizing_constant = -.5 * (n * ydim()) * Constants::log_2pi; return normalizing_constant + .5 * n * Siginv.logdet() - .5 * qform; }
//====================================================================== double dmvt(const Vector &x, const Vector &mu, const SpdMatrix &Siginv, double nu, bool logscale){ double ldsi = Siginv.logdet(); return dmvt(x, mu, Siginv, nu, ldsi, logscale); }
double dmvn(const Vector &y, const Vector &mu, const SpdMatrix &Siginv, bool logscale) { double ldsi = Siginv.logdet(); return dmvn(y, mu, Siginv, ldsi, logscale); }