SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
stat.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file stat.cc Statistics
3
//
4
// Copyright (c) 1991-2004 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
//
10
// class Stat implementation
11
//
12
13
////////////////////////////////////////////////////////////////////////////
14
// interface
15
//
16
17
#include "
simlib.h
"
18
#include "
internal.h
"
19
20
#include <cmath>
// sqrt()
21
22
23
////////////////////////////////////////////////////////////////////////////
24
// implementation
25
//
26
27
namespace
simlib3
{
28
29
SIMLIB_IMPLEMENTATION
;
30
31
////////////////////////////////////////////////////////////////////////////
32
// operator () --- record value
33
//
34
void
Stat::operator ()
(
double
x)
35
{
36
sx
+= x;
37
sx2
+= x*x;
38
if
(++
n
==1)
min
=
max
=x;
39
else
{
40
if
(x<
min
)
min
= x;
41
if
(x>
max
)
max
= x;
42
}
43
};
44
45
46
////////////////////////////////////////////////////////////////////////////
47
// constructors
48
//
49
Stat::Stat
(
const
char
*name) :
50
sx
(0),
sx2
(0),
51
min
(0),
max
(0),
52
n
(0)
53
{
54
Dprintf
((
"Stat::Stat(\"%s\")"
,name));
55
SetName
(name);
56
}
57
58
Stat::Stat
() :
59
sx
(0),
sx2
(0),
60
min
(0),
max
(0),
61
n
(0)
62
{
63
Dprintf
((
"Stat::Stat()"
));
64
}
65
66
////////////////////////////////////////////////////////////////////////////
67
// destructor
68
//
69
Stat::~Stat
()
70
{
71
Dprintf
((
"Stat::~Stat() // \"%s\" "
,
Name
().c_str()));
72
}
73
74
////////////////////////////////////////////////////////////////////////////
75
// Stat::Clear --- initialize
76
//
77
void
Stat::Clear
()
78
{
79
sx
=
sx2
= 0;
// sums
80
min
=
max
= 0;
81
n
= 0;
// # of records
82
}
83
84
85
////////////////////////////////////////////////////////////////////////////
86
// Stat::MeanValue
87
//
88
double
Stat::MeanValue
()
const
89
{
90
if
(
n
==0)
SIMLIB_error
(
StatNoRecError
);
91
return
sx
/
n
;
92
}
93
94
////////////////////////////////////////////////////////////////////////////
95
// Stat::StdDev --- standard deviation
96
//
97
double
Stat::StdDev
()
const
98
{
99
if
(
n
<2)
SIMLIB_error
(
StatDispError
);
100
double
mv =
sx
/
n
;
101
return
sqrt((
sx2
-
n
*mv*mv)/(
n
-1));
102
}
103
104
}
105
// end
simlib3::SimObject::SetName
void SetName(const std::string &name)
assign the name
Definition
object.cc:125
simlib3::SimObject::Name
virtual std::string Name() const
get object name
Definition
object.cc:134
simlib3::Stat::Stat
Stat()
Definition
stat.cc:58
simlib3::Stat::StdDev
double StdDev() const
Definition
stat.cc:97
simlib3::Stat::Clear
virtual void Clear()
initialize
Definition
stat.cc:77
simlib3::Stat::min
double min
Definition
simlib.h:572
simlib3::Stat::~Stat
~Stat()
Definition
stat.cc:69
simlib3::Stat::operator()
void operator()(double x)
record the value
Definition
stat.cc:34
simlib3::Stat::max
double max
Definition
simlib.h:573
simlib3::Stat::MeanValue
double MeanValue() const
Definition
stat.cc:88
simlib3::Stat::n
unsigned long n
Definition
simlib.h:574
simlib3::Stat::sx
double sx
Definition
simlib.h:570
simlib3::Stat::sx2
double sx2
Definition
simlib.h:571
internal.h
Internal header file for SIMLIB/C++.
Dprintf
#define Dprintf(f)
Definition
internal.h:100
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::SIMLIB_error
void SIMLIB_error(const enum _ErrEnum N)
print error message and abort program
Definition
error.cc:38
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::StatNoRecError
@ StatNoRecError
Definition
errors.cc:72
simlib3::StatDispError
@ StatDispError
Definition
errors.cc:73
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0