OpenMS
LevMarqFitter1D.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, 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: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 #include <algorithm>
14 
15 // forward decl
16 namespace Eigen
17 {
18  template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
19  class Matrix;
20  using MatrixXd = Matrix<double, -1, -1, 0, -1, -1>;
21  using VectorXd = Matrix<double, -1, 1, 0, -1, 1>;
22 } // namespace Eigen
23 
24 namespace OpenMS
25 {
26 
30  class OPENMS_DLLAPI LevMarqFitter1D : public Fitter1D
31  {
32  public:
33  typedef std::vector<double> ContainerType;
34 
36  // TODO: This is copy and paste from TraceFitter.h. Make a generic wrapper for LM optimization
38  {
39  public:
40  int inputs() const
41  {
42  return m_inputs;
43  }
44  int values() const
45  {
46  return m_values;
47  }
48 
49  GenericFunctor(int dimensions, int num_data_points) : m_inputs(dimensions), m_values(num_data_points)
50  {
51  }
52 
53  virtual ~GenericFunctor()
54  {
55  }
56 
57  virtual int operator()(const Eigen::VectorXd& x, Eigen::VectorXd& fvec) const = 0;
58 
59  // compute Jacobian matrix for the different parameters
60  virtual int df(const Eigen::VectorXd& x, Eigen::MatrixXd& J) const = 0;
61 
62  protected:
63  const int m_inputs, m_values;
64  };
65 
68  {
69  this->defaults_.setValue("max_iteration", 500, "Maximum number of iterations using by Levenberg-Marquardt algorithm.", {"advanced"});
70  }
71 
73  LevMarqFitter1D(const LevMarqFitter1D& source) : Fitter1D(source), max_iteration_(source.max_iteration_)
74  {
75  }
76 
78  ~LevMarqFitter1D() override
79  {
80  }
81 
84  {
85  if (&source == this)
86  return *this;
87 
88  Fitter1D::operator=(source);
89  max_iteration_ = source.max_iteration_;
90 
91  return *this;
92  }
93 
94  protected:
96  bool symmetric_;
99 
105  void optimize_(Eigen::VectorXd& x_init, GenericFunctor& functor) const;
106 
107  void updateMembers_() override;
108  };
109 } // namespace OpenMS
Definition: IsobaricIsotopeCorrector.h:17
Abstract base class for all 1D-dimensional model fitter.
Definition: Fitter1D.h:30
Fitter1D & operator=(const Fitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:38
virtual ~GenericFunctor()
Definition: LevMarqFitter1D.h:53
virtual int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J) const =0
int values() const
Definition: LevMarqFitter1D.h:44
GenericFunctor(int dimensions, int num_data_points)
Definition: LevMarqFitter1D.h:49
virtual int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const =0
const int m_inputs
Definition: LevMarqFitter1D.h:63
int inputs() const
Definition: LevMarqFitter1D.h:40
Abstract class for 1D-model fitter using Levenberg-Marquardt algorithm for parameter optimization.
Definition: LevMarqFitter1D.h:31
LevMarqFitter1D()
Default constructor.
Definition: LevMarqFitter1D.h:67
Int max_iteration_
Maximum number of iterations.
Definition: LevMarqFitter1D.h:98
std::vector< double > ContainerType
Definition: LevMarqFitter1D.h:33
bool symmetric_
Parameter indicates symmetric peaks.
Definition: LevMarqFitter1D.h:96
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
~LevMarqFitter1D() override
destructor
Definition: LevMarqFitter1D.h:78
LevMarqFitter1D & operator=(const LevMarqFitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:83
void optimize_(Eigen::VectorXd &x_init, GenericFunctor &functor) const
Optimize start parameter.
LevMarqFitter1D(const LevMarqFitter1D &source)
copy constructor
Definition: LevMarqFitter1D.h:73
int Int
Signed integer type.
Definition: Types.h:72
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
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19