IMP logo
IMP Reference Guide  2.13.0
The Integrative Modeling Platform
FNormal.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/FNormal.h \brief Normal distribution of Function
3  *
4  * Copyright 2007-2020 IMP Inventors. All rights reserved.
5  */
6 
7 #ifndef IMPISD_FNORMAL_H
8 #define IMPISD_FNORMAL_H
9 
10 #include <IMP/isd/isd_config.h>
11 #include <IMP/isd/distribution.h>
12 #include <IMP/macros.h>
13 #include <IMP/Model.h>
14 #include <IMP/constants.h>
15 #include <math.h>
16 
17 IMPISD_BEGIN_NAMESPACE
18 
19 //! FNormal
20 /** Probability density function and -log(p) of normal sampling from some
21  function F. If A is drawn from the F-Normal distribution then F(A) is
22  drawn from a normal distribution with mean F(M) and standard deviation
23  sigma (w/r F(A)).
24 
25  Arguments: F(A), J(A) the derivative of F w/r to A, F(M), and sigma. The
26  distribution is normalized with respect to the variable A. Note that the
27  mean and standard deviation with respect to A may not be M and sigma.
28 
29  Example: If F is the log function, the F-normal distribution is the
30  lognormal distribution with mean log(M) and standard deviation sigma
31  (wrt. log(A)).
32 
33  \note F must be a one-to-one function, i.e., it must be monotonically
34  increasing or decreasing. This is not checked. For a monotonically
35  decreasing function, set JA to -JA, so that JA > 0.
36  */
37 class IMPISDEXPORT FNormal : public OneDimensionalSufficientDistribution {
38  public:
39  FNormal(double FA, double JA, double FM, double sigma)
40  : OneDimensionalSufficientDistribution("FNormal %1%"), JA_(JA), FM_(FM)
41  , sigma_(sigma) {
43  }
44 
45  virtual void update_sufficient_statistics(double FA) {
46  set_FA(FA);
47  }
48 
49  virtual void do_update_sufficient_statistics(Floats data) IMP_OVERRIDE {
51  }
52 
53  virtual Floats do_get_sufficient_statistics() const IMP_OVERRIDE {
54  return Floats(1, FA_);
55  }
56 
57  /* energy (score) functions, aka -log(p) */
58  virtual double do_evaluate() const IMP_OVERRIDE {
59  return -log(JA_ / sigma_) + 0.5 * log(2 * IMP::PI) +
60  1 / (2 * square(sigma_)) * square(FA_ - FM_);
61  }
62 
63  // derivative of score wrt F(A)
64  virtual double evaluate_derivative_FA() const {
65  return (FA_ - FM_) / square(sigma_);
66  }
67 
68  virtual double evaluate_derivative_JA() const { return -1 / JA_; }
69 
70  // derivative wrt F(M)
71  virtual double evaluate_derivative_FM() const {
72  return (FM_ - FA_) / square(sigma_);
73  }
74 
75  virtual double evaluate_derivative_sigma() const {
76  return 1 / sigma_ - square(FA_ - FM_) / pow(sigma_, 3);
77  }
78 
79  /* probability density function */
80  virtual double do_get_density() const IMP_OVERRIDE {
81  return JA_ / (sqrt(2 * IMP::PI) * sigma_) *
82  exp(-square(FA_ - FM_) / (2 * square(sigma_)));
83  }
84 
85  /* change of parameters */
86  void set_FA(double f) { FA_ = f; }
87  void set_JA(double f) { JA_ = f; }
88  void set_FM(double f) { FM_ = f; }
89  void set_sigma(double f) { sigma_ = f; }
90 
92  /*IMP_OBJECT_INLINE(FNormal, out << "FNormal: " << FA_ << ", " << JA_
93  << ", " << FM_ << ", " << sigma_ <<std::endl, {});*/
94 
95  private:
96  double FA_, JA_, FM_, sigma_;
97 };
98 
99 IMPISD_END_NAMESPACE
100 
101 #endif /* IMPISD_FNORMAL_H */
Declare an efficient stl-compatible map.
Base class for single-variate distributions that cache sufficient statistics.
OneDimensionalSufficientDistribution(std::string name="OneDimensionalSufficientDistribution %1%")
Constructor.
static const double PI
the constant pi
Various useful constants.
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: types.h:47
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Storage of a model, its restraints, constraints and particles.
Various general useful macros for IMP.
Base class for probability distributions.
FNormal.
Definition: FNormal.h:37
void update_sufficient_statistics(Floats vs)
Update cached sufficient statistics from data.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.