~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TRANSFORMATIONS/FEATUREFINDER/BiGaussFitter1D.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Clemens Groepl $
 
25
// $Authors: $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/BiGaussFitter1D.h>
 
29
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/InterpolationModel.h>
 
30
#include <boost/math/special_functions/fpclassify.hpp>
 
31
namespace OpenMS
 
32
{
 
33
    BiGaussFitter1D::BiGaussFitter1D()                  
 
34
    : MaxLikeliFitter1D()
 
35
    {
 
36
        setName(getProductName());
 
37
    
 
38
        defaults_.setValue("statistics:variance1",1.0,"Variance of the first gaussian, used for the lower half of the model.", StringList::create("advanced"));
 
39
        defaults_.setValue("statistics:variance2",1.0,"Variance of the second gaussian, used for the upper half of the model.", StringList::create("advanced"));
 
40
    
 
41
        defaultsToParam_();
 
42
    }
 
43
                
 
44
    BiGaussFitter1D::BiGaussFitter1D(const BiGaussFitter1D& source)
 
45
    : MaxLikeliFitter1D(source)
 
46
    {
 
47
        updateMembers_();
 
48
    }
 
49
 
 
50
    BiGaussFitter1D::~BiGaussFitter1D()
 
51
    {
 
52
    }
 
53
 
 
54
    BiGaussFitter1D& BiGaussFitter1D::operator = (const BiGaussFitter1D& source)
 
55
    {
 
56
        if (&source == this) return *this;
 
57
    
 
58
        MaxLikeliFitter1D::operator = (source);
 
59
        updateMembers_();
 
60
    
 
61
        return *this;
 
62
    }
 
63
                
 
64
    BiGaussFitter1D::QualityType BiGaussFitter1D::fit1d(const RawDataArrayType& set, InterpolationModel*& model)
 
65
    {
 
66
        // Calculate bounding box
 
67
        min_ = max_ = set[0].getPos();
 
68
        for ( UInt pos=1; pos < set.size(); ++pos)
 
69
        {
 
70
            CoordinateType tmp = set[pos].getPos();
 
71
            if ( min_ > tmp ) min_ = tmp;
 
72
            if ( max_ < tmp ) max_ = tmp;
 
73
        }
 
74
    
 
75
        // Enlarge the bounding box by a few multiples of the standard deviation
 
76
        {
 
77
            stdev1_ = sqrt ( statistics1_.variance() ) * tolerance_stdev_box_;
 
78
            stdev2_ = sqrt ( statistics2_.variance() ) * tolerance_stdev_box_;
 
79
            min_ -= stdev1_;
 
80
            max_ += stdev2_;
 
81
        }
 
82
        
 
83
        // build model
 
84
        model = static_cast<InterpolationModel*> (Factory<BaseModel<1> >::create("BiGaussModel"));
 
85
        model->setInterpolationStep( interpolation_step_ );
 
86
        Param tmp;
 
87
        tmp.setValue( "bounding_box:min", min_ );
 
88
        tmp.setValue( "bounding_box:max", max_ );
 
89
        tmp.setValue( "statistics:mean", statistics1_.mean() );
 
90
        tmp.setValue( "statistics:variance1", statistics1_.variance() );
 
91
        tmp.setValue( "statistics:variance2", statistics2_.variance() );
 
92
        model->setParameters( tmp );
 
93
        
 
94
        // fit offset
 
95
        QualityType quality;
 
96
        quality = fitOffset_(model, set, stdev1_, stdev2_, interpolation_step_);
 
97
        if (boost::math::isnan(quality) ) quality = -1.0;
 
98
        
 
99
        return quality;
 
100
    }
 
101
                
 
102
    void BiGaussFitter1D::updateMembers_()
 
103
    {
 
104
        MaxLikeliFitter1D::updateMembers_();
 
105
        statistics1_.setMean(param_.getValue("statistics:mean"));
 
106
        statistics1_.setVariance(param_.getValue("statistics:variance1"));
 
107
        statistics2_.setMean(param_.getValue("statistics:mean"));
 
108
        statistics2_.setVariance(param_.getValue("statistics:variance2"));
 
109
    }
 
110
 
 
111
}