npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
SmoothedEMUnfoldND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_SMOOTHEDEMUNFOLDND_HH_
2 #define NPSTAT_SMOOTHEDEMUNFOLDND_HH_
3 
4 /*!
5 // \file SmoothedEMUnfoldND.hh
6 //
7 // \brief Multivariate expectation-maximization unfolding with smoothing
8 //
9 // Author: I. Volobouev
10 //
11 // June 2014
12 */
13 
15 
16 namespace npstat {
18  {
19  public:
20  typedef AbsUnfoldND Base;
21 
22  /**
23  // The constructor arguments are:
24  //
25  // responseMatrix -- Naturally, the problem response matrix.
26  //
27  // filter -- The filter to use for smoothing the
28  // unfolded values. This object will not
29  // make a copy of the filter. It is the
30  // responsibility of the caller to ensure
31  // that the argument filter exists while
32  // this object is in use.
33  //
34  // useConvolutions -- If "true", the code will call the
35  // "convolve" method of the filter rather
36  // than its "filter" method.
37  //
38  // useMultinomialCovariance -- Specifies whether we should use
39  // multinomial distribution to estimate
40  // covariance of fitted observations
41  // (otherwise Poisson assumption is used).
42  //
43  // smoothLastIter -- If "false", smoothing will not be
44  // applied after the last iteration.
45  // Setting this parameter to "false" is
46  // not recommended for production results
47  // because it is unclear how to compare
48  // such results with models.
49  //
50  // convergenceEpsilon -- Convergence criterion parameter for
51  // various iterations.
52  //
53  // maxIterations -- Maximum number of iterations allowed
54  // (both for the expectation-maximization
55  // iterations and for the code estimating
56  // the error propagation matrix).
57  */
58  SmoothedEMUnfoldND(const ResponseMatrix& responseMatrix,
59  const AbsUnfoldingFilterND& filter,
60  bool useConvolutions,
61  bool useMultinomialCovariance = false,
62  bool smoothLastIter = true,
63  double convergenceEpsilon = 1.0e-10,
64  unsigned maxIterations = 100000U);
65 
66  inline virtual ~SmoothedEMUnfoldND() {}
67 
68  /** Change maximum number of allowed iterations */
69  inline void setMaxIterations(const unsigned u) {maxIterations_ = u;}
70 
71  /** Switch between multinomial/Poisson covariance for observed space */
72  inline void useMultinomialCovariance(const bool b)
73  {useMultinomialCovariance_ = b;}
74 
75  /** Switch between smoothing/not smoothing the last iteration */
76  inline void smoothLastIteration(const bool b) {smoothLast_ = b;}
77 
78  /** Change the convergence criterion */
79  void setConvergenceEpsilon(double eps);
80 
81  //@{
82  /** Simple inspector of object properties */
83  inline double convergenceEpsilon() const {return convergenceEpsilon_;}
84  inline unsigned maxIterations() const {return maxIterations_;}
85  inline bool usingMultinomialCovariance() const
86  {return useMultinomialCovariance_;}
87  inline bool smoothingLastIteration() const {return smoothLast_;}
88  //@}
89 
90  /**
91  // Returns the last number of iterations used to calculate the unfolded
92  // results. This number will be filled after each "unfold" call.
93  */
94  inline unsigned lastNIterations() const {return lastIterations_;}
95 
96  /**
97  // The last number of iterations used to calculate the error
98  // propagation matrix
99  */
100  inline unsigned lastEPIterations() const {return lastEPIterations_;}
101 
102  /** The normalization factor applied during the last smoothing step */
103  inline double lastSmoothingNormfactor() const {return lastNormfactor_;}
104 
105  /** The main unfolding method */
106  virtual bool unfold(const ArrayND<double>& observed,
107  const Matrix<double>* observationCovarianceMatrix,
108  ArrayND<double>* unfolded,
109  Matrix<double>* unfoldedCovarianceMatrix);
110  protected:
111  /** Single expectation-maximization (a.k.a. D'Agostini) iteration */
112  void update(const ArrayND<double>& observed,
113  const ArrayND<double>* prev, ArrayND<double>* next,
114  bool performSmoothing) const;
115 
116  private:
117  // Error propagation matrix for expectation-maximization iterations
118  Matrix<double> errorPropagationMatrix(
119  const double* observed, unsigned lenObserved,
120  const double* unfolded, unsigned lenUnfolded,
121  const double* yHat, double norm, bool smoothLast, unsigned maxiter,
122  double convergenceEps, unsigned* itersMade, bool* converged) const;
123 
124  double convergenceEpsilon_;
125  mutable double lastNormfactor_;
126  unsigned maxIterations_;
127  unsigned lastIterations_;
128  unsigned lastEPIterations_;
129  bool useMultinomialCovariance_;
130  bool smoothLast_;
131 
132  // Memory buffers
133  ArrayND<double> v1_, v2_;
134  mutable ArrayND<double> yhatBuf_, unfoldedBuf_;
135  };
136 }
137 
138 #endif // NPSTAT_SMOOTHEDEMUNFOLDND_HH_
Interface definition for multivariate unfolding algorithms.
Definition: AbsUnfoldND.hh:19
virtual void useConvolutions(const bool b)
Definition: AbsUnfoldND.hh:57
Definition: AbsUnfoldingFilterND.hh:28
Definition: ResponseMatrix.hh:23
Definition: SmoothedEMUnfoldND.hh:18
double lastSmoothingNormfactor() const
Definition: SmoothedEMUnfoldND.hh:103
void setConvergenceEpsilon(double eps)
unsigned lastEPIterations() const
Definition: SmoothedEMUnfoldND.hh:100
void smoothLastIteration(const bool b)
Definition: SmoothedEMUnfoldND.hh:76
void useMultinomialCovariance(const bool b)
Definition: SmoothedEMUnfoldND.hh:72
virtual bool unfold(const ArrayND< double > &observed, const Matrix< double > *observationCovarianceMatrix, ArrayND< double > *unfolded, Matrix< double > *unfoldedCovarianceMatrix)
double convergenceEpsilon() const
Definition: SmoothedEMUnfoldND.hh:83
void update(const ArrayND< double > &observed, const ArrayND< double > *prev, ArrayND< double > *next, bool performSmoothing) const
void setMaxIterations(const unsigned u)
Definition: SmoothedEMUnfoldND.hh:69
unsigned lastNIterations() const
Definition: SmoothedEMUnfoldND.hh:94
SmoothedEMUnfoldND(const ResponseMatrix &responseMatrix, const AbsUnfoldingFilterND &filter, bool useConvolutions, bool useMultinomialCovariance=false, bool smoothLastIter=true, double convergenceEpsilon=1.0e-10, unsigned maxIterations=100000U)
Definition: AbsArrayProjector.hh:14