IMP  2.1.0
The Integrative Modeling Platform
GaussianProcessInterpolationRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/GaussianProcessInterpolationRestraint.h
3  * \brief kernel::Restraint and ScoreState for GaussianProcessInterpolation
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPISD_GAUSSIAN_PROCESS_INTERPOLATION_RESTRAINT_H
9 #define IMPISD_GAUSSIAN_PROCESS_INTERPOLATION_RESTRAINT_H
10 
11 #include <IMP/isd/isd_config.h>
12 #include <IMP/macros.h>
13 #include <boost/scoped_ptr.hpp>
14 #include <IMP/kernel/Restraint.h>
17 #include <IMP/base/Pointer.h>
18 #include <Eigen/Dense>
19 #include <Eigen/Cholesky>
20 
21 #include <IMP/ScoreState.h>
22 
23 
24 IMPISD_BEGIN_NAMESPACE
25 #ifndef SWIG
26 using Eigen::MatrixXd;
27 using Eigen::VectorXd;
28 using Eigen::RowVectorXd;
29 #endif
30 
31 class GaussianProcessInterpolationScoreState;
32 
33 //! gaussian process restraint
34 /* the restraint is a multivariate normal distribution on the vector of
35 * observations with mean and standard deviation given by the posterior of the
36 * gaussian process.
37 */
39  public kernel::Restraint
40 {
41  private:
42  // checks and makes necessary updates
43  void update_mean_and_covariance();
47  //number of observation points
48  unsigned M_;
49 
50  void create_score_state();
51 
52  public:
53  // this is a restraint on other restraints. It first constructs the
54  // necessary vectors from GaussianProcessInterpolation, then creates a
55  // multivariate normal distribution around it. Upon evaluation, it
56  // checks if parameters have changed, reconstructs the matrix if
57  // necessary, changes the DA weight and passes it to the functions.
60 
61  //to call this, you need to update the scorestate before.
62  //calling model.evaluate(False) is enough.
63  double get_probability() const
64  {
65  return mvn_->density();
66  }
67 
68  void stats() const
69  {
70  return mvn_->stats();
71  }
72 
73  //use conjugate gradients when possible (default false)
74  void set_use_cg(bool use, double tol) {mvn_->set_use_cg(use,tol);}
75 
76  //get minus log normalization and minus exponent separately
77  double get_minus_log_normalization() const;
78  double get_minus_exponent() const;
79 
80  //get hessian of the minus log likelihood
81  Eigen::MatrixXd get_hessian() const;
82 
83  //get log determinant of hessian
84  double get_logdet_hessian() const;
85 
86  //call this one from python
87  FloatsList get_hessian(bool unused) const;
88 
89  public:
90  double unprotected_evaluate(IMP::DerivativeAccumulator *accum)
91  const IMP_OVERRIDE;
92  IMP::kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
94 
95  //needed to register the score state
96  void do_set_model(kernel::Model *m);
97 
98  //to allow the scorestate to get the restraint's objects
99  friend class GaussianProcessInterpolationScoreState;
100 };
101 
102 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
103 class IMPISDEXPORT GaussianProcessInterpolationScoreState : public ScoreState
104 {
105  private:
107 
108  private:
109  GaussianProcessInterpolationScoreState(
111  ScoreState(gpir->get_model(),
112  "GaussianProcessInterpolationScoreState%1%"),
113  gpir_(gpir) {}
114 
115  public:
116  //only the GPIR can create this and add it to the model
117  friend class GaussianProcessInterpolationRestraint;
118  virtual void do_before_evaluate() IMP_OVERRIDE;
119  virtual void do_after_evaluate(DerivativeAccumulator *da) IMP_OVERRIDE;
120  virtual kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
121  virtual kernel::ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE;
122  IMP_OBJECT_METHODS(GaussianProcessInterpolationScoreState);
123 };
124 #endif
125 
126 IMPISD_END_NAMESPACE
127 
128 #endif /* IMPISD_GAUSSIAN_PROCESS_INTERPOLATION_RESTRAINT_H */
Normal distribution of Function.
Class for adding derivatives from restraints to the model.
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
A nullptr-initialized pointer to an IMP Object.
A smart pointer to a ref-counted Object that is a class memeber.
Definition: base/Pointer.h:146
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
Import IMP/kernel/macros.h in the namespace.
ScoreStates maintian invariants in the Model.
Normal distribution of Function.
Abstract base class for all restraints.
A restraint is a term in an IMP ScoringFunction.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Import IMP/kernel/ScoreState.h in the namespace.
virtual void do_set_model(kernel::Model *)
virtual ModelObjectsTemp do_get_inputs() const =0
Class for storing model, its restraints, constraints, and particles.