IsotopeFitter1D::QualityType IsotopeFitter1D::fit1d(const RawDataArrayType& set, InterpolationModel*& model)
  {
    // Calculate bounding box
    min_ = max_ = set[0].getPos();
    for (UInt pos = 1; pos < set.size(); ++pos)
    {
      CoordinateType tmp = set[pos].getPos();
      if (min_ > tmp)
        min_ = tmp;
      if (max_ < tmp)
        max_ = tmp;
    }

    // Enlarge the bounding box by a few multiples of the standard deviation
    {
      stdev1_ = sqrt(statistics_.variance()) * tolerance_stdev_box_;
      min_ -= stdev1_;
      max_ += stdev1_;
    }

    // build model
    if (charge_ == 0)
    {
      model = static_cast<InterpolationModel*>(Factory<BaseModel<1> >::create("GaussModel"));
      model->setInterpolationStep(interpolation_step_);

      Param tmp;
      tmp.setValue("bounding_box:min", min_);
      tmp.setValue("bounding_box:max", max_);
      tmp.setValue("statistics:variance", statistics_.variance());
      tmp.setValue("statistics:mean", statistics_.mean());
      model->setParameters(tmp);
    }
    else
    {
      model = static_cast<InterpolationModel*>(Factory<BaseModel<1> >::create("IsotopeModel"));

      Param iso_param = this->param_.copy("isotope_model:", true);
      iso_param.removeAll("stdev");
      model->setParameters(iso_param);
      model->setInterpolationStep(interpolation_step_);

      Param tmp;
      tmp.setValue("statistics:mean", statistics_.mean());
      tmp.setValue("charge", static_cast<Int>(charge_));
      tmp.setValue("isotope:mode:GaussianSD", isotope_stdev_);
      tmp.setValue("isotope:maximum", max_isotope_);

      model->setParameters(tmp);
      (static_cast<IsotopeModel*>(model))->setSamples((static_cast<IsotopeModel*>(model))->getFormula());
    }

    // fit offset
    QualityType quality;
    quality = fitOffset_(model, set, stdev1_, stdev1_, interpolation_step_);
    if (boost::math::isnan(quality))
      quality = -1.0;

    return quality;
  }
Exemplo n.º 2
0
  BiGaussFitter1D::QualityType BiGaussFitter1D::fit1d(const RawDataArrayType& set, InterpolationModel*& model)
  {
    // Calculate bounding box
    CoordinateType min_bb = set[0].getPos(), max_bb = set[0].getPos();
    for (UInt pos = 1; pos < set.size(); ++pos)
    {
      CoordinateType tmp = set[pos].getPos();
      if (min_bb > tmp)
        min_bb = tmp;
      if (max_bb < tmp)
        max_bb = tmp;
    }

    // Enlarge the bounding box by a few multiples of the standard deviation
    const CoordinateType stdev1 = sqrt(statistics1_.variance()) * tolerance_stdev_box_;
    const CoordinateType stdev2 = sqrt(statistics2_.variance()) * tolerance_stdev_box_;
    min_bb -= stdev1;
    max_bb += stdev2;


    // build model
    model = static_cast<InterpolationModel*>(Factory<BaseModel<1> >::create("BiGaussModel"));
    model->setInterpolationStep(interpolation_step_);
    Param tmp;
    tmp.setValue("bounding_box:min", min_bb);
    tmp.setValue("bounding_box:max", max_bb);
    tmp.setValue("statistics:mean", statistics1_.mean());
    tmp.setValue("statistics:variance1", statistics1_.variance());
    tmp.setValue("statistics:variance2", statistics2_.variance());
    model->setParameters(tmp);

    // fit offset
    QualityType quality;
    quality = fitOffset_(model, set, stdev1, stdev2, interpolation_step_);
    if (boost::math::isnan(quality))
      quality = -1.0;

    return quality;
  }
Exemplo n.º 3
0
  ExtendedIsotopeFitter1D::QualityType ExtendedIsotopeFitter1D::fit1d(const RawDataArrayType & set, InterpolationModel * & model)
  {
    // build model
    if (charge_ == 0)
    {
      // Calculate bounding box
      min_ = max_ = set[0].getPos();
      for (UInt pos = 1; pos < set.size(); ++pos)
      {
        CoordinateType tmp = set[pos].getPos();
        if (min_ > tmp)
          min_ = tmp;
        if (max_ < tmp)
          max_ = tmp;
      }

      // Enlarge the bounding box by a few multiples of the standard deviation
      {
        stdev1_ = sqrt(statistics_.variance()) * tolerance_stdev_box_;
        min_ -= stdev1_;
        max_ += stdev1_;
      }

      model = static_cast<InterpolationModel *>(Factory<BaseModel<1> >::create("GaussModel"));
      model->setInterpolationStep(interpolation_step_);

      Param tmp;
      tmp.setValue("bounding_box:min", min_);
      tmp.setValue("bounding_box:max", max_);
      tmp.setValue("statistics:variance", statistics_.variance());
      tmp.setValue("statistics:mean", statistics_.mean());
      model->setParameters(tmp);
    }
    else
    {
      model = static_cast<InterpolationModel *>(Factory<BaseModel<1> >::create("ExtendedIsotopeModel"));

      Param iso_param = this->param_.copy("isotope_model:", true);
      iso_param.removeAll("stdev");
      model->setParameters(iso_param);
      model->setInterpolationStep(interpolation_step_);

      Param tmp;
      tmp.setValue("isotope:monoisotopic_mz", monoisotopic_mz_);
      tmp.setValue("charge", static_cast<Int>(charge_));
      tmp.setValue("isotope:stdev", isotope_stdev_);
      tmp.setValue("isotope:maximum", max_isotope_);
      model->setParameters(tmp);
    }


    // calculate pearson correlation
    std::vector<Real> real_data;
    real_data.reserve(set.size());
    std::vector<Real> model_data;
    model_data.reserve(set.size());

    for (Size i = 0; i < set.size(); ++i)
    {
      real_data.push_back(set[i].getIntensity());
      model_data.push_back(model->getIntensity(DPosition<1>(set[i].getPosition())));
    }

    QualityType correlation = Math::pearsonCorrelationCoefficient(real_data.begin(), real_data.end(), model_data.begin(), model_data.end());
    if (boost::math::isnan(correlation))
      correlation = -1.0;

    return correlation;
  }