7 #ifndef IMPISD_VON_MISES_SUFFICIENT_H
8 #define IMPISD_VON_MISES_SUFFICIENT_H
10 #include <IMP/isd/isd_config.h>
15 #include <boost/math/special_functions/bessel.hpp>
17 IMPISD_BEGIN_NAMESPACE
47 :
Object(
"von Mises sufficient %1%"),
52 force_set_kappa(kappa);
63 :
Object(
"von Mises sufficient %1%"), x_(chi) {
64 Floats stats = get_sufficient_statistics(obs);
65 N_ = (unsigned)stats[0];
68 force_set_kappa(kappa);
72 virtual double evaluate()
const {
73 return logterm_ - R0_ * kappa_ * cos(x_ - chiexp_);
76 virtual double evaluate_derivative_x()
const {
77 return R0_ * kappa_ * sin(x_ - chiexp_);
80 virtual double evaluate_derivative_kappa()
const {
81 return -R0_ * cos(x_ - chiexp_) + double(N_) * I1_ / I0_;
85 virtual double density()
const {
86 return exp(R0_ * kappa_ * cos(x_ - chiexp_)) / (2 *
IMP::PI * I0N_);
90 double get_x() {
return x_; }
91 double get_R0() {
return R0_; }
92 double get_chiexp() {
return chiexp_; }
93 double get_N() {
return N_; }
94 double get_kappa() {
return kappa_; }
97 void set_x(
double x) { x_ = x; }
99 void set_R0(
double R0) { R0_ = R0; }
101 void set_chiexp(
double chiexp) { chiexp_ = chiexp; }
103 void set_N(
unsigned N) {
105 I0N_ = pow(I0_, static_cast<int>(N_));
106 logterm_ = log(2 *
IMP::PI * I0N_);
109 void set_kappa(
double kappa) {
110 if (kappa_ != kappa) {
111 force_set_kappa(kappa);
122 unsigned N = data.size();
126 for (
unsigned i = 0; i < N; ++i) {
127 cosbar += cos(data[i]);
128 sinbar += sin(data[i]);
130 double R = sqrt(cosbar * cosbar + sinbar * sinbar);
131 double chi = acos(cosbar / R);
132 if (sinbar < 0) chi = -chi;
146 double x_, R0_, chiexp_, kappa_, I0_, I1_, logterm_, I0N_;
148 void force_set_kappa(
double kappa) {
150 I0_ = double(boost::math::cyl_bessel_i(0, kappa));
151 I1_ = double(boost::math::cyl_bessel_i(1, kappa));
152 I0N_ = pow(I0_, static_cast<int>(N_));
153 logterm_ = log(2 *
IMP::PI * I0N_);
static const double PI
the constant pi
Various useful constants.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
static Floats get_sufficient_statistics(Floats data)
Compute sufficient statistics from a list of observations.
vonMisesSufficient(double chi, unsigned N, double R0, double chiexp, double kappa)
Storage of a model, its restraints, constraints and particles.
Various general useful macros for IMP.
Common base class for heavy weight IMP objects.
vonMisesSufficient(double chi, Floats obs, double kappa)