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

MaxLikeliFitter1D.h (Maintainer: Marcel Grunert)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Marcel Grunert $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_MAXLIKELIFITTER1D_H
00028 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_MAXLIKELIFITTER1D_H
00029 
00030 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/Fitter1D.h>
00031 #include <OpenMS/MATH/STATISTICS/StatisticFunctions.h>
00032 #include <OpenMS/MATH/STATISTICS/AsymmetricStatistics.h>
00033 
00034 namespace OpenMS
00035 {
00036   
00042     class MaxLikeliFitter1D
00043     : public Fitter1D
00044     {
00045 
00046         public:
00047           
00049           MaxLikeliFitter1D()       
00050           : Fitter1D()
00051           {
00052           }
00053 
00055           MaxLikeliFitter1D(const MaxLikeliFitter1D& source)
00056           : Fitter1D(source)
00057           {
00058           }
00059         
00061           virtual ~MaxLikeliFitter1D()
00062           {
00063           }
00064   
00066           virtual MaxLikeliFitter1D& operator = (const MaxLikeliFitter1D& source)
00067           {
00068               if (&source ==this) return *this;
00069       
00070               Fitter1D::operator = (source);
00071       
00072               return *this;
00073           }
00074     
00075       protected:
00076       
00078           QualityType fitOffset_(InterpolationModel* model, const RawDataArrayType& set, const CoordinateType stdev1, const CoordinateType stdev2, const CoordinateType offset_step)
00079           {
00080               const CoordinateType offset_min = model->getInterpolation().supportMin() - stdev1;
00081               const CoordinateType offset_max = model->getInterpolation().supportMin() + stdev2;
00082       
00083               CoordinateType offset;
00084               QualityType correlation;
00085       
00086               //test model with default offset
00087               std::vector<Real> real_data;
00088               real_data.reserve(set.size());
00089               std::vector<Real> model_data;
00090               model_data.reserve(set.size());
00091               
00092               for (UInt i=0; i < set.size(); ++i)
00093               {
00094                   real_data.push_back(set[i].getIntensity());
00095                   model_data.push_back( model->getIntensity( DPosition<1>(set[i].getPosition()) ) );
00096               }
00097               
00098               CoordinateType max_offset = model->getInterpolation().getOffset();
00099               QualityType max_correlation = Math::pearsonCorrelationCoefficient(real_data.begin(), real_data.end(), model_data.begin(), model_data.end());
00100       
00101               //test different offsets
00102               for ( offset = offset_min; offset <= offset_max; offset += offset_step )
00103               {
00104                   // set offset
00105                   model->setOffset( offset );
00106           
00107                   // get samples
00108                   model_data.clear();
00109                   for (UInt i=0; i < set.size(); ++i)
00110                   {
00111                       model_data.push_back( model->getIntensity( DPosition<1>(set[i].getPosition()) ) );
00112                   }
00113                   
00114                   correlation = Math::pearsonCorrelationCoefficient(real_data.begin(), real_data.end(), model_data.begin(), model_data.end());
00115                   
00116                   if ( correlation > max_correlation )
00117                   {
00118                       max_correlation = correlation;
00119                       max_offset = offset;
00120                   }
00121               }
00122               
00123               model->setOffset( max_offset );
00124               
00125               return max_correlation;
00126           }
00127           
00128           void updateMembers_()
00129           {
00130             Fitter1D::updateMembers_();
00131           }
00132       
00133   };
00134 }
00135 
00136 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_MAXLIKELIFITTER1D_H

Generated Tue Apr 1 15:36:36 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1