OpenMS
OptimizePick.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Eva Lange $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 #include <OpenMS/KERNEL/Peak1D.h>
13 
14 // forward decl
15 namespace Eigen
16 {
17  template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
18  class Matrix;
19  using MatrixXd = Matrix<double, -1, -1, 0, -1, -1>;
20  using VectorXd = Matrix<double, -1, 1, 0, -1, 1>;
21 }
22 
23 #include <vector>
24 
25 namespace OpenMS
26 {
27  namespace OptimizationFunctions
28  {
30  typedef std::vector<Peak1D> RawDataVector;
32  typedef RawDataVector::iterator PeakIterator;
33 
42  struct OPENMS_DLLAPI PenaltyFactors
43  {
45  pos(0), lWidth(0), rWidth(0) {}
47  pos(p.pos), lWidth(p.lWidth), rWidth(p.rWidth) {}
49  {
50  pos = p.pos;
51  lWidth = p.lWidth;
52  rWidth = p.rWidth;
53 
54  return *this;
55  }
56 
58 
60  double pos;
62  double lWidth;
64  double rWidth;
65  };
66  }
67 
68 
75  class OPENMS_DLLAPI OptimizePick
76  {
77 public:
78 
79  struct Data
80  {
82  std::vector<double> positions;
83  std::vector<double> signal;
85  std::vector<PeakShape> peaks;
86 
88 
89  };
90 
92  {
93  public:
94  int inputs() const { return m_inputs; }
95  int values() const { return m_values; }
96 
97  OptPeakFunctor(unsigned dimensions, unsigned num_data_points, const OptimizePick::Data * data)
98  : m_inputs(dimensions), m_values(num_data_points), m_data(data) {}
99 
101  // compute Jacobian matrix for the different parameters
102  int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J);
103 
104  private:
105  const int m_inputs, m_values;
106  const Data * m_data;
107  };
108 
110  typedef std::vector<Peak1D> RawDataVector;
112  typedef RawDataVector::iterator PeakIterator;
113 
114 
117  max_iteration_(400)
118  {}
119 
122  const int max_iteration_);
123 
126 
128  inline const struct OptimizationFunctions::PenaltyFactors & getPenalties() const { return penalties_; }
130  inline struct OptimizationFunctions::PenaltyFactors & getPenalties() { return penalties_; }
132  inline void setPenalties(const struct OptimizationFunctions::PenaltyFactors & penalties) { penalties_ = penalties; }
133 
135  inline UInt getNumberIterations() const { return max_iteration_; }
137  inline unsigned int & getNumberIterations() { return max_iteration_; }
139  inline void setNumberIterations(const int max_iteration) { max_iteration_ = max_iteration; }
140 
142  void optimize(std::vector<PeakShape> & peaks, Data & data);
143 
144 
145 protected:
147  struct OptimizationFunctions::PenaltyFactors penalties_;
148 
150  unsigned int max_iteration_;
151  };
152 }
153 
Definition: OptimizePick.h:92
OptPeakFunctor(unsigned dimensions, unsigned num_data_points, const OptimizePick::Data *data)
Definition: OptimizePick.h:97
int values() const
Definition: OptimizePick.h:95
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J)
const Data * m_data
Definition: OptimizePick.h:106
const int m_inputs
Definition: OptimizePick.h:105
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec)
int inputs() const
Definition: OptimizePick.h:94
This class provides the non-linear optimization of the peak parameters.
Definition: OptimizePick.h:76
void setNumberIterations(const int max_iteration)
Mutable access to the number of iterations.
Definition: OptimizePick.h:139
void setPenalties(const struct OptimizationFunctions::PenaltyFactors &penalties)
Mutable access to the penalty factors.
Definition: OptimizePick.h:132
std::vector< Peak1D > RawDataVector
Profile data vector type.
Definition: OptimizePick.h:110
OptimizationFunctions::PenaltyFactors penalties
Definition: OptimizePick.h:87
OptimizePick()
Constructor.
Definition: OptimizePick.h:116
RawDataVector::iterator PeakIterator
Profile data iterator type.
Definition: OptimizePick.h:112
unsigned int max_iteration_
Maximum number of iterations during optimization.
Definition: OptimizePick.h:150
std::vector< double > positions
Positions and intensity values of the profile data.
Definition: OptimizePick.h:82
OptimizePick(const struct OptimizationFunctions::PenaltyFactors &penalties_, const int max_iteration_)
Constructor to set the penalty factors, the number of optimization iterations as well as the threshol...
unsigned int & getNumberIterations()
Mutable access to the number of iterations.
Definition: OptimizePick.h:137
struct OptimizationFunctions::PenaltyFactors & getPenalties()
Mutable access to the penalty factors.
Definition: OptimizePick.h:130
std::vector< PeakShape > peaks
This container contains the peak shapes to be optimized.
Definition: OptimizePick.h:85
const struct OptimizationFunctions::PenaltyFactors & getPenalties() const
Non-mutable access to the penalty factors.
Definition: OptimizePick.h:128
~OptimizePick()
Destructor.
void optimize(std::vector< PeakShape > &peaks, Data &data)
Start the optimization of the peak shapes peaks. The original peak shapes will be substituted by the ...
UInt getNumberIterations() const
Non-mutable access to the number of iterations.
Definition: OptimizePick.h:135
std::vector< double > signal
Definition: OptimizePick.h:83
Definition: OptimizePick.h:80
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
Definition: IsobaricIsotopeCorrector.h:15
Matrix< double, -1, -1, 0, -1, -1 > MatrixXd
Definition: IsobaricIsotopeCorrector.h:18
Matrix< double, -1, 1, 0, -1, 1 > VectorXd
Definition: IsobaricIsotopeCorrector.h:19
Definition: IsobaricIsotopeCorrector.h:17
std::vector< Peak1D > RawDataVector
Profile data vector type.
Definition: OptimizePick.h:30
RawDataVector::iterator PeakIterator
Profile data iterator type.
Definition: OptimizePick.h:32
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Class for the penalty factors used during the optimization.
Definition: OptimizePick.h:43
double rWidth
Penalty factor for the peak shape's right width parameter.
Definition: OptimizePick.h:64
double pos
Penalty factor for the peak shape's position.
Definition: OptimizePick.h:60
PenaltyFactors()
Definition: OptimizePick.h:44
double lWidth
Penalty factor for the peak shape's left width parameter.
Definition: OptimizePick.h:62
PenaltyFactors & operator=(const PenaltyFactors &p)
Definition: OptimizePick.h:48
PenaltyFactors(const PenaltyFactors &p)
Definition: OptimizePick.h:46
~PenaltyFactors()
Definition: OptimizePick.h:57