[7fa5e8]: src / modules / bugs / functions / SD.cc Maximize Restore History

Download this file

SD.cc    43 lines (34 with data), 799 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <config.h>
#include "SD.h"
#include <cmath>
using std::vector;
using std::sqrt;
namespace bugs {
SD::SD ()
: VectorFunction ("sd", 1)
{
}
void SD::evaluate (double *x, vector<double const *>const &args,
vector<unsigned int> const &lengths) const
{
double svalue = 0;
if (lengths[0] > 1) {
unsigned int i;
double sum = 0;
for (unsigned i = 0; i < lengths[0]; i++) {
sum += args[0][i];
}
double mean = sum / lengths[0];
double var = 0;
for (i = 0; i < lengths[0]; i++) {
var += (args[0][i] - mean) * (args[0][i] - mean);
}
svalue = sqrt (var / (lengths[0] - 1));
}
*x = svalue;
}
bool SD::checkParameterLength (vector<unsigned int> const &lengths) const
{
return lengths[0] >= 2;
}
}