IMP logo
IMP Reference Guide  2.8.0
The Integrative Modeling Platform
isd/distribution.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/distribution.h
3  * \brief Base class for probability distributions
4  *
5  * Copyright 2007-2017 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPISD_DISTRIBUTION_H
9 #define IMPISD_DISTRIBUTION_H
10 
11 #include <IMP/isd/isd_config.h>
12 #include <IMP/macros.h>
13 #include <IMP/Model.h>
14 
15 IMPISD_BEGIN_NAMESPACE
16 
17 //! Base class for all distributions, provided for common inheritance.
18 /** This base class exists to define a common parent for all distribution types.
19  Children are expected to define one or more evaluate() and get_density()
20  methods taking an arbitrary number of arguments to provide negative
21  log-density and probability density, respectively.
22  */
23 class IMPISDEXPORT Distribution : public Object {
24  public:
25  Distribution(std::string name = "Distribution %1%")
26  : Object(name) {}
27 
29 };
31 
32 
33 //! Base class for distributions that are passed a single random variable.
34 /** Children must overload IMP::isd::OneDimensionalDistribution::do_evaluate().
35  */
36 class IMPISDEXPORT OneDimensionalDistribution : public Distribution {
37  protected:
38  virtual double do_evaluate(double v) const = 0;
39  virtual double do_get_density(double v) const;
40  virtual Floats do_evaluate(const Floats &vs) const;
41  virtual Floats do_get_density(const Floats &vs) const;
42 
43  public:
45  std::string name = "OneDimensionalDistribution %1%"): Distribution(name) {
46  }
47 
48  //! Get negative log-density for passed variable value.
49  double evaluate(double v) const { return do_evaluate(v); }
50 
51  //! Get negative log-densities for passed variable values.
52  Floats evaluate(const Floats &vs) const { return do_evaluate(vs); }
53 
54  //! Get probability density for passed variable value.
55  double get_density(double v) const { return do_get_density(v); }
56 
57  //! Get probability densities for passed variable values.
58  Floats get_density(const Floats &vs) const { return do_get_density(vs); }
59 
61 };
63 
64 
65 //! Base class for single-variate distributions that cache sufficient statistics.
66 /** Sufficient statistics are one or more statistics whose values are sufficient
67  to describe the entire distribution. For the joint probability of many
68  independent draws from a distribution, the set of all drawn values is
69  a sufficient statistic, but minimally sufficient statistics (such as the
70  mean and variance for a joint normal distribution) often exist, permitting
71  one-time calculation and efficient use of memory.
72 
73  Children must overload the following methods:
74  - IMP::isd::OneDimensionalSufficientDistribution::do_update_sufficient_statistics()
75  - IMP::isd::OneDimensionalSufficientDistribution::do_get_sufficient_statistics()
76  - IMP::isd::OneDimensionalSufficientDistribution::do_evaluate()
77 
78  */
80  protected:
81  virtual void do_update_sufficient_statistics(Floats vs) = 0;
82  virtual Floats do_get_sufficient_statistics() const = 0;
83  virtual double do_evaluate() const = 0;
84  virtual double do_get_density() const;
85 
86  public:
87  //! Constructor
89  std::string name = "OneDimensionalSufficientDistribution %1%")
90  : Distribution(name) {}
91 
92  //! Update cached sufficient statistics from data.
94  do_update_sufficient_statistics(vs);
95  }
96 
97  Floats get_sufficient_statistics() const {
98  return do_get_sufficient_statistics();
99  }
100 
101  //! Get negative log-density using cached sufficient statistics.
102  double evaluate() const { return do_evaluate(); }
103 
104  //! Get probability density using cached sufficient statistics.
105  double get_density() const { return do_get_density(); }
106 
108 };
110 
111 IMPISD_END_NAMESPACE
112 
113 #endif /* IMPISD_DISTRIBUTION_H */
Base class for single-variate distributions that cache sufficient statistics.
OneDimensionalSufficientDistribution(std::string name="OneDimensionalSufficientDistribution %1%")
Constructor.
Floats evaluate(const Floats &vs) const
Get negative log-densities for passed variable values.
double get_density() const
Get probability density using cached sufficient statistics.
double get_density(double v) const
Get probability density for passed variable value.
double evaluate(double v) const
Get negative log-density for passed variable value.
#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.
double evaluate() const
Get negative log-density using cached sufficient statistics.
Various general useful macros for IMP.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
Common base class for heavy weight IMP objects.
Definition: Object.h:106
Base class for distributions that are passed a single random variable.
Floats get_density(const Floats &vs) const
Get probability densities for passed variable values.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
Base class for all distributions, provided for common inheritance.
Object(std::string name)
Construct an object with the given name.
void update_sufficient_statistics(Floats vs)
Update cached sufficient statistics from data.