tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
measure.h
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: measure.h (Formerly measure.h)
5  * Description: Statistics for a group of single measurements
6  * Author: Mark Seaman, SW Productivity
7  * Created: Fri Oct 16 14:37:00 1987
8  * Modified: Mon Apr 8 09:42:28 1991 (Mark Seaman) marks@hpgrlt
9  * Language: C
10  * Package: N/A
11  * Status: Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  ********************************************************************************
25  */
26 
27 #ifndef MEASURE_H
28 #define MEASURE_H
29 
30 /*
31 ----------------------------------------------------------------------
32  I n c l u d e s
33 ----------------------------------------------------------------------
34 */
35 
36 #include <cmath>
37 
38 /*
39 ----------------------------------------------------------------------
40  T y p e s
41 ----------------------------------------------------------------------
42 */
43 
44 typedef struct
45 {
49 } MEASUREMENT;
50 
51 /*
52 ----------------------------------------------------------------------
53  M a c r o s
54 ----------------------------------------------------------------------
55 */
56 
57 /**********************************************************************
58  * add_sample
59  *
60  * Add one more sample to a measurement.
61  **********************************************************************/
62 
63 #define ADD_SAMPLE(m, s) \
64  (m.sum_of_samples += (float)(s), \
65  m.sum_of_squares += (float)(s) * (float)(s), ++m.num_samples)
66 
67 /**********************************************************************
68  * mean
69  *
70  * Return the mean value of the measurement.
71  **********************************************************************/
72 
73 #define MEAN(m) \
74  ((m).num_samples ? ((float)((m).sum_of_samples / (m).num_samples)) : 0)
75 
76 /**********************************************************************
77  * new_measurement
78  *
79  * Initialize a record to hold a measurement of a group of individual
80  * samples.
81  **********************************************************************/
82 
83 #define new_measurement(m) \
84  ((m).num_samples = 0, (m).sum_of_samples = 0, (m).sum_of_squares = 0)
85 
86 /**********************************************************************
87  * number_of_samples
88  *
89  * Return the number of samples in a measurement.
90  **********************************************************************/
91 
92 #define number_of_samples(m) \
93 ((m).num_samples)
94 
95 /**********************************************************************
96  * standard_deviation
97  *
98  * Return the standard deviation of the measurement.
99  **********************************************************************/
100 
101 #define standard_deviation(m) \
102 ((float) sqrt (VARIANCE (m)))
103 
104 /**********************************************************************
105  * variance
106  *
107  * Return the variance of the measurement.
108  **********************************************************************/
109 
110 #define VARIANCE(m) \
111  (((m).num_samples > 1) \
112  ? ((float)(((m).num_samples * (m).sum_of_squares - \
113  (m).sum_of_samples * (m).sum_of_samples) / \
114  (((m).num_samples - 1) * (m).num_samples))) \
115  : 0)
116 
117 /**********************************************************************
118  * print_summary
119  *
120  * Summarize a MEASUREMENT record.
121  **********************************************************************/
122 
123 #define print_summary(string, measure) \
124  cprintf("\t%-20s \tn = %d, \tm = %4.2f, \ts = %4.2f\n ", string, \
125  number_of_samples(measure), MEAN(measure), \
126  standard_deviation(measure))
127 #endif
long num_samples
Definition: measure.h:46
float sum_of_squares
Definition: measure.h:48
float sum_of_samples
Definition: measure.h:47
Definition: measure.h:44