OpenMS  2.7.0
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-2021.
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 
38 
39 #include <unsupported/Eigen/NonLinearOptimization>
40 
41 #include <algorithm>
42 
44 
45 namespace OpenMS
46 {
47 
51  class OPENMS_DLLAPI LevMarqFitter1D :
52  public Fitter1D
53  {
54 
55 public:
56 
57  typedef std::vector<double> ContainerType;
58 
60  //TODO: This is copy and paste from TraceFitter.h. Make a generic wrapper for LM optimization
62  {
63  public:
64  int inputs() const { return m_inputs; }
65  int values() const { return m_values; }
66 
67  GenericFunctor(int dimensions, int num_data_points)
68  : m_inputs(dimensions), m_values(num_data_points) {}
69 
70  virtual ~GenericFunctor() {}
71 
72  virtual int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const = 0;
73 
74  // compute Jacobian matrix for the different parameters
75  virtual int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J) const = 0;
76 
77  protected:
78  const int m_inputs, m_values;
79  };
80 
83  Fitter1D()
84  {
85  this->defaults_.setValue("max_iteration", 500, "Maximum number of iterations using by Levenberg-Marquardt algorithm.", {"advanced"});
86  }
87 
89  LevMarqFitter1D(const LevMarqFitter1D & source) :
90  Fitter1D(source),
91  max_iteration_(source.max_iteration_)
92  {
93  }
94 
96  ~LevMarqFitter1D() override
97  {
98  }
99 
101  virtual LevMarqFitter1D & operator=(const LevMarqFitter1D & source)
102  {
103  if (&source == this) return *this;
104 
105  Fitter1D::operator=(source);
106  max_iteration_ = source.max_iteration_;
107 
108  return *this;
109  }
110 
111 protected:
112 
117 
123  void optimize_(Eigen::VectorXd& x_init, GenericFunctor& functor);
124 
125  void updateMembers_() override;
126 
127  };
128 }
129 
Abstract base class for all 1D-dimensional model fitter.
Definition: Fitter1D.h:62
virtual Fitter1D & operator=(const Fitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:62
virtual ~GenericFunctor()
Definition: LevMarqFitter1D.h:70
virtual int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J) const =0
int values() const
Definition: LevMarqFitter1D.h:65
GenericFunctor(int dimensions, int num_data_points)
Definition: LevMarqFitter1D.h:67
virtual int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const =0
const int m_inputs
Definition: LevMarqFitter1D.h:78
int inputs() const
Definition: LevMarqFitter1D.h:64
Abstract class for 1D-model fitter using Levenberg-Marquardt algorithm for parameter optimization.
Definition: LevMarqFitter1D.h:53
LevMarqFitter1D()
Default constructor.
Definition: LevMarqFitter1D.h:82
void optimize_(Eigen::VectorXd &x_init, GenericFunctor &functor)
Optimize start parameter.
Int max_iteration_
Maximum number of iterations.
Definition: LevMarqFitter1D.h:116
std::vector< double > ContainerType
Definition: LevMarqFitter1D.h:57
bool symmetric_
Parameter indicates symmetric peaks.
Definition: LevMarqFitter1D.h:114
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:96
virtual LevMarqFitter1D & operator=(const LevMarqFitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:101
LevMarqFitter1D(const LevMarqFitter1D &source)
copy constructor
Definition: LevMarqFitter1D.h:89
int Int
Signed integer type.
Definition: Types.h:102
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47