Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
ProductModel.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 
36 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_PRODUCTMODEL_H
37 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_PRODUCTMODEL_H
38 
41 #include <OpenMS/KERNEL/Peak2D.h>
44 
45 namespace OpenMS
46 {
47 
60  template <UInt D>
61  class ProductModel;
62 
64  template <>
65  class OPENMS_DLLAPI ProductModel<2>:
66  public BaseModel<2>
67  {
68 public:
69 
71  enum {D = 2};
72 
73  typedef double IntensityType;
76 
79  BaseModel<D>(),
80  distributions_(D, 0)
81  {
82  this->setName(this->getProductName());
83 
84  //Register model info
85  for (UInt dim = 0; dim < D; ++dim)
86  {
88  this->subsections_.push_back(name);
89  this->defaults_.setValue(name, "GaussModel", "Name of the model used for this dimension");
90  }
91 
92  //defaults
93  this->defaults_.setValue("intensity_scaling", 1.0, "Scaling factor used to adjust the model distribution to the intensities of the data");
94  this->defaultsToParam_();
95  }
96 
98  ProductModel(const ProductModel & source) :
99  BaseModel<D>(source),
100  distributions_(D, 0),
101  scale_(source.scale_)
102  {
103  for (UInt dim = 0; dim < D; ++dim)
104  {
105  // clone source model
106  if (source.distributions_[dim])
107  {
108  ModelDescription<1> desc(source.distributions_[dim]);
109  setModel(dim, desc.createModel());
110  }
111  }
112  updateMembers_();
113  }
114 
116  virtual ~ProductModel()
117  {
118  for (Size dim = 0; dim < D; ++dim)
119  {
120  delete distributions_[dim];
121  }
122  }
123 
125  virtual ProductModel & operator=(const ProductModel & source)
126  {
127  if (&source == this) return *this;
128 
129  BaseModel<D>::operator=(source);
130  scale_ = source.scale_;
131 
132  for (UInt dim = 0; dim < D; ++dim)
133  {
134  if (source.distributions_[dim])
135  {
136  // clone source model
137  ModelDescription<1> desc(source.distributions_[dim]);
138  setModel(dim, desc.createModel());
139  }
140  else
141  {
142  distributions_[dim] = 0;
143  }
144  }
145  updateMembers_();
146 
147  return *this;
148  }
149 
151  IntensityType getIntensity(const PositionType & pos) const
152  {
153  IntensityType intens(scale_);
154  for (UInt dim = 0; dim < D; ++dim)
155  {
156  if (distributions_[dim] == 0)
157  {
158  throw Exception::BaseException(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, String("ProductModel: model for dimension ") + dim + " not set.", "");
159  }
160  intens *= distributions_[dim]->getIntensity(pos[dim]);
161  }
162  return intens;
163  }
164 
166  static BaseModel<D> * create()
167  {
168  return new ProductModel<D>();
169  }
170 
172  static const String getProductName()
173  {
174  return String("ProductModel") + D + "D";
175  }
176 
185  {
186  OPENMS_PRECONDITION(dim < D, "ProductModel<D>:getModel(Position): index overflow!");
187  if (dist == 0 || dist == distributions_[dim])
188  {
189  return *this;
190  }
191 
192  delete distributions_[dim];
193  distributions_[dim] = dist;
194 
195  // Update model info
197  this->param_.removeAll(name + ':');
198  this->param_.insert(name + ':', distributions_[dim]->getParameters());
199  this->param_.setValue(name, distributions_[dim]->getName());
200 
201  return *this;
202  }
203 
205  {
206  OPENMS_PRECONDITION(dim < D, "ProductModel<D>:getModel(Position): index overflow!");
207  return distributions_[dim];
208  }
209 
211  IntensityType getScale() const
212  {
213  return scale_;
214  }
215 
217  void setScale(IntensityType scale)
218  {
219  this->setCutOff(this->getCutOff() / scale_); // remove scaling from cutoff
220  scale_ = scale;
221  this->param_.setValue("intensity_scaling", scale);
222  this->setCutOff(this->getCutOff() * scale_); // scale cutoff
223  }
224 
226  void getSamples(SamplesType & cont) const
227  {
228  cont.clear();
229  typedef BaseModel<1>::SamplesType Samples1D;
230  std::vector<Samples1D> samples(D);
231  // get samples for each dimension
232  for (Size dim = 0; dim < D; ++dim)
233  {
234  distributions_[dim]->getSamples(samples[dim]);
235  }
236 
238  std::vector<UInt> i(D, 0); // index vector
239 
240  while (i[D - 1] < samples[D - 1].size())
241  {
242  for (UInt dim = 0; dim < D; ++dim)
243  {
244  peak.getPosition()[dim] = samples[dim][i[dim]].getPosition()[0];
245  }
246  fillIntensity(peak);
247  cont.push_back(peak);
248 
249  ++i[0];
250  for (Size dim = 0; dim < D - 1; ++dim)
251  {
252  if (i[dim] >= samples[dim].size())
253  {
254  i[dim] = 0;
255  ++i[dim + 1];
256  }
257  }
258  }
259  return;
260  }
261 
262 protected:
264  {
266  scale_ = (double)(this->param_.getValue("intensity_scaling"));
267  for (UInt dim = 0; dim < D; ++dim)
268  {
270  if (this->param_.exists(name))
271  {
272  delete distributions_[dim];
273  distributions_[dim] = Factory<BaseModel<1> >::create(this->param_.getValue(name));
274  Param copy = this->param_.copy(name + ":", true);
275  distributions_[dim]->setParameters(copy);
276  if (distributions_[dim]->getName().hasSubstring("IsotopeModel"))
277  {
278  static_cast<IsotopeModel *>(distributions_[dim])->setSamples(static_cast<IsotopeModel *>(distributions_[dim])->getFormula());
279  }
280  }
281  }
282  }
283 
284  std::vector<BaseModel<1> *> distributions_;
285  IntensityType scale_;
286  };
287 }
288 
289 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_PRODUCTMODEL_H
ProductModel & setModel(UInt dim, BaseModel< 1 > *dist)
set model dist for dimension dim
Definition: ProductModel.h:184
A more convenient string class.
Definition: String.h:57
ProductModel(const ProductModel &source)
copy constructor
Definition: ProductModel.h:98
virtual ProductModel & operator=(const ProductModel &source)
assignment operator
Definition: ProductModel.h:125
Isotope distribution approximated using linear interpolation.
Definition: IsotopeModel.h:59
void getSamples(SamplesType &cont) const
get reasonable set of samples from the model (i.e. for printing)
Definition: ProductModel.h:226
IntensityType getIntensity(const PositionType &pos) const
intensity equals product of intensities in each dimension
Definition: ProductModel.h:151
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:107
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
Returns FactoryProduct* based on the name of the desired concrete FactoryProduct. ...
Definition: Factory.h:61
double IntensityType
Definition: ProductModel.h:73
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
DPosition< D > PositionType
Definition: ProductModel.h:74
BaseModel< D > * createModel()
Definition: ModelDescription.h:97
virtual void updateMembers_()
This method is used to update extra member variables at the end of the setParameters() method...
Definition: BaseModel.h:158
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
static char const * shortDimensionName(UInt const dim)
Short name of the dimension (abbreviated form)
ProductModel()
Default constructor.
Definition: ProductModel.h:78
BaseModel< D >::SamplesType SamplesType
Definition: ProductModel.h:75
Exception base class.
Definition: Exception.h:90
void setScale(IntensityType scale)
set the intensity scaling factor
Definition: ProductModel.h:217
Management and storage of parameters / INI files.
Definition: Param.h:75
std::vector< BaseModel< 1 > * > distributions_
Definition: ProductModel.h:284
virtual ~ProductModel()
destructor
Definition: ProductModel.h:116
Stores the name and parameters of a model.
Definition: ModelDescription.h:54
IntensityType scale_
Definition: ProductModel.h:285
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
Class for product models i.e. models with D independent dimensions.
Definition: ProductModel.h:61
Abstract base class for all D-dimensional models.
Definition: BaseModel.h:51
void updateMembers_()
This method is used to update extra member variables at the end of the setParameters() method...
Definition: ProductModel.h:263
BaseModel< 1 > * getModel(UInt dim) const
Definition: ProductModel.h:204
static const String getProductName()
Returns the name of the model.
Definition: ProductModel.h:172
IntensityType getScale() const
return the intensity scaling factor
Definition: ProductModel.h:211
std::vector< PeakType > SamplesType
Definition: BaseModel.h:61
virtual BaseModel & operator=(const BaseModel &source)
assignment operator
Definition: BaseModel.h:84
DPeak< D >::Type PeakType
Definition: BaseModel.h:60
static BaseModel< D > * create()
create new ProductModel object (needed by Factory)
Definition: ProductModel.h:166

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