BivarStats_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "BivarStats.hpp"
40 #include "Vector.hpp"
41 #include "TestUtil.hpp"
42 #include <iostream>
43 
45 {
46  public:
47  BivarStats_T(){eps = 1e-12;}// Default Constructor, set the precision value
48  ~BivarStats_T() {} // Default Desructor
49  double eps;
50  int addTest()
51  // Test to add data. Want to add single values to empty Stats class.
52  // Then add another stat on top with weight. I will use the average to check
53  // that data was added and that the data added was correct.
54  {
55  gnsstk::TestUtil testFramework("BivarStats","Add()",__FILE__,__LINE__);
56  std::string failMesg;
57 
59  test.add(1, 2);
60  test.add(2, 5);
61  test.add(3, 1);
62  test.add(4, 4);
63  test.add(5, 3);
64 
65  failMesg = "The Add method was unsuccessful";
66  //std::cout << "The Average is: " << test.average() << std::endl;
67  testFramework.assert(test.averageX() == 3, failMesg, __LINE__);
68  return testFramework.countFails();
69  }
70 
72  // Verify the X average calculation.
73  {
74  gnsstk::TestUtil testFramework("BivarStats","AverageX()",__FILE__,__LINE__);
75  std::string failMesg;
76 
78  test.add(1, 2);
79  test.add(2, 5);
80  test.add(3, 1);
81  test.add(4, 4);
82  test.add(5, 3);
83 
84  failMesg = "The AverageX method was unsuccessful";
85  //std::cout << "The Average of X is: " << test.averageX() << std::endl;
86  testFramework.assert(test.averageX() == 3, failMesg, __LINE__);
87  return testFramework.countFails();
88  }
89 
91  // Verify the Y average calculation.
92  {
93  gnsstk::TestUtil testFramework("BivarStats","AverageY()",__FILE__,__LINE__);
94  std::string failMesg;
95 
97  test.add(1, 2);
98  test.add(2, 5);
99  test.add(3, 1);
100  test.add(4, 4);
101  test.add(5, 3);
102 
103  failMesg = "The AverageY method was unsuccessful";
104  //std::cout << "The Average of Y is: " << test.averageY() << std::endl;
105  testFramework.assert(test.averageY() == 3, failMesg, __LINE__);
106  return testFramework.countFails();
107  }
108 
109  int MaxXTest()
110  // Verify the X maximum calculation.
111  {
112  gnsstk::TestUtil testFramework("BivarStats","MaximumX()",__FILE__,__LINE__);
113  std::string failMesg;
114 
116  test.add(1, 2);
117  test.add(2, 5);
118  test.add(3, 1);
119  test.add(4, 4);
120  test.add(5, 3);
121 
122  failMesg = "The MaximumX method was unsuccessful";
123  //std::cout << "The Maximum of X is: " << test.maximumX() << std::endl;
124  testFramework.assert(test.maximumX() == 5, failMesg, __LINE__);
125  return testFramework.countFails();
126  }
127 
128  int MaxYTest()
129  // Verify the Y maximum calculation.
130  {
131  gnsstk::TestUtil testFramework("BivarStats","MaximumY()",__FILE__,__LINE__);
132  std::string failMesg;
133 
135  test.add(1, 2);
136  test.add(2, 5);
137  test.add(3, 1);
138  test.add(4, 4);
139  test.add(5, 3);
140 
141  failMesg = "The MaximumY method was unsuccessful";
142  //std::cout << "The Maximum of Y is: " << test.maximumY() << std::endl;
143  testFramework.assert(test.maximumY() == 5, failMesg, __LINE__);
144  return testFramework.countFails();
145  }
146 
147  int MinXTest()
148  // Verify the X minimum calculation.
149  {
150  gnsstk::TestUtil testFramework("BivarStats","MinimumX()",__FILE__,__LINE__);
151  std::string failMesg;
152 
154  test.add(1, 2);
155  test.add(2, 5);
156  test.add(3, 1);
157  test.add(4, 4);
158  test.add(5, 3);
159 
160  failMesg = "The MinimumX method was unsuccessful";
161  //std::cout << "The Minimum of X is: " << test.minimumX() << std::endl;
162  testFramework.assert(test.minimumX() == 1, failMesg, __LINE__);
163  return testFramework.countFails();
164  }
165 
166  int MinYTest()
167  // Verify the Y minimum calculation.
168  {
169  gnsstk::TestUtil testFramework("BivarStats","MinimumY()",__FILE__,__LINE__);
170  std::string failMesg;
171 
173  test.add(1, 2);
174  test.add(2, 5);
175  test.add(3, 1);
176  test.add(4, 4);
177  test.add(5, 3);
178 
179  failMesg = "The MinimumY method was unsuccessful";
180  //std::cout << "The Minimum of Y is: " << test.minimumY() << std::endl;
181  testFramework.assert(test.minimumY() == 1, failMesg, __LINE__);
182  return testFramework.countFails();
183  }
184 
186  // Verify the X variance calculation.
187  {
188  gnsstk::TestUtil testFramework("BivarStats","VarianceX()",__FILE__,__LINE__);
189  std::string failMesg;
190 
192  test.add(1, 2);
193  test.add(2, 5);
194  test.add(3, 1);
195  test.add(4, 4);
196  test.add(5, 3);
197 
198  failMesg = "The VarianceX method was unsuccessful";
199  //std::cout << "The Variance of X is: " << test.varianceX() << std::endl;
200  testFramework.assert(fabs(test.varianceX() - 2.5) < eps, failMesg, __LINE__);
201  return testFramework.countFails();
202  }
203 
205  // Verify the Y variance calculation.
206  {
207  gnsstk::TestUtil testFramework("BivarStats","VarianceY()",__FILE__,__LINE__);
208  std::string failMesg;
209 
211  test.add(1, 2);
212  test.add(2, 5);
213  test.add(3, 1);
214  test.add(4, 4);
215  test.add(5, 3);
216 
217  failMesg = "The VarianceY method was unsuccessful";
218  //std::cout << "The Variance of Y is: " << test.varianceY() << std::endl;
219  testFramework.assert(fabs(test.varianceY() - 2.5) < eps, failMesg, __LINE__);
220  return testFramework.countFails();
221  }
222 
224  // Verify the X Standard Deviation calculation.
225  {
226  gnsstk::TestUtil testFramework("BivarStats","StdDevX()",__FILE__,__LINE__);
227  std::string failMesg;
228 
230  test.add(1, 2);
231  test.add(2, 5);
232  test.add(3, 1);
233  test.add(4, 4);
234  test.add(5, 3);
235 
236  failMesg = "The stdDevX method was unsuccessful";
237  //std::cout << "The Standard Deviation of X is: " << test.stdDevX() << std::endl;
238  testFramework.assert(fabs(test.stdDevX() - sqrt(2.5)) < eps, failMesg, __LINE__);
239  return testFramework.countFails();
240  }
242  // Verify the Y Standard Deviation calculation.
243  {
244  gnsstk::TestUtil testFramework("BivarStats","StdDevY()",__FILE__,__LINE__);
245  std::string failMesg;
246 
248  test.add(1, 2);
249  test.add(2, 5);
250  test.add(3, 1);
251  test.add(4, 4);
252  test.add(5, 3);
253 
254  failMesg = "The stdDevY method was unsuccessful";
255  //std::cout << "The Standard Deviation of Y is: " << test.stdDevY() << std::endl;
256  testFramework.assert(fabs(test.stdDevY() - sqrt(2.5)) < eps, failMesg, __LINE__);
257  return testFramework.countFails();
258  }
259 
260  int SlopeTest()
261  // Verify the Slope calculation.
262  {
263  gnsstk::TestUtil testFramework("BivarStats","Slope()",__FILE__,__LINE__);
264  std::string failMesg;
265 
267  test.add(1, 2);
268  test.add(2, 5);
269  test.add(3, 1);
270  test.add(4, 4);
271  test.add(5, 3);
272 
273  failMesg = "The Slope method was unsuccessful";
274  //std::cout << "The Slope is: " << test.slope() << std::endl;
275  testFramework.assert(fabs(test.slope() - 0.1) < eps, failMesg, __LINE__);
276  return testFramework.countFails();
277  }
278 
280  // Verify the Intercept calculation.
281  {
282  gnsstk::TestUtil testFramework("BivarStats","Intercept()",__FILE__,__LINE__);
283  std::string failMesg;
284 
286  test.add(1, 2);
287  test.add(2, 5);
288  test.add(3, 1);
289  test.add(4, 4);
290  test.add(5, 3);
291 
292  failMesg = "The Intercept method was unsuccessful";
293  //std::cout << "The Intercept is: " << test.intercept() << std::endl;
294  testFramework.assert(fabs(test.intercept() - 2.7) < eps, failMesg, __LINE__);
295  return testFramework.countFails();
296  }
297 
299  // Verify the Slope Uncertainty calculation.
300  {
301  gnsstk::TestUtil testFramework("BivarStats","SlopeUncertainty()",__FILE__,__LINE__);
302  std::string failMesg;
303 
305  test.add(1, 2);
306  test.add(2, 5);
307  test.add(3, 1);
308  test.add(4, 4);
309  test.add(5, 3);
310 
311  failMesg = "The sigmaSlope method was unsuccessful";
312  //std::cout << "The Slope Uncertainty is: " << test.sigmaSlope() << std::endl;
313  testFramework.assert(fabs(test.sigmaSlope() - 0.574456264653803) < eps, failMesg, __LINE__);
314  return testFramework.countFails();
315  }
316 
318  // Verify the Conditional Uncertainty calculation.
319  {
320  gnsstk::TestUtil testFramework("BivarStats","ConditionalUncertaintyTest()",__FILE__,__LINE__);
321  std::string failMesg;
322 
324  test.add(1, 2);
325  test.add(2, 5);
326  test.add(3, 1);
327  test.add(4, 4);
328  test.add(5, 3);
329 
330  failMesg = "The sigmaYX method was unsuccessful";
331  //std::cout << "The Conditional Uncertainty is: " << test.sigmaYX() << std::endl;
332  testFramework.assert(fabs(test.sigmaYX() - 1.81659021245849) < eps, failMesg, __LINE__);
333  return testFramework.countFails();
334  }
335 
337  // Verify the Correlation calculation.
338  {
339  gnsstk::TestUtil testFramework("BivarStats","Correlation()",__FILE__,__LINE__);
340  std::string failMesg;
341 
343  test.add(1, 2);
344  test.add(2, 5);
345  test.add(3, 1);
346  test.add(4, 4);
347  test.add(5, 3);
348 
349  failMesg = "The correlation method was unsuccessful";
350  //std::cout << "The Correlation is: " << test.correlation() << std::endl;
351  testFramework.assert(fabs(test.correlation() - 0.1) < eps, failMesg, __LINE__);
352  return testFramework.countFails();
353  }
354 
355  };
356 
357 int main()
358 {
359  int check, errorCounter = 0;
360  BivarStats_T testClass;
361 
362  check = testClass.addTest();
363  errorCounter += check;
364 
365  check = testClass.AverageXTest();
366  errorCounter += check;
367 
368  check = testClass.AverageYTest();
369  errorCounter += check;
370 
371  check = testClass.MaxXTest();
372  errorCounter += check;
373 
374  check = testClass.MaxYTest();
375  errorCounter += check;
376 
377  check = testClass.MinXTest();
378  errorCounter += check;
379 
380  check = testClass.MinYTest();
381  errorCounter += check;
382 
383  check = testClass.VarianceXTest();
384  errorCounter += check;
385 
386  check = testClass.VarianceYTest();
387  errorCounter += check;
388 
389  check = testClass.StdDevXTest();
390  errorCounter += check;
391 
392  check = testClass.StdDevYTest();
393  errorCounter += check;
394 
395  check = testClass.SlopeTest();
396  errorCounter += check;
397 
398  check = testClass.InterceptTest();
399  errorCounter += check;
400 
401  check = testClass.ConditionalUncertaintyTest();
402  errorCounter += check;
403 
404  check = testClass.SlopeUncertaintyTest();
405  errorCounter += check;
406 
407  check = testClass.CorrelationTest();
408  errorCounter += check;
409 
410  std::cout << "Total Errors: " << errorCounter << std::endl;
411 
412  return errorCounter;
413 }
gnsstk::BivarStats::averageX
T averageX(void) const
Definition: BivarStats.hpp:346
BivarStats.hpp
BivarStats_T::MaxYTest
int MaxYTest()
Definition: BivarStats_T.cpp:128
BivarStats_T::CorrelationTest
int CorrelationTest()
Definition: BivarStats_T.cpp:336
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
gnsstk::BivarStats::sigmaYX
T sigmaYX(void) const
return conditional uncertainty = uncertainty y given x
Definition: BivarStats.hpp:409
gnsstk::BivarStats::stdDevX
T stdDevX(void) const
Definition: BivarStats.hpp:366
gnsstk::BivarStats::averageY
T averageY(void) const
Definition: BivarStats.hpp:349
gnsstk::BivarStats::stdDevY
T stdDevY(void) const
Definition: BivarStats.hpp:368
gnsstk::BivarStats::varianceX
T varianceX(void) const
Definition: BivarStats.hpp:354
BivarStats_T::SlopeTest
int SlopeTest()
Definition: BivarStats_T.cpp:260
BivarStats_T::AverageXTest
int AverageXTest()
Definition: BivarStats_T.cpp:71
BivarStats_T::VarianceXTest
int VarianceXTest()
Definition: BivarStats_T.cpp:185
TestUtil.hpp
gnsstk::BivarStats::maximumY
T maximumY(void) const
Definition: BivarStats.hpp:343
gnsstk::BivarStats::correlation
T correlation(void) const
Definition: BivarStats.hpp:399
gnsstk::BivarStats::intercept
T intercept(void) const
Return intercept of best-fit line Y=slope*X + intercept.
Definition: BivarStats.hpp:381
BivarStats_T::eps
double eps
Definition: BivarStats_T.cpp:49
gnsstk::BivarStats::minimumY
T minimumY(void) const
Definition: BivarStats.hpp:341
BivarStats_T::SlopeUncertaintyTest
int SlopeUncertaintyTest()
Definition: BivarStats_T.cpp:298
BivarStats_T::StdDevYTest
int StdDevYTest()
Definition: BivarStats_T.cpp:241
main
int main()
Definition: BivarStats_T.cpp:357
gnsstk::BivarStats::varianceY
T varianceY(void) const
Definition: BivarStats.hpp:360
BivarStats_T::addTest
int addTest()
Definition: BivarStats_T.cpp:50
BivarStats_T::MinYTest
int MinYTest()
Definition: BivarStats_T.cpp:166
BivarStats_T::VarianceYTest
int VarianceYTest()
Definition: BivarStats_T.cpp:204
BivarStats_T
Definition: BivarStats_T.cpp:44
BivarStats_T::MaxXTest
int MaxXTest()
Definition: BivarStats_T.cpp:109
gnsstk::BivarStats::maximumX
T maximumX(void) const
Definition: BivarStats.hpp:339
gnsstk::BivarStats
Definition: BivarStats.hpp:63
BivarStats_T::MinXTest
int MinXTest()
Definition: BivarStats_T.cpp:147
BivarStats_T::ConditionalUncertaintyTest
int ConditionalUncertaintyTest()
Definition: BivarStats_T.cpp:317
BivarStats_T::StdDevXTest
int StdDevXTest()
Definition: BivarStats_T.cpp:223
BivarStats_T::InterceptTest
int InterceptTest()
Definition: BivarStats_T.cpp:279
BivarStats_T::BivarStats_T
BivarStats_T()
Definition: BivarStats_T.cpp:47
gnsstk::TestUtil
Definition: TestUtil.hpp:265
BivarStats_T::AverageYTest
int AverageYTest()
Definition: BivarStats_T.cpp:90
Vector.hpp
gnsstk::BivarStats::add
void add(const T &x, const T &y)
Definition: BivarStats.hpp:204
BivarStats_T::~BivarStats_T
~BivarStats_T()
Definition: BivarStats_T.cpp:48
gnsstk::BivarStats::sigmaSlope
T sigmaSlope(void) const
Return uncertainty in slope.
Definition: BivarStats.hpp:390
gnsstk::BivarStats::minimumX
T minimumX(void) const
Definition: BivarStats.hpp:337
gnsstk::BivarStats::slope
T slope(void) const
Return slope of best-fit line Y=slope*X + intercept.
Definition: BivarStats.hpp:371


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38