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