IMP  2.2.1
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-2014 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 
16 IMPISD_BEGIN_NAMESPACE
17 
18 //! Add nuisance parameter to particle
19 /** The value of the nuisance parameter may express data
20  or theory uncertainty. It can be initialized with or without
21  specifying its value. Default is 1. On construction, the Nuisance is
22  unbounded. It can be bounded with set_upper and set_lower. Setting it
23  to values outside of bounds results in setting it to the bound value.
24  */
25 class IMPISDEXPORT Nuisance : public Decorator {
26  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
27  double nuisance = 1.0);
28 
29  public:
32  IMP_DECORATOR_SETUP_1(Nuisance, double, nuisance);
33 
34  static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi) {
35  return m->get_has_attribute(get_nuisance_key(), pi);
36  }
37 
38  static FloatKey get_nuisance_key();
39  Float get_nuisance() const {
40  return get_particle()->get_value(get_nuisance_key());
41  }
42  void set_nuisance(Float d);
43 
44  /** set upper and lower bound of nuisance by specifying
45  * either a float or another nuisance. Both can be set at the same
46  * time in which case the upper bound is the minimum of the two values.
47  * This constraint is enforced with the help of a ScoreState that will be
48  * created on-the-fly.
49  */
50  bool get_has_lower() const;
51  Float get_lower() const;
52  static FloatKey get_lower_key();
53  static kernel::ParticleIndexKey get_lower_particle_key();
54  void set_lower(Float d);
55  void set_lower(kernel::Particle *d);
56  void remove_lower();
57 
58  bool get_has_upper() const;
59  Float get_upper() const;
60  static FloatKey get_upper_key();
61  static kernel::ParticleIndexKey get_upper_particle_key();
62  void set_upper(Float d);
63  void set_upper(kernel::Particle *d);
64  void remove_upper();
65 
66  Float get_nuisance_derivative() const {
67  return get_particle()->get_derivative(get_nuisance_key());
68  }
69 
70  void add_to_nuisance_derivative(Float d, DerivativeAccumulator &accum) {
71  get_particle()->add_to_derivative(get_nuisance_key(), d, accum);
72  }
73 
74  bool get_nuisance_is_optimized() const {
75  return get_particle()->get_is_optimized(get_nuisance_key());
76  }
77 
78  void set_nuisance_is_optimized(bool val) {
79  get_particle()->set_is_optimized(get_nuisance_key(), val);
80  }
81 
82  friend class NuisanceScoreState;
83 
84  private:
85  // scorestate-related bookkeeping
86  static ObjectKey get_ss_key();
87  void enforce_bounds();
88  void remove_bounds();
89 };
90 
91 IMP_DECORATORS(Nuisance, Nuisances, kernel::ParticlesTemp);
92 
93 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
94 class IMPISDEXPORT NuisanceScoreState : public ScoreState {
95  private:
97 
98  private:
99  NuisanceScoreState(kernel::Particle *p)
100  : ScoreState(p->get_model(), "NuisanceScoreState%1%"), p_(p) {}
101 
102  public:
103  friend class Nuisance;
104  virtual void do_before_evaluate() IMP_OVERRIDE;
105  virtual void do_after_evaluate(DerivativeAccumulator *da) IMP_OVERRIDE;
106  virtual kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
107  virtual kernel::ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE;
108  IMP_OBJECT_METHODS(NuisanceScoreState);
109 };
110 #endif
111 
112 IMPISD_END_NAMESPACE
113 
114 #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)
#define IMP_DECORATOR_SETUP_0(Name)
Add nuisance parameter to particle.
Definition: Nuisance.h:25
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
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.
Definition: kernel/Model.h:72