34 arma::vec region = X.subvec(min_index, max_index);
35 arma::uword size = region.n_elem;
36 double maximum, half_maximum;
37 double start_value, end_value;
38 midline.set_size(size);
40 arma::uword left_index = 0;
41 arma::uword right_index = 0;
42 start_value = X(min_index);
43 end_value = X(max_index);
44 baseline = arma::linspace(start_value, end_value, size);
46 maximum = region.max();
47 half_maximum = maximum / 2.0;
48 arma::uvec max_indices = find(region == maximum);
49 max_index = max_indices(0);
52 for (arma::uword i = max_index; i > 0; --i){
53 if (X(i) - half_maximum < 0){
60 for (arma::uword i = max_index; i < size; ++i){
61 if (X(i) - half_maximum < 0){
68 if (left_index > 0 && right_index < size - 1){
69 if(std::fabs(X(left_index) - half_maximum) > std::fabs(X(left_index - 1) - half_maximum)){
73 if (std::fabs(X(right_index) - half_maximum) > std::fabs(X(right_index + 1) - half_maximum)){
78 double region_size = region.subvec(left_index, right_index).n_elem;
80 return abscissa_step * region_size;
95 double delta = std::abs(abscissa(1) - abscissa(0));
96 arma::uvec left_bound = find(((min-delta) <= abscissa) && (abscissa <= (min+delta)));
97 arma::uvec right_bound = find(((max-delta) <= abscissa) && (abscissa <= (max+delta)));
99 arma::uword min_index = left_bound(0);
100 arma::uword max_index = right_bound(0);
101 boundaries << min_index << arma::endr << max_index;
103 min = abscissa(min_index);
104 max = abscissa(max_index);
106 arma::uword size = abscissa.subvec(min_index, max_index).n_elem;
107 arma::vec results(X.n_cols);
108 midlines.set_size(X.n_cols, size);
109 baselines.set_size(X.n_cols, size);
112 for (arma::uword i = 0; i < X.n_cols; ++i){
113 results(i) =
FindBandwidth(X.col(i), min_index, max_index, midline, baseline, delta);
114 midlines.row(i) = midline;
115 baselines.row(i) = baseline;
VESPUCCI_EXPORT arma::vec FindBandwidthMat(const arma::mat &X, arma::vec abscissa, double &min, double &max, arma::mat &midlines, arma::mat &baselines, arma::uvec &boundaries)
Vespucci::Math::Quantification::FindBandwidthMat.
VESPUCCI_EXPORT arma::uword max(arma::uword a, arma::uword b)
Vespucci::Math::max.
VESPUCCI_EXPORT arma::uword min(arma::uword a, arma::uword b)
Vespucci::Math::min.
VESPUCCI_EXPORT double FindBandwidth(const arma::vec &X, arma::uword min_index, arma::uword max_index, arma::vec &midline, arma::vec &baseline, double abscissa_step)
Vespucci::Math::Quantification::FindBandwidth.