Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
AsymmetricStatistics.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_MATH_STATISTICS_ASYMMETRICSTATISTICS_H
36 #define OPENMS_MATH_STATISTICS_ASYMMETRICSTATISTICS_H
37 
38 #include <OpenMS/CONCEPT/Types.h>
40 
41 #include <vector>
42 #include <ostream>
43 #include <cmath>
44 
45 namespace OpenMS
46 {
47  namespace Math
48  {
49 
58  template <typename RealT = double>
60  public BasicStatistics<RealT>
61  {
64  typedef typename Base::RealType RealType;
65 
66  using Base::clear;
67  using Base::sum_;
68  using Base::mean_;
69  using Base::variance_;
70 
71 public:
72 
75  BasicStatistics<>(),
76  variance1_(0),
77  variance2_(0)
78  {}
79 
81  RealType variance1() const
82  {
83  return variance1_;
84  }
85 
87  RealType variance2() const
88  {
89  return variance2_;
90  }
91 
93  template <typename ProbabilityIterator, typename CoordinateIterator>
94  void update(ProbabilityIterator const probability_begin,
95  ProbabilityIterator const probability_end,
96  CoordinateIterator const coordinate_begin)
97  {
98  // reuse...
99  Base::update(probability_begin, probability_end, coordinate_begin);
100 
101  const RealType stdev = std::sqrt(variance_);
102 
103  RealType sum1 = 0;
104  RealType sum2 = 0;
105  variance1_ = 0;
106  variance2_ = 0;
107  ProbabilityIterator prob_iter = probability_begin;
108  CoordinateIterator coord_iter = coordinate_begin;
109  for (; prob_iter != probability_end; ++prob_iter, ++coord_iter)
110  {
111  RealType diff = *coord_iter - mean_;
112  RealType diff_squared = diff * diff;
113 
114  if (diff_squared > variance_)
115  {
116  if (*coord_iter < mean_)
117  {
118  variance1_ += (*prob_iter * diff_squared);
119  sum1 += *prob_iter;
120  }
121  else // ( *coord_iter > mean_ )
122  {
123  variance2_ += (*prob_iter * diff_squared);
124  sum2 += *prob_iter;
125  }
126  }
127  else
128  {
129  RealType frac = (diff / stdev + 1.) / 2.;
130  RealType prob_frac = frac * *prob_iter;
131  variance2_ += prob_frac * diff_squared;
132  sum2 += prob_frac;
133  prob_frac = *prob_iter * (1. - frac);
134  variance1_ += prob_frac * diff_squared;
135  sum1 += prob_frac;
136  }
137  }
138  variance1_ /= sum1;
139  variance2_ /= sum2;
140  return;
141  }
142 
143 protected:
146  };
147 
148  } // namespace Math
149 
150 } // namespace OpenMS
151 
152 #endif // OPENMS_MATH_STATISTICS_ASYMMETRICSTATISTICS_H
RealType variance_
Definition: BasicStatistics.h:258
void update(ProbabilityIterator const probability_begin, ProbabilityIterator const probability_end, CoordinateIterator const coordinate_begin)
You can call this as often as you like, using different input vectors.
Definition: AsymmetricStatistics.h:94
RealType mean_
Definition: BasicStatistics.h:257
BasicStatistics< RealT > Base
The real type and basic statistics specified as template argument.
Definition: AsymmetricStatistics.h:63
void update(ProbabilityIterator probability_begin, ProbabilityIterator const probability_end)
This does the actual calculation.
Definition: BasicStatistics.h:114
Internal class for asymmetric distributions.
Definition: AsymmetricStatistics.h:59
AsymmetricStatistics()
Default constructor.
Definition: AsymmetricStatistics.h:74
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Calculates some basic statistical parameters of a distribution: sum, mean, variance, and provides the normal approximation.
Definition: BasicStatistics.h:68
RealType variance1_
Definition: AsymmetricStatistics.h:145
RealType variance2_
Definition: AsymmetricStatistics.h:145
RealType variance2() const
"variance to the right hand side"
Definition: AsymmetricStatistics.h:87
RealType variance1() const
"variance to the left hand side"
Definition: AsymmetricStatistics.h:81
void clear()
Set sum, mean, and variance to zero.
Definition: BasicStatistics.h:104
RealType sum_
Definition: BasicStatistics.h:259
RealT RealType
The real type specified as template argument.
Definition: BasicStatistics.h:75
Base::RealType RealType
Definition: AsymmetricStatistics.h:64

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13