ProteoWizard
NoiseTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2009 Center for Applied Molecular Medicine
8// University of Southern California, Los Angeles, CA
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23
24#include "Noise.hpp"
26#include <boost/random.hpp>
28#include <cstring>
29
30
31using namespace pwiz::util;
32using namespace pwiz::math;
33using namespace pwiz::analysis;
34
35
36ostream* os_ = 0;
37
38
40{
41 boost::mt19937 rng;
42 boost::normal_distribution<> normal(10, 1);
43 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > generator(rng, normal);
44
45 for (int i=0; i<100; i++)
46 {
47 cout << i << ", " << generator() << ", ";
48 if (i%10 == 9) cout << endl;
49 }
50}
51
52
53double testNoise_[] = // generated ~ N(10,1)
54{
55 0, 10.2134, 1, 9.50442, 2, 11.5754, 3, 8.9408, 4, 11.8393, 5, 11.8858, 6, 10.6047, 7, 9.63402, 8, 9.42174, 9, 9.36562,
56 10, 11.0297, 11, 10.7241, 12, 9.88493, 13, 10.6358, 14, 6.99061, 15, 9.08698, 16, 13.2407, 17, 9.11359, 18, 12.5566, 19, 9.42665,
57 20, 10.8823, 21, 11.3452, 22, 12.7695, 23, 9.48237, 24, 10.4651, 25, 9.87172, 26, 8.21869, 27, 10.1641, 28, 10.2608, 29, 9.20198,
58 30, 10.0615, 31, 10.0762, 32, 9.56936, 33, 10.2306, 34, 11.2333, 35, 9.27828, 36, 10.5381, 37, 8.01883, 38, 11.1455, 39, 9.70199,
59 40, 9.00168, 41, 8.51621, 42, 10.9232, 43, 10.2107, 44, 10.4026, 45, 9.43944, 46, 11.3842, 47, 9.39058, 48, 9.56328, 49, 9.09075,
60 50, 10.0799, 51, 8.35904, 52, 9.95105, 53, 8.86625, 54, 9.18384, 55, 10.6562, 56, 9.65414, 57, 9.48778, 58, 10.4029, 59, 10.746,
61 60, 9.51285, 61, 8.28112, 62, 10.8551, 63, 10.1733, 64, 9.65835, 65, 12.0004, 66, 10.5445, 67, 10.1626, 68, 12.6242, 69, 11.8353,
62 70, 10.8273, 71, 8.33673, 72, 9.82429, 73, 9.51358, 74, 9.30484, 75, 11.55, 76, 11.1051, 77, 9.64263, 78, 11.4417, 79, 10.317,
63 80, 9.51919, 81, 10.1948, 82, 9.49461, 83, 10.4654, 84, 10.0316, 85, 9.67727, 86, 10.0763, 87, 9.73844, 88, 10.396, 89, 10.9456,
64 90, 8.89552, 91, 10.0711, 92, 8.91056, 93, 10.3877, 94, 8.92218, 95, 8.58656, 96, 9.43114, 97, 7.82059, 98, 10.0535, 99, 8.1854
65}; // testNoise_
66
67
69{
71 config.zValueCutoff = 10; // high value -> nothing is excluded
72
73 NoiseCalculator_2Pass noiseCalculator(config);
74
75 OrderedPairContainerRef data(testNoise_, testNoise_+sizeof(testNoise_)/sizeof(double));
76 Noise noise = noiseCalculator.calculateNoise(data);
77
78 if (os_)
79 *os_ << "noise ~ N(" << noise.mean << "," << noise.standardDeviation << ")\n";
80
81 const double epsilon = .2;
82 unit_assert_equal(noise.mean, 10, epsilon);
84}
85
86
88{
89 NoiseCalculator_2Pass noiseCalculator;
90
91 vector<double> data;
92 copy(testNoise_, testNoise_+sizeof(testNoise_)/sizeof(double), back_inserter(data));
93
94 // add spikes
95 data[51] += 100;
96 data[101] += 100;
97 data[151] += 100;
98
99 Noise noise = noiseCalculator.calculateNoise(data);
100
101 if (os_)
102 *os_ << "noise ~ N(" << noise.mean << "," << noise.standardDeviation << ")\n";
103
104 const double epsilon = .2;
105 unit_assert_equal(noise.mean, 10, epsilon);
107}
108
109
111{
112 Noise noise(0,1);
113 const double epsilon = .0005;
114 unit_assert_equal(noise.pvalue(1), .159, epsilon);
115 unit_assert_equal(noise.pvalue(2), .023, epsilon);
116 unit_assert_equal(noise.pvalue(3), .001, epsilon);
117}
118
119
120void test()
121{
123 test_2Pass();
124 test_pvalue();
125}
126
127
128int main(int argc, char* argv[])
129{
130 TEST_PROLOG(argc, argv)
131
132 try
133 {
134 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
135 test();
136 }
137 catch (exception& e)
138 {
139 TEST_FAILED(e.what())
140 }
141 catch (...)
142 {
143 TEST_FAILED("Caught unknown exception.")
144 }
145
147}
148
int main(int argc, char *argv[])
void generateNoise()
Definition NoiseTest.cpp:39
double testNoise_[]
Definition NoiseTest.cpp:53
void test_2Pass_NoSignal()
Definition NoiseTest.cpp:68
ostream * os_
Definition NoiseTest.cpp:36
void test_pvalue()
void test_2Pass()
Definition NoiseTest.cpp:87
void test()
virtual Noise calculateNoise(const math::OrderedPairContainerRef &pairs) const
wrapper class for accessing contiguous data as a container of OrderedPairs; note that it does not own...
const double epsilon
Definition DiffTest.cpp:41
double pvalue(double value) const
double standardDeviation
Definition Noise.hpp:39
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175