ProteoWizard
Functions | Variables
StatsTest.cpp File Reference
#include "Stats.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Functions

void test ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ test()

void test ( )

Definition at line 37 of file StatsTest.cpp.

38{
40 a(0) = 1;
41 a(1) = 2;
42
44 b(0) = 3;
45 b(1) = 4;
46
48 c(0) = 5;
49 c(1) = 6;
50
52 data.push_back(a);
53 data.push_back(b);
54 data.push_back(c);
55
56 Stats stats(data);
57 if (os_) *os_ << "mean: " << stats.mean() << endl;
58 if (os_) *os_ << "covariance: " << stats.covariance() << endl;
59
60 // mean & covariance computed using good old-fashioned reckoning
62 mean(0) = 3;
63 mean(1) = 4;
64 Stats::matrix_type covariance(2,2);
65 covariance(0,0) = covariance(0,1) = covariance(1,0) = covariance(1,1) = 8/3.;
66
67 // verify results
68 const double epsilon = 1e-12;
69 unit_assert_vectors_equal(stats.mean(), mean, epsilon);
70 unit_assert_matrices_equal(stats.covariance(), covariance, epsilon);
71
72 double rms0_good = sqrt(35./3);
73 double rms1_good = sqrt(56./3);
74 double rms0_test = sqrt(stats.meanOuterProduct()(0,0));
75 double rms1_test = sqrt(stats.meanOuterProduct()(1,1));
76 unit_assert_equal(rms0_test, rms0_good, epsilon);
77 unit_assert_equal(rms1_test, rms1_good, epsilon);
78}
ostream * os_
Definition StatsTest.cpp:34
std::vector< vector_type > data_type
Definition Stats.hpp:46
boost::numeric::ublas::vector< double > vector_type
Definition Stats.hpp:44
boost::numeric::ublas::matrix< double > matrix_type
Definition Stats.hpp:45
const double epsilon
Definition DiffTest.cpp:41
std::iterator_traits< InputIterator >::value_type mean(InputIterator begin, InputIterator end)
MEAN Trimmed arithmetic mean.
Definition base.hpp:187
#define unit_assert_matrices_equal(A, B, epsilon)
Definition unit.hpp:135
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99
#define unit_assert_vectors_equal(A, B, epsilon)
Definition unit.hpp:139

References pwiz::math::Stats::covariance(), epsilon, pwiz::math::Stats::mean(), pwiz::math::Stats::meanOuterProduct(), os_, unit_assert_equal, unit_assert_matrices_equal, and unit_assert_vectors_equal.

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 81 of file StatsTest.cpp.

82{
83 TEST_PROLOG(argc, argv)
84
85 try
86 {
87 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
88 if (os_) *os_ << "StatsTest\n";
89 test();
90 }
91 catch (exception& e)
92 {
93 TEST_FAILED(e.what())
94 }
95 catch (...)
96 {
97 TEST_FAILED("Caught unknown exception.")
98 }
99
101}
void test()
Definition StatsTest.cpp:37
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

References os_, test(), TEST_EPILOG, TEST_FAILED, and TEST_PROLOG.

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 34 of file StatsTest.cpp.

Referenced by main(), and test().