| OpenMS 2.5.0

EmgGradientDescent.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: Douglas McCloskey, Pasquale Domenico Colaianni $
32 // $Authors: Douglas McCloskey, Pasquale Domenico Colaianni $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/config.h> // OPENMS_DLLAPI
38 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
39 #include <OpenMS/KERNEL/MSChromatogram.h>
40 #include <OpenMS/KERNEL/MSSpectrum.h>
41
42 namespace OpenMS
43 {
64 class OPENMS_DLLAPI EmgGradientDescent :
65 public DefaultParamHandler
66 {
67 public:
69 EmgGradientDescent();
71 ~EmgGradientDescent() = default;
72
73 void getDefaultParameters(Param& params);
74
76 friend class EmgGradientDescent_friend;
77
111 template <typename PeakContainerT>
112 void fitEMGPeakModel(
113 const PeakContainerT& input_peak,
114 PeakContainerT& output_peak,
115 const double left_pos = 0.0,
116 const double right_pos = 0.0
117 ) const;
118
131 UInt estimateEmgParameters(
132 const std::vector<double>& xs,
133 const std::vector<double>& ys,
134 double& best_h,
135 double& best_mu,
136 double& best_sigma,
137 double& best_tau
138 ) const;
139
154 void applyEstimatedParameters(
155 const std::vector<double>& xs,
156 const double h,
157 const double mu,
158 const double sigma,
159 const double tau,
160 std::vector<double>& out_xs,
161 std::vector<double>& out_ys
162 ) const;
163
164 protected:
165 void updateMembers_() override;
166
189 void extractTrainingSet(
190 const std::vector<double>& xs,
191 const std::vector<double>& ys,
192 std::vector<double>& TrX,
193 std::vector<double>& TrY
194 ) const;
195
208 double computeMuMaxDistance(const std::vector<double>& xs) const;
209
223 double computeInitialMean(
224 const std::vector<double>& xs,
225 const std::vector<double>& ys
226 ) const;
227
228 private:
246 void iRpropPlus(
247 const double prev_diff_E_param,
248 double& diff_E_param,
249 double& param_lr,
250 double& param_update,
251 double& param,
252 const double current_E,
253 const double previous_E
254 ) const;
255
271 double Loss_function(
272 const std::vector<double>& xs,
273 const std::vector<double>& ys,
274 const double h,
275 const double mu,
276 const double sigma,
277 const double tau
278 ) const;
279
295 double E_wrt_h(
296 const std::vector<double>& xs,
297 const std::vector<double>& ys,
298 const double h,
299 const double mu,
300 const double sigma,
301 const double tau
302 ) const;
303
319 double E_wrt_mu(
320 const std::vector<double>& xs,
321 const std::vector<double>& ys,
322 const double h,
323 const double mu,
324 const double sigma,
325 const double tau
326 ) const;
327
343 double E_wrt_sigma(
344 const std::vector<double>& xs,
345 const std::vector<double>& ys,
346 const double h,
347 const double mu,
348 const double sigma,
349 const double tau
350 ) const;
351
367 double E_wrt_tau(
368 const std::vector<double>& xs,
369 const std::vector<double>& ys,
370 const double h,
371 const double mu,
372 const double sigma,
373 const double tau
374 ) const;
375
396 double compute_z(
397 const double x,
398 const double mu,
399 const double sigma,
400 const double tau
401 ) const;
402
414 double emg_point(
415 const double x,
416 const double h,
417 const double mu,
418 const double sigma,
419 const double tau
420 ) const;
421
423 const double PI = OpenMS::Constants::PI;
424
430 UInt print_debug_;
431
433 UInt max_gd_iter_;
434
439 bool compute_additional_points_;
440 };
441
442 class EmgGradientDescent_friend
443 {
444 public:
445 EmgGradientDescent_friend() = default;
446 ~EmgGradientDescent_friend() = default;
447
448 double Loss_function(
449 const std::vector<double>& xs,
450 const std::vector<double>& ys,
451 const double h,
452 const double mu,
453 const double sigma,
454 const double tau
455 ) const
456 {
457 return emg_gd_.Loss_function(xs, ys, h, mu, sigma, tau);
458 }
459
460 double computeMuMaxDistance(const std::vector<double>& xs) const
461 {
462 return emg_gd_.computeMuMaxDistance(xs);
463 }
464
465 void extractTrainingSet(
466 const std::vector<double>& xs,
467 const std::vector<double>& ys,
468 std::vector<double>& TrX,
469 std::vector<double>& TrY
470 ) const
471 {
472 emg_gd_.extractTrainingSet(xs, ys, TrX, TrY);
473 }
474
475 double computeInitialMean(
476 const std::vector<double>& xs,
477 const std::vector<double>& ys
478 ) const
479 {
480 return emg_gd_.computeInitialMean(xs, ys);
481 }
482
483 void iRpropPlus(
484 const double prev_diff_E_param,
485 double& diff_E_param,
486 double& param_lr,
487 double& param_update,
488 double& param,
489 const double current_E,
490 const double previous_E
491 ) const
492 {
493 emg_gd_.iRpropPlus(
494 prev_diff_E_param, diff_E_param, param_lr,
495 param_update, param, current_E, previous_E
496 );
497 }
498
499 double compute_z(
500 const double x,
501 const double mu,
502 const double sigma,
503 const double tau
504 ) const
505 {
506 return emg_gd_.compute_z(x, mu, sigma, tau);
507 }
508
509 void applyEstimatedParameters(
510 const std::vector<double>& xs,
511 const double h,
512 const double mu,
513 const double sigma,
514 const double tau,
515 std::vector<double>& out_xs,
516 std::vector<double>& out_ys
517 ) const
518 {
519 emg_gd_.applyEstimatedParameters(xs, h, mu, sigma, tau, out_xs, out_ys);
520 }
521
522 double emg_point(
523 const double x,
524 const double h,
525 const double mu,
526 const double sigma,
527 const double tau
528 ) const
529 {
530 return emg_gd_.emg_point(x, h, mu, sigma, tau);
531 }
532
533 EmgGradientDescent emg_gd_;
534 };
535 }
OpenMS::EmgGradientDescent_friend::applyEstimatedParameters
void applyEstimatedParameters(const std::vector< double > &xs, const double h, const double mu, const double sigma, const double tau, std::vector< double > &out_xs, std::vector< double > &out_ys) const
Definition: EmgGradientDescent.h:509
OpenMS::EmgGradientDescent_friend::Loss_function
double Loss_function(const std::vector< double > &xs, const std::vector< double > &ys, const double h, const double mu, const double sigma, const double tau) const
Definition: EmgGradientDescent.h:448
OpenMS::EmgGradientDescent_friend::emg_point
double emg_point(const double x, const double h, const double mu, const double sigma, const double tau) const
Definition: EmgGradientDescent.h:522
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::EmgGradientDescent::Loss_function
double Loss_function(const std::vector< double > &xs, const std::vector< double > &ys, const double h, const double mu, const double sigma, const double tau) const
Compute the cost given by loss function E.
OpenMS::EmgGradientDescent::max_gd_iter_
UInt max_gd_iter_
Maximum number of gradient descent iterations in `fitEMGPeakModel()`.
Definition: EmgGradientDescent.h:433
OpenMS::EmgGradientDescent::print_debug_
UInt print_debug_
Definition: EmgGradientDescent.h:430
OpenMS::EmgGradientDescent
Compute the area, background and shape metrics of a peak.
Definition: EmgGradientDescent.h:64
OpenMS::EmgGradientDescent_friend::compute_z
double compute_z(const double x, const double mu, const double sigma, const double tau) const
Definition: EmgGradientDescent.h:499
OpenMS::EmgGradientDescent::extractTrainingSet
void extractTrainingSet(const std::vector< double > &xs, const std::vector< double > &ys, std::vector< double > &TrX, std::vector< double > &TrY) const
Given a peak, extract a training set to be used with the gradient descent algorithm.
OpenMS::Constants::PI
const double PI
PI.
OpenMS::EmgGradientDescent::iRpropPlus
void iRpropPlus(const double prev_diff_E_param, double &diff_E_param, double &param_lr, double &param_update, double &param, const double current_E, const double previous_E) const
Apply the iRprop+ algorithm for gradient descent.
OpenMS::EmgGradientDescent::applyEstimatedParameters
void applyEstimatedParameters(const std::vector< double > &xs, const double h, const double mu, const double sigma, const double tau, std::vector< double > &out_xs, std::vector< double > &out_ys) const
Compute the EMG function on a set of points.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::EmgGradientDescent::computeInitialMean
double computeInitialMean(const std::vector< double > &xs, const std::vector< double > &ys) const
Compute an estimation of the mean of a peak.
OpenMS::EmgGradientDescent_friend::emg_gd_
EmgGradientDescent emg_gd_
Definition: EmgGradientDescent.h:533
OpenMS::EmgGradientDescent::compute_additional_points_
bool compute_additional_points_
Definition: EmgGradientDescent.h:439
OpenMS::EmgGradientDescent::emg_point
double emg_point(const double x, const double h, const double mu, const double sigma, const double tau) const
Compute the EMG function on a single point.
DefaultParamHandler.h
OpenMS::EmgGradientDescent::compute_z
double compute_z(const double x, const double mu, const double sigma, const double tau) const
Compute EMG&#39;s z parameter.
MSSpectrum.h
OpenMS::EmgGradientDescent_friend::~EmgGradientDescent_friend
~EmgGradientDescent_friend()=default
OpenMS::EmgGradientDescent_friend::EmgGradientDescent_friend
EmgGradientDescent_friend()=default
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::EmgGradientDescent_friend
Definition: EmgGradientDescent.h:442
OpenMS::EmgGradientDescent_friend::extractTrainingSet
void extractTrainingSet(const std::vector< double > &xs, const std::vector< double > &ys, std::vector< double > &TrX, std::vector< double > &TrY) const
Definition: EmgGradientDescent.h:465
OpenMS::EmgGradientDescent_friend::iRpropPlus
void iRpropPlus(const double prev_diff_E_param, double &diff_E_param, double &param_lr, double &param_update, double &param, const double current_E, const double previous_E) const
Definition: EmgGradientDescent.h:483
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:73
OpenMS::EmgGradientDescent_friend::computeInitialMean
double computeInitialMean(const std::vector< double > &xs, const std::vector< double > &ys) const
Definition: EmgGradientDescent.h:475
MSChromatogram.h
OpenMS::EmgGradientDescent::computeMuMaxDistance
double computeMuMaxDistance(const std::vector< double > &xs) const
Compute the boundary for the mean (`mu`) parameter in gradient descent.
OpenMS::EmgGradientDescent_friend::computeMuMaxDistance
double computeMuMaxDistance(const std::vector< double > &xs) const
Definition: EmgGradientDescent.h:460
OpenMS::Constants::h
const double h