Vespucci  1.0.0
maximum.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  Vespucci is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
22 
31 double Vespucci::Math::Quantification::FindPeakMax(const arma::vec &X, arma::uword min_index, arma::uword max_index, arma::uword &position)
32 {
33  arma::vec region = X.subvec(min_index, max_index);
34  double max = region.max();
35  arma::uvec positions = find(region == max);
36  position = min_index + positions(0);
37  return max;
38 }
39 
50 arma::vec Vespucci::Math::Quantification::FindPeakMaxMat(const arma::mat &X, arma::vec abscissa, double &min, double &max, arma::vec &positions)
51 {
52  double delta = std::abs(abscissa(1) - abscissa(0));
53  arma::uvec left_bound = find(((min-delta) <= abscissa) && (abscissa <= (min+delta)));
54  arma::uvec right_bound = find(((max-delta) <= abscissa) && (abscissa <= (max+delta)));
55 
56  arma::uword min_index = left_bound(0);
57  arma::uword max_index = right_bound(0);
58 
59  min = abscissa(min_index);
60  max = abscissa(max_index);
61 
62  arma::vec results(X.n_cols);
63  arma::uword position;
64  positions.set_size(X.n_cols);
65  for (arma::uword i = 0; i < X.n_cols; ++i){
66  results(i) = FindPeakMax(X.col(i), min_index, max_index, position);
67  positions(i) = abscissa(position);
68  }
69 
70  return results;
71 }
72 
84 arma::mat Vespucci::Math::Quantification::FindPeakMaxesMat(const arma::mat &X, arma::vec abscissa, double &first_min, double &first_max, double &second_min, double &second_max, arma::mat positions)
85 {
86  double delta = std::abs(abscissa(1) - abscissa(0));
87  arma::uvec first_left_bound = find(((first_min-delta) <= abscissa) && (abscissa <= (first_min+delta)));
88  arma::uvec first_right_bound = find(((first_max-delta) <= abscissa) && (abscissa <= (first_max+delta)));
89  arma::uvec second_left_bound = find(((second_min-delta) <= abscissa) && (abscissa <= (second_min+delta)));
90  arma::uvec second_right_bound = find(((second_max-delta) <= abscissa) && (abscissa <= (second_max+delta)));
91 
92  arma::uword first_min_index = first_left_bound(0);
93  arma::uword first_max_index = first_right_bound(0);
94  arma::uword second_min_index = second_left_bound(0);
95  arma::uword second_max_index = second_right_bound(0);
96 
97  first_min = abscissa(first_min_index);
98  first_max = abscissa(first_max_index);
99  second_min = abscissa(second_min_index);
100  second_max = abscissa(second_max_index);
101 
102  positions.set_size(X.n_cols, 2);
103  arma::mat results(X.n_cols, 2);
104  arma::uword first_position;
105  arma::uword second_position;
106  for (arma::uword i = 0; i < X.n_cols; ++i){
107  results(i, 0) = FindPeakMax(X.col(i), first_min_index, first_max_index, first_position);
108  results(i, 1) = FindPeakMax(X.col(i), second_min_index, second_max_index, second_position);
109  positions(i, 0) = abscissa(first_position);
110  positions(i, 1) = abscissa(second_position);
111  }
112 
113  return results;
114 
115 }
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
Definition: accessory.cpp:237
VESPUCCI_EXPORT arma::mat FindPeakMaxesMat(const arma::mat &X, arma::vec abscissa, double &first_min, double &first_max, double &second_min, double &second_max, arma::mat positions)
Vespucci::Math::Quantification::FindPeakMaxesMat.
Definition: maximum.cpp:84
VESPUCCI_EXPORT void position(arma::uword index, arma::uword n_rows, arma::uword n_cols, arma::uword &i, arma::uword &j)
Vespucci::Math::position Find row and column numbers for index.
Definition: accessory.cpp:469
VESPUCCI_EXPORT arma::vec FindPeakMaxMat(const arma::mat &X, arma::vec abscissa, double &min, double &max, arma::vec &positions)
Vespucci::Math::Quantification::FindPeakMaxMat.
Definition: maximum.cpp:50
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
Definition: accessory.cpp:249
VESPUCCI_EXPORT double FindPeakMax(const arma::vec &X, arma::uword min_index, arma::uword max_index, arma::uword &position)
Vespucci::Math::Quantification::FindPeakMax.
Definition: maximum.cpp:31