IMP  2.1.0
The Integrative Modeling Platform
Nuisance.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/Nuisance.h
3  * \brief A decorator for nuisance parameters particles
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPISD_NUISANCE_H
9 #define IMPISD_NUISANCE_H
10 
11 #include "isd_config.h"
12 
13 #include <IMP/Decorator.h>
14 #include <IMP/decorator_macros.h>
15 #include <IMP/score_state_macros.h>
16 
17 IMPISD_BEGIN_NAMESPACE
18 
19 //! Add nuisance parameter to particle
20 /** The value of the nuisance parameter may express data
21  or theory uncertainty. It can be initialized with or without
22  specifying its value. Default is 1. On construction, the Nuisance is
23  unbounded. It can be bounded with set_upper and set_lower. Setting it
24  to values outside of bounds results in setting it to the bound value.
25  */
26 class IMPISDEXPORT Nuisance: public Decorator
27 {
28  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
29  double nuisance=1.0);
30 
31 public:
34  IMP_DECORATOR_SETUP_1(Nuisance, double, nuisance);
35 
37  return m->get_has_attribute(get_nuisance_key(), pi);
38  }
39 
40  static FloatKey get_nuisance_key();
41  Float get_nuisance() const {
42  return get_particle()->get_value(get_nuisance_key());
43  }
44  void set_nuisance(Float d);
45 
46  /** set upper and lower bound of nuisance by specifying
47  * either a float or another nuisance. Both can be set at the same
48  * time in which case the upper bound is the minimum of the two values.
49  * This constraint is enforced with the help of a ScoreState that will be
50  * created on-the-fly.
51  */
52  bool get_has_lower() const;
53  Float get_lower() const;
54  static FloatKey get_lower_key();
55  static kernel::ParticleIndexKey get_lower_particle_key();
56  void set_lower(Float d);
57  void set_lower(kernel::Particle * d);
58  void remove_lower();
59 
60  bool get_has_upper() const;
61  Float get_upper() const;
62  static FloatKey get_upper_key();
63  static kernel::ParticleIndexKey get_upper_particle_key();
64  void set_upper(Float d);
65  void set_upper(kernel::Particle * d);
66  void remove_upper();
67 
68  Float get_nuisance_derivative() const {
69  return get_particle()->get_derivative(get_nuisance_key());
70  }
71 
72  void add_to_nuisance_derivative(Float d, DerivativeAccumulator &accum) {
73  get_particle()->add_to_derivative(get_nuisance_key(), d, accum);
74  }
75 
76  bool get_nuisance_is_optimized() const {
77  return get_particle()->get_is_optimized(get_nuisance_key());
78  }
79 
80  void set_nuisance_is_optimized(bool val) {
81  get_particle()->set_is_optimized(get_nuisance_key(), val);
82  }
83 
84  friend class NuisanceScoreState;
85 
86 private:
87  //scorestate-related bookkeeping
88  static ObjectKey get_ss_key();
89  void enforce_bounds();
90  void remove_bounds();
91 
92 };
93 
94 IMP_DECORATORS(Nuisance, Nuisances, kernel::ParticlesTemp);
95 
96 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
97 class IMPISDEXPORT NuisanceScoreState : public ScoreState
98 {
99  private:
101 
102  private:
103  NuisanceScoreState(kernel::Particle *p) :
104  ScoreState(p->get_model(), "NuisanceScoreState%1%"), p_(p) {}
105 
106  public:
107  friend class Nuisance;
108  virtual void do_before_evaluate() IMP_OVERRIDE;
109  virtual void do_after_evaluate(DerivativeAccumulator *da) IMP_OVERRIDE;
110  virtual kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
111  virtual kernel::ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE;
112  IMP_OBJECT_METHODS(NuisanceScoreState);
113 };
114 #endif
115 
116 
117 IMPISD_END_NAMESPACE
118 
119 #endif /* IMPISD_NUISANCE_H */
Import IMP/kernel/Decorator.h in the namespace.
IMP::kernel::ScoreState ScoreState
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
Particle * get_particle() const
IMP::kernel::DerivativeAccumulator DerivativeAccumulator
#define IMP_DECORATOR_METHODS(Name, Parent)
static bool get_is_setup(Particle *p)
Return true if the particle can be cast to the decorator.
#define IMP_DECORATOR_SETUP_0(Name)
Add nuisance parameter to particle.
Definition: Nuisance.h:26
Import IMP/kernel/decorator_macros.h in the namespace.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Class to handle individual model particles.
Key< 4, true > ObjectKey
The type used to identify an Object attribute.
IMP::kernel::Particle Particle
Import IMP/kernel/score_state_macros.h in the namespace.
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Class for storing model, its restraints, constraints, and particles.