OpenMS
LevMarqFitter1D.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <algorithm>
40 
41 // forward decl
42 namespace Eigen
43 {
44  template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
45  class Matrix;
46  using MatrixXd = Matrix<double, -1, -1, 0, -1, -1>;
47  using VectorXd = Matrix<double, -1, 1, 0, -1, 1>;
48 } // namespace Eigen
49 
50 namespace OpenMS
51 {
52 
56  class OPENMS_DLLAPI LevMarqFitter1D : public Fitter1D
57  {
58  public:
59  typedef std::vector<double> ContainerType;
60 
62  // TODO: This is copy and paste from TraceFitter.h. Make a generic wrapper for LM optimization
64  {
65  public:
66  int inputs() const
67  {
68  return m_inputs;
69  }
70  int values() const
71  {
72  return m_values;
73  }
74 
75  GenericFunctor(int dimensions, int num_data_points) : m_inputs(dimensions), m_values(num_data_points)
76  {
77  }
78 
79  virtual ~GenericFunctor()
80  {
81  }
82 
83  virtual int operator()(const Eigen::VectorXd& x, Eigen::VectorXd& fvec) const = 0;
84 
85  // compute Jacobian matrix for the different parameters
86  virtual int df(const Eigen::VectorXd& x, Eigen::MatrixXd& J) const = 0;
87 
88  protected:
89  const int m_inputs, m_values;
90  };
91 
94  {
95  this->defaults_.setValue("max_iteration", 500, "Maximum number of iterations using by Levenberg-Marquardt algorithm.", {"advanced"});
96  }
97 
99  LevMarqFitter1D(const LevMarqFitter1D& source) : Fitter1D(source), max_iteration_(source.max_iteration_)
100  {
101  }
102 
104  ~LevMarqFitter1D() override
105  {
106  }
107 
110  {
111  if (&source == this)
112  return *this;
113 
114  Fitter1D::operator=(source);
115  max_iteration_ = source.max_iteration_;
116 
117  return *this;
118  }
119 
120  protected:
125 
131  void optimize_(Eigen::VectorXd& x_init, GenericFunctor& functor) const;
132 
133  void updateMembers_() override;
134  };
135 } // namespace OpenMS
Abstract base class for all 1D-dimensional model fitter.
Definition: Fitter1D.h:60
Fitter1D & operator=(const Fitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:64
virtual ~GenericFunctor()
Definition: LevMarqFitter1D.h:79
virtual int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J) const =0
int values() const
Definition: LevMarqFitter1D.h:70
GenericFunctor(int dimensions, int num_data_points)
Definition: LevMarqFitter1D.h:75
virtual int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const =0
const int m_inputs
Definition: LevMarqFitter1D.h:89
int inputs() const
Definition: LevMarqFitter1D.h:66
Abstract class for 1D-model fitter using Levenberg-Marquardt algorithm for parameter optimization.
Definition: LevMarqFitter1D.h:57
LevMarqFitter1D()
Default constructor.
Definition: LevMarqFitter1D.h:93
Int max_iteration_
Maximum number of iterations.
Definition: LevMarqFitter1D.h:124
std::vector< double > ContainerType
Definition: LevMarqFitter1D.h:59
bool symmetric_
Parameter indicates symmetric peaks.
Definition: LevMarqFitter1D.h:122
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:104
LevMarqFitter1D & operator=(const LevMarqFitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:109
void optimize_(Eigen::VectorXd &x_init, GenericFunctor &functor) const
Optimize start parameter.
LevMarqFitter1D(const LevMarqFitter1D &source)
copy constructor
Definition: LevMarqFitter1D.h:99
int Int
Signed integer type.
Definition: Types.h:102
Definition: IsobaricIsotopeCorrector.h:41
Matrix< double, -1, -1, 0, -1, -1 > MatrixXd
Definition: IsobaricIsotopeCorrector.h:44
Matrix< double, -1, 1, 0, -1, 1 > VectorXd
Definition: IsobaricIsotopeCorrector.h:45
Definition: IsobaricIsotopeCorrector.h:43
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48