Vespucci  1.0.0
histogram.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 *******************************************************************************/
20 #include "Math/Stats/histogram.h"
21 arma::uvec Vespucci::Math::Stats::GenerateHistogram(const arma::mat &data,
22  arma::vec &edges,
23  uint bins)
24 {
25  if (!data.n_elem) return arma::uvec();
26  uint bin_count = bins;
27 
28  if (!bins){
30  }
31 
32  bin_count = (bin_count > 2 ? bin_count : 3); //histogram will always have at least three bins
33  edges = arma::linspace<arma::vec>(data.min() - 1.0, data.max() + 1.0, bin_count + 1);
34  arma::umat hist_data = arma::histc(data, edges);
35  hist_data = arma::sum(hist_data, 1);
36 
37  return arma::conv_to<arma::uvec>::from(hist_data);
38 }
39 
40 uint Vespucci::Math::Stats::EstimateBinCount(const arma::mat &data)
41 {
42  //Sturges' rule for finding bin counts automagically
43  return uint(std::round(1.0 + 3.332*std::log10((double(data.n_elem)))));
44 }
VESPUCCI_EXPORT arma::uvec GenerateHistogram(const arma::mat &data, arma::vec &edges, uint bins=0)
Definition: histogram.cpp:21
VESPUCCI_EXPORT uint EstimateBinCount(const arma::mat &data)
Definition: histogram.cpp:40