Phoenix2D-Library  0.10
Normal.cpp
Go to the documentation of this file.
1 /*
2  * Phoenix2D (RoboCup Soccer Simulation 2D League)
3  * Copyright (c) 2013 Ivan Gonzalez
4  *
5  * This file is part of Phoenix2D.
6  *
7  * Phoenix2D is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Phoenix2D is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Phoenix2D. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <cmath>
22 #include "Normal.h"
23 namespace Phoenix
24 {
25 Normal::Normal(double mean, double deviation) {
26  this->mean = mean;
27  this->deviation = deviation;
28 }
29 
30 Normal::Normal(std::list<double> data, bool circular) {
31  mean = 0.0;
32  deviation = 0.0;
33  if (data.size() > 1) {
34  double sum = 0.0;
35  for (std::list<double>::iterator it = data.begin(); it != data.end(); ++it) {
36  sum += *it;
37  }
38  mean = sum / data.size();
39  sum = 0.0;
40  for (std::list<double>::iterator it = data.begin(); it != data.end(); ++it) {
41  sum += pow(*it - mean, 2.0);
42  }
43  deviation = sqrt(sum / (data.size() - 1));
44  } else if (data.size() == 1) {
45  mean = data.front();
46  }
47 }
48 
49 Normal::Normal(std::list<double> data, std::list<int> multipliers, bool circular) {
50  mean = 0.0;
51  deviation = 0.0;
52  if (data.size() == multipliers.size() && data.size() > 1) {
53  double sum = 0.0;
54  int weight = 0;
55  std::list<double>::iterator data_it = data.begin();
56  std::list<int>::iterator multiplier_it = multipliers.begin();
57  do {
58  sum += *multiplier_it * *data_it;
59  weight += *multiplier_it;
60  ++data_it;
61  ++multiplier_it;
62  } while (data_it != data.end());
63  mean = sum / weight;
64  sum = 0.0;
65  data_it = data.begin();
66  multiplier_it = multipliers.begin();
67  do {
68  sum += *multiplier_it * pow(*data_it - mean, 2.0);
69  ++data_it;
70  ++multiplier_it;
71  } while (data_it != data.end());
72  deviation = sqrt(sum / (weight - 1));
73  } else if (data.size() == 1) {
74  mean = data.front();
75  }
76 }
77 
79 
80 }
81 
83  return mean - 1.68 * deviation;
84 }
85 
87  return mean + 1.68 * deviation;
88 }
89 
90 double Normal::getMean() {
91  return mean;
92 }
93 
95  return deviation;
96 }
97 }
double getUpper5()
Definition: Normal.cpp:86
Normal(double mean, double deviation)
Definition: Normal.cpp:25
double getMean()
Definition: Normal.cpp:90
double getStdDeviation()
Definition: Normal.cpp:94
double deviation
Definition: Normal.h:37
double mean
Definition: Normal.h:36
double getLower5()
Definition: Normal.cpp:82