double BLSSS::find_posterior_mode() { BinomialLogitUnNormalizedLogPosterior logpost(m_, pri_.get()); const Selector &inc(m_->coef().inc()); Vector beta(m_->included_coefficients()); int dim = beta.size(); if (dim == 0) { return negative_infinity(); // TODO: This logic prohibits an empty model. Better to return // the actual value of the un-normalized posterior, which in // this case would just be the likelihood portion. } else { Vector gradient(dim); Matrix hessian(dim, dim); double logf; std::string error_message; bool ok = max_nd2_careful(beta, gradient, hessian, logf, Target(logpost), dTarget(logpost), d2Target(logpost), 1e-5, error_message); if (ok) { m_->set_included_coefficients(beta, inc); return logf; } else { return negative_infinity(); } } }
void LogitEMC::find_posterior_mode(){ if(!pri_){ ostringstream err; err << "Logit_EMC cannot find posterior mode. " << "No prior is set." << endl; throw_exception<std::runtime_error>(err.str()); } d2LoglikeTF loglike(this); d2LogPostTF logpost(loglike, pri_); Vec b = this->beta(); uint dim = b.size(); Vec g(dim); Mat h(dim,dim); b = max_nd2(b, g, h, Target(logpost), dTarget(logpost), d2Target(logpost), 1e-5); this->set_beta(b); }
void LogitEMC::find_posterior_mode(){ if(!pri_){ ostringstream err; err << "Logit_EMC cannot find posterior mode. " << "No prior is set." << endl; report_error(err.str()); } d2LoglikeTF loglike(this); d2LogPostTF logpost(loglike, pri_); Vector b = this->Beta(); uint dim = b.size(); Vector g(dim); Matrix h(dim,dim); b = max_nd2(b, g, h, Target(logpost), dTarget(logpost), d2Target(logpost), 1e-5); this->set_Beta(b); }
double PRSS::find_posterior_mode() { const Selector &included(model_->inc()); d2TargetFunPointerAdapter logpost( boost::bind(&PoissonRegressionModel::log_likelihood, model_, _1, _2, _3, _4), boost::bind(&MvnBase::logp_given_inclusion, slab_prior_.get(), _1, _2, _3, included, _4)); Vector beta = model_->included_coefficients(); int dim = beta.size(); if (dim == 0) { return negative_infinity(); // TODO: This logic prohibits an empty model. Better to return // the actual value of the un-normalized log posterior, which in // this case would just be the likelihood portion. } Vector gradient(dim); Spd hessian(dim); double logf; std::string error_message; bool ok = max_nd2_careful(beta, gradient, hessian, logf, Target(logpost), dTarget(logpost), d2Target(logpost), 1e-5, error_message); if (ok) { model_->set_included_coefficients(beta, included); return logf; } else { return negative_infinity(); } }