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();
     }
   }
 }
示例#2
0
  bool TIM::locate_mode(const Vector & old){
    cand_ = old;
    g_ = old;
    H_.resize(old.size(), old.size());
    double max_value;
    string error_message;
    bool ok = max_nd2_careful(cand_, g_, H_, max_value,
                              f_, df_, d2f_,
                              1e-5, error_message);

    if(!ok) {
      mode_has_been_found_ = false;
      return false;
    }
    H_*= -1;
    mode_has_been_found_ = true;
    check_proposal(old.size());
    prop_->set_mu(cand_);
    prop_->set_ivar(H_);
    return true;
  }
  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();
    }
  }