Statistics.cpp
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Illustrates usage of the statistics component.
5  *
6  *
7  *
8  * \author T.Voss
9  * \date 2010
10  *
11  *
12  * \par Copyright 1995-2017 Shark Development Team
13  *
14  * <BR><HR>
15  * This file is part of Shark.
16  * <http://shark-ml.org/>
17  *
18  * Shark is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Lesser General Public License as published
20  * by the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * Shark is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
30  *
31  */
32 
34 #include <shark/Core/Random.h>
35 
36 using namespace shark;
37 
38 
39 int main(int argc, char** argv)
40 {
41  statistics::ResultTable<double> table(2,"VarianceOfGaussian");//set a name for the results
42  table.setDimensionName(0,"input1");
43  table.setDimensionName(1,"input2");
44 
45  // Fill the table with randomly generated numbers for different variances and mean and also add missing values
46  for(std::size_t k = 1; k != 10; ++k){
47  double var= 10.0*k;
48  for (std::size_t i = 0; i < 10000; i++){
49  double value1=random::gauss(random::globalRng, 0,var);
50  double value2=random::gauss(random::globalRng, 0,var);
52  value2=statistics::missingValue();
53  table.update(var,value1,value2 );
54  }
55  }
56 
57  statistics::Statistics<double> stats(&table);
58  stats.addStatistic(statistics::Mean());//adds a statistic "Mean" for each variable
59  stats.addStatistic("Variance", statistics::Variance());//explicit name
60  stats.addStatistic("Missing", statistics::FractionMissing());
61 
62  printCSV(stats);
63 }