statistics.h
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// S T A T I S T I C S H E A D E R
5//
6// Artificial Intelligence Techniques, SL
7// artelnics@artelnics.com
8
9#ifndef STATISTICS_H
10#define STATISTICS_H
11
12// System includes
13
14#include <fstream>
15#include <iostream>
16#include <limits>
17#include <math.h>
18#include <vector>
19
20// OpenNN includes
21
22#include "config.h"
23
24using namespace std;
25using namespace Eigen;
26
27namespace OpenNN
28{
29
31
39
41
42 // Default constructor.
43
44 explicit Descriptives();
45
46 // Values constructor.
47
48 explicit Descriptives(const type&, const type&, const type&, const type&);
49
51
52 virtual ~Descriptives();
53
54 // Set methods
55
56 void set(const type&, const type&, const type&, const type&);
57
58 void set_minimum(const type&);
59
60 void set_maximum(const type&);
61
62 void set_mean(const type&);
63
64 void set_standard_deviation(const type&);
65
66 Tensor<type, 1> to_vector() const;
67
69
71
72 void save(const string &file_name) const;
73
74 void print(const string& = "Descriptives:") const;
75
77
78 string name;
79
81
82 type minimum = type(0);
83
85
86 type maximum = type(0);
87
89
90 type mean = type(0);
91
93
94 type standard_deviation = type(0);
95
96};
97
98
109
110struct BoxPlot {
111
112 type minimum = type(0);
113
114 type first_quartile = type(0);
115
116 type median = type(0);
117
118 type third_quartile = type(0);
119
120 type maximum = type(0);
121
122 // Default constructor.
123
124 explicit BoxPlot() {}
125
126 // Values constructor.
127
128 explicit BoxPlot(const type&, const type&, const type&, const type&, const type&);
129
130 virtual ~BoxPlot() {}
131
132
133 void set(const type&, const type&, const type&, const type&, const type&);
134};
135
136
147
149{
151
152 explicit Histogram();
153
155
156 explicit Histogram(const Index&);
157
159
160 explicit Histogram(const Tensor<type, 1>&, const Tensor<Index, 1>&);
161
163
164 explicit Histogram(const Tensor<type, 1>&, const Index&);
165
167
168 explicit Histogram(const Tensor<type, 1>&);
169
171
172 virtual ~Histogram();
173
174 // Methods
175
176 Index get_bins_number() const;
177
178 Index count_empty_bins() const;
179
180 Index calculate_minimum_frequency() const;
181
182 Index calculate_maximum_frequency() const;
183
184 Index calculate_most_populated_bin() const;
185
186 Tensor<type, 1> calculate_minimal_centers() const;
187
188 Tensor<type, 1> calculate_maximal_centers() const;
189
190 Index calculate_bin(const type&) const;
191
192 Index calculate_frequency(const type&) const;
193
194 void save(const string&) const;
195
197
198 Tensor<type, 1> centers;
199
201
202 Tensor<type, 1> minimums;
203
205
206 Tensor<type, 1> maximums;
207
209
210 Tensor<Index, 1> frequencies;
211};
212 // Minimum
213
214 type minimum(const Tensor<type, 1>&);
215 type minimum(const Tensor<type, 1>&, const Tensor<Index, 1>&);
216 Index minimum(const Tensor<Index, 1>&);
217 type minimum(const Tensor<type, 2>&);
218 Tensor<type, 1> columns_minimums(const Tensor<type, 2>&, const Tensor<Index, 1>& = Tensor<Index, 1>(), const Tensor<Index, 1>& = Tensor<Index, 1>());
219
220 // Maximum
221
222 type maximum(const Tensor<type, 1>&);
223 type maximum(const Tensor<type, 1>&, const Tensor<Index, 1>&);
224 Index maximum(const Tensor<Index, 1>&);
225 type maximum(const Tensor<type, 2>&);
226 Tensor<type, 1> columns_maximums(const Tensor<type, 2>&, const Tensor<Index, 1>& = Tensor<Index, 1>(), const Tensor<Index, 1>& = Tensor<Index, 1>());
227
228 // Range
229 type range(const Tensor<type, 1>&);
230
231 // Mean
232 type mean(const Tensor<type, 1>&);
233 type mean(const Tensor<type, 1>&, const Index&, const Index&);
234 type mean(const Tensor<type, 2>&, const Index&);
235 Tensor<type, 1> mean(const Tensor<type, 2>&);
236 Tensor<type, 1> mean(const Tensor<type, 2>&, const Tensor<Index, 1>&);
237 Tensor<type, 1> mean(const Tensor<type, 2>&, const Tensor<Index, 1>&, const Tensor<Index, 1>&);
238
239 // Median
240 type median(const Tensor<type, 1>&);
241 type median(const Tensor<type, 2>&, const Index&);
242 Tensor<type, 1> median(const Tensor<type, 2>&);
243 Tensor<type, 1> median(const Tensor<type, 2>&, const Tensor<Index, 1>&);
244 Tensor<type, 1> median(const Tensor<type, 2>&, const Tensor<Index, 1>&, const Tensor<Index, 1>&);
245
246 // Variance
247 type variance(const Tensor<type, 1>&);
248 type variance(const Tensor<type, 1>&, const Tensor<Index, 1>&);
249
250 // Standard deviation
251 type standard_deviation(const Tensor<type, 1>&);
252 type standard_deviation(const Tensor<type, 1>&, const Tensor<Index, 1>&);
253 Tensor<type, 1> standard_deviation(const Tensor<type, 1>&, const Index&);
254
255 // Assymetry
256 type asymmetry(const Tensor<type, 1>&);
257
258 // Kurtosis
259 type kurtosis(const Tensor<type, 1>&);
260
261 // Quartiles
262 Tensor<type, 1> quartiles(const Tensor<type, 1>&);
263 Tensor<type, 1> quartiles(const Tensor<type, 1>&, const Tensor<Index, 1>&);
264
265 // Box plot
266 BoxPlot box_plot(const Tensor<type, 1>&);
267 BoxPlot box_plot(const Tensor<type, 1>&, const Tensor<Index, 1>&);
268
269 // Descriptives vector
270 Descriptives descriptives(const Tensor<type, 1>&);
271
272 // Descriptives matrix
273 Tensor<Descriptives, 1> descriptives(const Tensor<type, 2>&);
274 Tensor<Descriptives, 1> descriptives(const Tensor<type, 2>&, const Tensor<Index, 1>&, const Tensor<Index, 1>&);
275
276 // Histograms
277 Histogram histogram(const Tensor<type, 1>&, const Index& = 10);
278 Histogram histogram_centered(const Tensor<type, 1>&, const type& = type(0), const Index& = 10);
279 Histogram histogram(const Tensor<bool, 1>&);
280 Histogram histogram(const Tensor<Index, 1>&, const Index& = 10);
281 Tensor<Histogram, 1> histograms(const Tensor<type, 2>&, const Index& = 10);
282 Tensor<Index, 1> total_frequencies(const Tensor<Histogram, 1>&);
283
284 // Distribution
285 Index perform_distribution_distance_analysis(const Tensor<type, 1>&);
286 type normal_distribution_distance(const Tensor<type, 1>&);
287 type half_normal_distribution_distance(const Tensor<type, 1>&);
288 type uniform_distribution_distance(const Tensor<type, 1>&);
289
290 // Normality
291 type normality_parameter(const Tensor<type, 1>&);
292
293 // Minimal indices
294 Index minimal_index(const Tensor<type, 1>&);
295 Tensor<Index, 1> minimal_indices(const Tensor<type, 1>&, const Index&);
296 Tensor<Index, 1> minimal_indices(const Tensor<type, 2>&);
297
298 // Maximal indices
299 Index maximal_index(const Tensor<type, 1>&);
300 Tensor<Index, 1> maximal_indices(const Tensor<type, 1>&, const Index&);
301 Tensor<Index, 1> maximal_indices(const Tensor<type, 2>&);
302 Tensor<Index, 2> maximal_columns_indices(const Tensor<type, 2>&, const Index&);
303 Tensor<type, 1> variation_percentage(const Tensor<type, 1>&);
304
305 // Mean weights
306 Tensor<Index, 1> maximal_indices();
307 Tensor<Tensor<Index, 1>, 1> minimal_maximal_indices();
308
309 // Percentiles
310 Tensor<type, 1> percentiles(const Tensor<type, 1>&);
311
312 // Means by categories
313 Tensor<type, 1> means_by_categories(const Tensor<type, 2>& matrix);
314
315 // NAN methods
316 Index count_nan(const Tensor<type, 1>&);
317}
318
319#endif // STATISTICS_H
Extensions to the C++ standard library.
Definition: half.hpp:2325
This structure contains the simplest Descriptives for a set, variable, etc. It includes :
Definition: statistics.h:40
bool has_minimum_minus_one_maximum_one()
Definition: statistics.cpp:111
Tensor< type, 1 > to_vector() const
Definition: statistics.cpp:96
Descriptives()
Default constructor.
Definition: statistics.cpp:16
bool has_mean_zero_standard_deviation_one()
Definition: statistics.cpp:125
virtual ~Descriptives()
Destructor.
Definition: statistics.cpp:41
void print(const string &="Descriptives:") const
Print the tittle of descriptives structure.
Definition: statistics.cpp:140
type minimum
Smallest value of a set, function, etc.
Definition: statistics.h:82
string name
Name of variable.
Definition: statistics.h:78
void set_maximum(const type &)
Definition: statistics.cpp:67
void set_standard_deviation(const type &)
Definition: statistics.cpp:85
type standard_deviation
Standard deviation value of a set, function, etc.
Definition: statistics.h:94
void set_mean(const type &)
Definition: statistics.cpp:76
type mean
Mean value of a set, function, etc.
Definition: statistics.h:90
void set_minimum(const type &)
Definition: statistics.cpp:58
type maximum
Biggest value of a set, function, etc.
Definition: statistics.h:86
void save(const string &file_name) const
Definition: statistics.cpp:181
virtual ~Histogram()
Destructor.
Definition: statistics.cpp:214
Index calculate_most_populated_bin() const
Retuns the index of the most populated bin.
Definition: statistics.cpp:365
Index count_empty_bins() const
Returns the number of bins with zero variates.
Definition: statistics.cpp:332
Tensor< type, 1 > minimums
Minimum positions of the bins in the histogram.
Definition: statistics.h:202
Index calculate_minimum_frequency() const
Returns the number of variates in the less populated bin.
Definition: statistics.cpp:349
Index calculate_frequency(const type &) const
Definition: statistics.cpp:507
Tensor< type, 1 > calculate_minimal_centers() const
Returns a vector with the centers of the less populated bins.
Definition: statistics.cpp:380
Tensor< type, 1 > calculate_maximal_centers() const
Returns a vector with the centers of the most populated bins.
Definition: statistics.cpp:421
Index calculate_bin(const type &) const
Definition: statistics.cpp:463
Index calculate_maximum_frequency() const
Returns the number of variates in the most populated bin.
Definition: statistics.cpp:357
Tensor< type, 1 > maximums
Maximum positions of the bins in the histogram.
Definition: statistics.h:206
Tensor< Index, 1 > frequencies
Population of the bins in the histogram.
Definition: statistics.h:210
Tensor< type, 1 > centers
Positions of the bins in the histogram.
Definition: statistics.h:198
Histogram()
Default constructor.
Definition: statistics.cpp:209
Index get_bins_number() const
Returns the number of bins in the histogram.
Definition: statistics.cpp:324