Beispiel #1
0
/** Calculates Sn as estimator of scale for given vector
  *
  * This method implements a naive calculation of Sn, as defined by Rousseeuw
  *and Croux (http://dx.doi.org/10.2307%2F2291267).
  * In contrast to standard deviation, this is more robust towards outliers.
  *
  * @param begin :: Beginning of vector.
  * @param end :: End of vector.
  * @return Sn of supplied data.
  */
double PoldiPeakSearch::getSn(MantidVec::const_iterator begin,
                              MantidVec::const_iterator end) const {
  size_t numberOfPoints = std::distance(begin, end);
  MantidVec absoluteDifferenceMedians(numberOfPoints);

  PARALLEL_FOR_NO_WSP_CHECK()
  for (int i = 0; i < static_cast<int>(numberOfPoints); ++i) {
    double currentValue = *(begin + i);
    MantidVec temp;
    temp.reserve(numberOfPoints - 1);
    for (int j = 0; j < static_cast<int>(numberOfPoints); ++j) {
      if (j != i) {
        temp.push_back(fabs(*(begin + j) - currentValue));
      }
    }
    std::sort(temp.begin(), temp.end());

    absoluteDifferenceMedians[i] =
        getMedianFromSortedVector(temp.begin(), temp.end());
  }

  std::sort(absoluteDifferenceMedians.begin(), absoluteDifferenceMedians.end());

  return 1.1926 * getMedianFromSortedVector(absoluteDifferenceMedians.begin(),
                                            absoluteDifferenceMedians.end());
}
Beispiel #2
0
/** Computes a background estimation with an error
  *
  * This method computes an estimate of the average background along with its deviation. Since the background does not
  * follow a normal distribution and may contain outliers, instead of computing the average and standard deviation,
  * the median is used as location estimator and Sn is used as scale estimator. For details regarding the latter
  * refer to PoldiPeakSearch::getSn.
  *
  * @param peakPositions :: Peak positions.
  * @param correlationCounts :: Data from which the peak positions were extracted.
  * @return Background estimation with error.
  */
UncertainValue PoldiPeakSearch::getBackgroundWithSigma(std::list<MantidVec::const_iterator> peakPositions, const MantidVec &correlationCounts) const
{
    MantidVec background = getBackground(peakPositions, correlationCounts);

    /* Instead of using Mean and Standard deviation, which are appropriate
     * for data originating from a normal distribution (which is not the case
     * for background of POLDI correlation spectra), the more robust measures
     * Median and Sn are used.
     */
    std::sort(background.begin(), background.end());
    double meanBackground = getMedianFromSortedVector(background.begin(), background.end());
    double sigmaBackground = getSn(background.begin(), background.end());

    return UncertainValue(meanBackground, sigmaBackground);
}