1 /*********************************************************************
2 Statistical functions.
3 This is part of GNU Astronomy Utilities (Gnuastro) package.
4 
5 Original author:
6      Mohammad Akhlaghi <mohammad@akhlaghi.org>
7 Contributing author(s):
8 Copyright (C) 2015-2021, Free Software Foundation, Inc.
9 
10 Gnuastro is free software: you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation, either version 3 of the License, or (at your
13 option) any later version.
14 
15 Gnuastro is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
22 **********************************************************************/
23 #ifndef __GAL_STATISTICS_H__
24 #define __GAL_STATISTICS_H__
25 
26 /* Include other headers if necessary here. Note that other header files
27    must be included before the C++ preparations below */
28 #include <gnuastro/data.h>
29 
30 
31 /* C++ Preparations */
32 #undef __BEGIN_C_DECLS
33 #undef __END_C_DECLS
34 #ifdef __cplusplus
35 # define __BEGIN_C_DECLS extern "C" {
36 # define __END_C_DECLS }
37 #else
38 # define __BEGIN_C_DECLS                /* empty */
39 # define __END_C_DECLS                  /* empty */
40 #endif
41 /* End of C++ preparations */
42 
43 
44 
45 /* Actual header contants (the above were for the Pre-processor). */
46 __BEGIN_C_DECLS  /* From C++ preparations */
47 
48 
49 
50 /* Maximum number of tests for sigma-clipping convergence. */
51 #define GAL_STATISTICS_SIG_CLIP_MAX_CONVERGE 50
52 
53 /* Least acceptable mode symmetricity.*/
54 #define GAL_STATISTICS_MODE_GOOD_SYM         0.2f
55 
56 
57 
58 
59 
60 enum bin_status
61 {
62   GAL_STATISTICS_BINS_INVALID,           /* ==0 by C standard.  */
63 
64   GAL_STATISTICS_BINS_REGULAR,
65   GAL_STATISTICS_BINS_IRREGULAR,
66 };
67 
68 
69 /****************************************************************
70  ********               Simple statistics                 *******
71  ****************************************************************/
72 
73 gal_data_t *
74 gal_statistics_number(gal_data_t *input);
75 
76 gal_data_t *
77 gal_statistics_minimum(gal_data_t *input);
78 
79 gal_data_t *
80 gal_statistics_maximum(gal_data_t *input);
81 
82 gal_data_t *
83 gal_statistics_sum(gal_data_t *input);
84 
85 gal_data_t *
86 gal_statistics_mean(gal_data_t *input);
87 
88 gal_data_t *
89 gal_statistics_std(gal_data_t *input);
90 
91 gal_data_t *
92 gal_statistics_mean_std(gal_data_t *input);
93 
94 gal_data_t *
95 gal_statistics_median(gal_data_t *input, int inplace);
96 
97 size_t
98 gal_statistics_quantile_index(size_t size, double quantile);
99 
100 gal_data_t *
101 gal_statistics_quantile(gal_data_t *input, double quantile, int inplace);
102 
103 size_t
104 gal_statistics_quantile_function_index(gal_data_t *input, gal_data_t *value,
105                                        int inplace);
106 
107 gal_data_t *
108 gal_statistics_quantile_function(gal_data_t *input, gal_data_t *value,
109                                  int inplace);
110 
111 gal_data_t *
112 gal_statistics_unique(gal_data_t *input, int inplace);
113 
114 
115 
116 
117 
118 /****************************************************************
119  ********                     Mode                        *******
120  ****************************************************************/
121 
122 gal_data_t *
123 gal_statistics_mode(gal_data_t *input, float errorstd, int inplace);
124 
125 gal_data_t *
126 gal_statistics_mode_mirror_plots(gal_data_t *input, gal_data_t *value,
127                                  size_t numbins, int inplace,
128                                  double *mirror_val);
129 
130 
131 
132 
133 
134 /****************************************************************
135  ********                      Sort                       *******
136  ****************************************************************/
137 
138 int
139 gal_statistics_is_sorted(gal_data_t *input, int updateflags);
140 
141 void
142 gal_statistics_sort_increasing(gal_data_t *input);
143 
144 void
145 gal_statistics_sort_decreasing(gal_data_t *input);
146 
147 gal_data_t *
148 gal_statistics_no_blank_sorted(gal_data_t *input, int inplace);
149 
150 
151 
152 
153 
154 /****************************************************************
155  ********     Histogram and Cumulative Frequency Plot     *******
156  ****************************************************************/
157 gal_data_t *
158 gal_statistics_regular_bins(gal_data_t *data, gal_data_t *range,
159                             size_t numbins, double onebinstart);
160 
161 gal_data_t *
162 gal_statistics_histogram(gal_data_t *data, gal_data_t *bins,
163                          int normalize, int maxhistone);
164 
165 gal_data_t *
166 gal_statistics_histogram2d(gal_data_t *input, gal_data_t *bins);
167 
168 gal_data_t *
169 gal_statistics_cfp(gal_data_t *data, gal_data_t *bins, int normalize);
170 
171 
172 
173 
174 
175 /****************************************************************
176  *****************         Outliers          ********************
177  ****************************************************************/
178 gal_data_t *
179 gal_statistics_sigma_clip(gal_data_t *input, float multip, float param,
180                           int inplace, int quiet);
181 
182 gal_data_t *
183 gal_statistics_outlier_bydistance(int pos1_neg0, gal_data_t *input,
184                                   size_t window_size, float sigma,
185                                   float sigclip_multip, float sigclip_param,
186                                   int inplace, int quiet);
187 
188 gal_data_t *
189 gal_statistics_outlier_flat_cfp(gal_data_t *input, size_t numprev,
190                                 float sigclip_multip, float sigclip_param,
191                                 float thresh, size_t numcontig, int inplace,
192                                 int quiet, size_t *index);
193 
194 
195 
196 __END_C_DECLS    /* From C++ preparations */
197 
198 #endif           /* __GAL_STATISTICS_H__ */
199