Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

MaxLikeliFitter1D.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Clemens Groepl $
00032 // $Authors: $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_MAXLIKELIFITTER1D_H
00036 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_MAXLIKELIFITTER1D_H
00037 
00038 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/Fitter1D.h>
00039 #include <OpenMS/MATH/STATISTICS/StatisticFunctions.h>
00040 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/InterpolationModel.h>
00041 
00042 namespace OpenMS
00043 {
00044 
00048   class OPENMS_DLLAPI MaxLikeliFitter1D :
00049     public Fitter1D
00050   {
00051 
00052 public:
00053 
00055     MaxLikeliFitter1D() :
00056       Fitter1D()
00057     {
00058     }
00059 
00061     MaxLikeliFitter1D(const MaxLikeliFitter1D & source) :
00062       Fitter1D(source)
00063     {
00064     }
00065 
00067     virtual ~MaxLikeliFitter1D()
00068     {
00069     }
00070 
00072     virtual MaxLikeliFitter1D & operator=(const MaxLikeliFitter1D & source)
00073     {
00074       if (&source == this) return *this;
00075 
00076       Fitter1D::operator=(source);
00077 
00078       return *this;
00079     }
00080 
00081 protected:
00082 
00084     QualityType fitOffset_(InterpolationModel * model, const RawDataArrayType & set, const CoordinateType stdev1, const CoordinateType stdev2, const CoordinateType offset_step)
00085     {
00086       const CoordinateType offset_min = model->getInterpolation().supportMin() - stdev1;
00087       const CoordinateType offset_max = model->getInterpolation().supportMin() + stdev2;
00088 
00089       CoordinateType offset;
00090       QualityType correlation;
00091 
00092       //test model with default offset
00093       std::vector<Real> real_data;
00094       real_data.reserve(set.size());
00095       std::vector<Real> model_data;
00096       model_data.reserve(set.size());
00097 
00098       for (Size i = 0; i < set.size(); ++i)
00099       {
00100         real_data.push_back(set[i].getIntensity());
00101         model_data.push_back(model->getIntensity(DPosition<1>(set[i].getPosition())));
00102       }
00103 
00104       CoordinateType max_offset = model->getInterpolation().getOffset();
00105       QualityType max_correlation = Math::pearsonCorrelationCoefficient(real_data.begin(), real_data.end(), model_data.begin(), model_data.end());
00106 
00107       //test different offsets
00108       for (offset = offset_min; offset <= offset_max; offset += offset_step)
00109       {
00110         // set offset
00111         model->setOffset(offset);
00112 
00113         // get samples
00114         model_data.clear();
00115         for (Size i = 0; i < set.size(); ++i)
00116         {
00117           model_data.push_back(model->getIntensity(DPosition<1>(set[i].getPosition())));
00118         }
00119 
00120         correlation = Math::pearsonCorrelationCoefficient(real_data.begin(), real_data.end(), model_data.begin(), model_data.end());
00121 
00122         if (correlation > max_correlation)
00123         {
00124           max_correlation = correlation;
00125           max_offset = offset;
00126         }
00127       }
00128 
00129       model->setOffset(max_offset);
00130 
00131       return max_correlation;
00132     }
00133 
00134     void updateMembers_()
00135     {
00136       Fitter1D::updateMembers_();
00137     }
00138 
00139   };
00140 }
00141 
00142 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_MAXLIKELIFITTER1D_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:41 using doxygen 1.7.1