| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/Fitter1D.h>
38
39 #include <unsupported/Eigen/NonLinearOptimization>
40
41 #include <algorithm>
42
43 #include <OpenMS/DATASTRUCTURES/ListUtils.h>
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
61 class GenericFunctor
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) = 0;
73
74 // compute Jacobian matrix for the different parameters
75 virtual int df(const Eigen::VectorXd &x, Eigen::MatrixXd &J) = 0;
76
77 protected:
78 const int m_inputs, m_values;
79 };
80
82 LevMarqFitter1D() :
83 Fitter1D()
84 {
85 this->defaults_.setValue("max_iteration", 500, "Maximum number of iterations using by Levenberg-Marquardt algorithm.", ListUtils::create<String>("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
114 bool symmetric_;
116 Int max_iteration_;
117
123 void optimize_(Eigen::VectorXd& x_init, GenericFunctor& functor);
124
125 void updateMembers_() override;
126
127 };
128 }
129
OpenMS::LevMarqFitter1D::GenericFunctor::~GenericFunctor
virtual ~GenericFunctor()
Definition: LevMarqFitter1D.h:70
OpenMS::LevMarqFitter1D::operator=
virtual LevMarqFitter1D & operator=(const LevMarqFitter1D &source)
assignment operator
Definition: LevMarqFitter1D.h:101
Fitter1D.h
OpenMS::LevMarqFitter1D::GenericFunctor::inputs
int inputs() const
Definition: LevMarqFitter1D.h:64
OpenMS::LevMarqFitter1D::LevMarqFitter1D
LevMarqFitter1D()
Default constructor.
Definition: LevMarqFitter1D.h:82
OpenMS::Fitter1D
Abstract base class for all 1D-dimensional model fitter.
Definition: Fitter1D.h:58
OpenMS::LevMarqFitter1D
Abstract class for 1D-model fitter using Levenberg-Marquardt algorithm for parameter optimization...
Definition: LevMarqFitter1D.h:51
OpenMS::LevMarqFitter1D::symmetric_
bool symmetric_
Parameter indicates symmetric peaks.
Definition: LevMarqFitter1D.h:114
OpenMS::LevMarqFitter1D::max_iteration_
Int max_iteration_
Maximum number of iterations.
Definition: LevMarqFitter1D.h:116
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::LevMarqFitter1D::GenericFunctor
Definition: LevMarqFitter1D.h:61
OpenMS::LevMarqFitter1D::~LevMarqFitter1D
~LevMarqFitter1D() override
destructor
Definition: LevMarqFitter1D.h:96
int
OpenMS::LevMarqFitter1D::GenericFunctor::m_values
const int m_values
Definition: LevMarqFitter1D.h:78
OpenMS::Fitter1D::operator=
virtual Fitter1D & operator=(const Fitter1D &source)
assignment operator
OpenMS::LevMarqFitter1D::GenericFunctor::values
int values() const
Definition: LevMarqFitter1D.h:65
ListUtils.h
OpenMS::LevMarqFitter1D::ContainerType
std::vector< double > ContainerType
Definition: LevMarqFitter1D.h:57
OpenMS::LevMarqFitter1D::GenericFunctor::GenericFunctor
GenericFunctor(int dimensions, int num_data_points)
Definition: LevMarqFitter1D.h:67
OpenMS::LevMarqFitter1D::LevMarqFitter1D
LevMarqFitter1D(const LevMarqFitter1D &source)
copy constructor
Definition: LevMarqFitter1D.h:89