double vonMisesKappaConjugateRestraint::get_probability() const {
  Scale kappascale(kappa_);
  double kappaval = get_kappa();
  // std::cout << "kappa " << kappaval << " c " << c_ << " R0 " << R0_
  //    << " I0 " << I0_ << " exp "  << std::exp(kappaval*R0_)
  //    << " pow " << pow(I0_,-c_) << std::endl;
  if (R0_ > 0) {
    return std::exp(kappaval * R0_) * pow(I0_, -c_);
  } else {
    return pow(I0_, -c_);
  }
}
double vonMisesKappaJeffreysRestraint::get_probability() const {
  Scale kappascale(kappa_);
  double kappaval = kappascale.get_scale();
  if (kappaval <= 0) {
    IMP_THROW("cannot use jeffreys prior on negative or zero scale",
              ModelException);
  }
  if (kappaval != old_kappaval) {
    const_cast<vonMisesKappaJeffreysRestraint *>(this)->update_bessel(kappaval);
  }
  double ratio = I1_ / I0_;
  return sqrt(ratio * (kappaval - ratio - kappaval * ratio * ratio));
}
double vonMisesKappaConjugateRestraint::get_kappa() const {
  Scale kappascale(kappa_);
  double kappaval = kappascale.get_scale();
  if (kappaval <= 0) {
    IMP_THROW("cannot use conjugate prior on negative or zero scale",
              ModelException);
  }
  if (!bessel_init_ || kappaval != old_kappaval) {
    const_cast<vonMisesKappaConjugateRestraint *>(this)
        ->update_bessel(kappaval);
  }
  return kappaval;
}
/* Apply the score if it's a scale decorator.
 */
double vonMisesKappaJeffreysRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  double score;
  Scale kappascale(kappa_);
  double kappaval = kappascale.get_scale();
  // computes the bessel functions if necessary
  score = -std::log(get_probability());
  if (accum) {
    /* calculate derivative and add to 1st coordinate of kappascale */
    double ratio = I1_ / I0_;
    double deriv =
        0.5 *
        (-1.0 / ratio + 3 * ratio + 1 / kappaval +
         1 / (kappaval * (1 - kappaval / ratio) + ratio * kappaval * kappaval));
    kappascale.add_to_scale_derivative(deriv, *accum);
  }
  return score;
}
double vonMisesKappaConjugateRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  double score;
  Scale kappascale(kappa_);
  double kappaval = get_kappa();
  if (R0_ > 0) {
    score = -kappaval * R0_ + c_ * std::log(I0_);
  } else {
    score = c_ * std::log(I0_);
  }

  if (accum) {
    /* calculate derivative and add to 1st coordinate of kappascale */
    double deriv = -R0_ + c_ * I1_ / I0_;
    kappascale.add_to_scale_derivative(deriv, *accum);
  }
  return score;
}
示例#6
0
/** \param[in] accum If not nullptr, use this object to accumulate
    partial first
    derivatives.
    \return Current score.
 */
double
TALOSRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const
{
    core::XYZ d0 = core::XYZ::decorate_particle(p_[0]);
    core::XYZ d1 = core::XYZ::decorate_particle(p_[1]);
    core::XYZ d2 = core::XYZ::decorate_particle(p_[2]);
    core::XYZ d3 = core::XYZ::decorate_particle(p_[3]);
    Scale kappascale(kappa_);
    double kappaval=kappascale.get_scale();

  // get angle
  algebra::VectorD<3> derv0, derv1, derv2, derv3;
  double angle;
  if (accum) {
    angle = core::internal::dihedral(d0, d1, d2, d3, &derv0, &derv1,
                                      &derv2, &derv3);
  } else {
    angle = core::internal::dihedral(d0, d1, d2, d3, nullptr,
                                     nullptr, nullptr, nullptr);
  }

  // score current angle
  mises_->set_x(angle);
  mises_->set_kappa(kappaval);
  double score=mises_->evaluate();

  //store derivatives if necessary
  if (accum) {

    double deriv=mises_->evaluate_derivative_x();
    d0.add_to_derivatives(derv0 * deriv, *accum);
    d1.add_to_derivatives(derv1 * deriv, *accum);
    d2.add_to_derivatives(derv2 * deriv, *accum);
    d3.add_to_derivatives(derv3 * deriv, *accum);

    kappascale.add_to_scale_derivative(mises_->evaluate_derivative_kappa(),
                                       *accum);
  }
  return score;
}