68 template <
typename Container = MSSpectrum>
95 this->
setName(
"SignalToNoiseEstimatorMeanIterative");
97 defaults_.
setValue(
"max_intensity", -1,
"maximal intensity considered for histogram construction. By default, it will be calculated automatically (see auto_mode)." \
98 " Only provide this parameter if you know what you are doing (and change 'auto_mode' to '-1')!" \
99 " All intensities EQUAL/ABOVE 'max_intensity' will not be added to the histogram." \
100 " If you choose 'max_intensity' too small, the noise estimate might be too small as well." \
101 " If chosen too big, the bins become quite large (which you could counter by increasing 'bin_count', which increases runtime).", ListUtils::create<String>(
"advanced"));
104 defaults_.
setValue(
"auto_max_stdev_factor", 3.0,
"parameter for 'max_intensity' estimation (if 'auto_mode' == 0): mean + 'auto_max_stdev_factor' * stdev", ListUtils::create<String>(
"advanced"));
109 defaults_.
setValue(
"auto_max_percentile", 95,
"parameter for 'max_intensity' estimation (if 'auto_mode' == 1): auto_max_percentile th percentile", ListUtils::create<String>(
"advanced"));
113 defaults_.
setValue(
"auto_mode", 0,
"method to use to determine maximal intensity: -1 --> use 'max_intensity'; 0 --> 'auto_max_stdev_factor' method (default); 1 --> 'auto_max_percentile' method", ListUtils::create<String>(
"advanced"));
123 defaults_.
setValue(
"stdev_mp", 3.0,
"multiplier for stdev", ListUtils::create<String>(
"advanced"));
127 defaults_.
setValue(
"min_required_elements", 10,
"minimum number of elements required in a window (otherwise it is considered sparse)");
130 defaults_.
setValue(
"noise_for_empty_window", std::pow(10.0, 20),
"noise value used for sparse windows", ListUtils::create<String>(
"advanced"));
148 if (&source ==
this)
return *
this;
174 double sparse_window_percent = 0;
195 OPENMS_PRETTY_FUNCTION,
196 "auto_mode is on AUTOMAXBYPERCENT! auto_max_percentile is not in [0,100]. Use setAutoMaxPercentile(<value>) to change it!",
200 std::vector<int> histogram_auto(100, 0);
206 while (run != scan_last_)
208 maxInt = std::max(maxInt, (*run).getIntensity());
213 double bin_size = maxInt / 100;
217 while (run != scan_last_)
219 ++histogram_auto[(int) (((*run).getIntensity() - 1) / bin_size)];
225 int elements_seen = 0;
229 while (run != scan_last_ && elements_seen < elements_below_percentile)
232 elements_seen += histogram_auto[i];
245 OPENMS_PRETTY_FUNCTION,
246 "auto_mode is on MANUAL! max_intensity is <=0. Needs to be positive! Use setMaxIntensity(<value>) or enable auto_mode!",
253 std::cerr <<
"TODO SignalToNoiseEstimatorMedian: the max_intensity_ value should be positive! " <<
max_intensity_ << std::endl;
261 double window_half_size =
win_len_ / 2;
270 bin_value[bin] = (bin + 0.5) * bin_size;
273 int hist_rightmost_bin;
281 int elements_in_window = 0;
282 int window_count = 0;
287 int windows_overall = 0;
289 while (run != scan_last_)
297 while (window_pos_center != scan_last_)
300 while ((*window_pos_borderleft).getMZ() < (*window_pos_center).getMZ() - window_half_size)
303 to_bin = (int) ((std::max((*window_pos_borderleft).getIntensity(), 0.0f)) / bin_size);
307 --elements_in_window;
309 ++window_pos_borderleft;
316 while ((window_pos_borderright != scan_last_)
317 && ((*window_pos_borderright).getMZ() < (*window_pos_center).getMZ() + window_half_size))
321 to_bin = (int) ((std::max((*window_pos_borderright).getIntensity(), 0.0f)) / bin_size);
325 ++elements_in_window;
327 ++window_pos_borderright;
333 ++sparse_window_percent;
341 for (
int i = 0; i < 3; ++i)
345 for (
int bin = 0; bin < hist_rightmost_bin; ++bin)
349 hist_mean += histogram[bin] / (
double) elements_in_window * bin_value[bin];
355 for (
int bin = 0; bin < hist_rightmost_bin; ++bin)
357 double tmp(bin_value[bin] - hist_mean);
358 hist_stdev += histogram[bin] / (
double) elements_in_window * tmp * tmp;
360 hist_stdev = std::sqrt(hist_stdev);
363 int estimate = (int) ((hist_mean + hist_stdev *
stdev_ - 1) / bin_size + 1);
365 hist_rightmost_bin = std::min(estimate,
bin_count_);
369 noise = std::max(1.0, hist_mean);
373 stn_estimates_[*window_pos_center] = (*window_pos_center).getIntensity() / noise;
387 sparse_window_percent = sparse_window_percent * 100 / window_count;
389 if (sparse_window_percent > 20)
391 std::cerr <<
"WARNING in SignalToNoiseEstimatorMeanIterative: " 392 << sparse_window_percent
393 <<
"% of all windows were sparse. You should consider increasing 'win_len' or increasing 'min_required_elements'" 394 <<
" You should also check the MaximalIntensity value (or the parameters for its heuristic estimation)" 395 <<
" If it is too low, then too many high intensity peaks will be discarded, which leads to a sparse window!"
~SignalToNoiseEstimatorMeanIterative() override
Destructor.
Definition: SignalToNoiseEstimatorMeanIterative.h:159
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!...
Definition: DefaultParamHandler.h:156
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
A more convenient string class.
Definition: String.h:57
void computeSTN_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) override
Definition: SignalToNoiseEstimatorMeanIterative.h:171
double auto_max_stdev_Factor_
parameter for initial automatic estimation of "max_intensity_": a stdev multiplier ...
Definition: SignalToNoiseEstimatorMeanIterative.h:421
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:149
void endProgress() const
Ends the progress display.
int min_required_elements_
minimal number of elements a window needs to cover to be used
Definition: SignalToNoiseEstimatorMeanIterative.h:433
SignalToNoiseEstimator< Container >::GaussianEstimate GaussianEstimate
Definition: SignalToNoiseEstimatorMeanIterative.h:88
SignalToNoiseEstimator & operator=(const SignalToNoiseEstimator &source)
Assignment operator.
Definition: SignalToNoiseEstimator.h:91
Container::const_iterator PeakIterator
Definition: SignalToNoiseEstimator.h:64
int bin_count_
number of bins in the histogram
Definition: SignalToNoiseEstimatorMeanIterative.h:429
double variance
mean of estimated Gaussian
Definition: SignalToNoiseEstimator.h:169
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
void updateMembers_() override
overridden function from DefaultParamHandler to keep members up to date, when a parameter is changed ...
Definition: SignalToNoiseEstimatorMeanIterative.h:404
double mean
Definition: SignalToNoiseEstimator.h:168
bool is_result_valid_
flag: set to true if SignalToNoise estimates are calculated and none of the params were changed...
Definition: SignalToNoiseEstimator.h:214
void setMaxInt(const String &key, Int max)
Sets the maximum value for the integer or integer list parameter key.
GaussianEstimate estimate_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) const
calculate mean & stdev of intensities of a spectrum
Definition: SignalToNoiseEstimator.h:174
Estimates the signal/noise (S/N) ratio of each data point in a scan based on an iterative scheme whic...
Definition: SignalToNoiseEstimatorMeanIterative.h:69
protected struct to store parameters my, sigma for a Gaussian distribution
Definition: SignalToNoiseEstimator.h:166
double auto_max_percentile_
parameter for initial automatic estimation of "max_intensity_" percentile or a stdev ...
Definition: SignalToNoiseEstimatorMeanIterative.h:423
double noise_for_empty_window_
Definition: SignalToNoiseEstimatorMeanIterative.h:436
double win_len_
range of data points which belong to a window in Thomson
Definition: SignalToNoiseEstimatorMeanIterative.h:427
SignalToNoiseEstimatorMeanIterative(const SignalToNoiseEstimatorMeanIterative &source)
Copy Constructor.
Definition: SignalToNoiseEstimatorMeanIterative.h:136
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
void setProgress(SignedSize value) const
Sets the current progress.
void setMaxFloat(const String &key, double max)
Sets the maximum value for the floating point or floating point list parameter key.
SignalToNoiseEstimator< Container >::PeakIterator PeakIterator
Definition: SignalToNoiseEstimatorMeanIterative.h:85
PeakIterator::value_type PeakType
Definition: SignalToNoiseEstimator.h:65
SignalToNoiseEstimatorMeanIterative & operator=(const SignalToNoiseEstimatorMeanIterative &source)
Definition: SignalToNoiseEstimatorMeanIterative.h:146
Definition: SignalToNoiseEstimatorMeanIterative.h:76
Invalid value exception.
Definition: Exception.h:335
int auto_mode_
determines which method shall be used for estimating "max_intensity_". valid are MANUAL=-1, AUTOMAXBYSTDEV=0 or AUTOMAXBYPERCENT=1
Definition: SignalToNoiseEstimatorMeanIterative.h:425
SignalToNoiseEstimator< Container >::PeakType PeakType
Definition: SignalToNoiseEstimatorMeanIterative.h:86
Definition: SignalToNoiseEstimatorMeanIterative.h:76
void setMinInt(const String &key, Int min)
Sets the minimum value for the integer or integer list parameter key.
void startProgress(SignedSize begin, SignedSize end, const String &label) const
Initializes the progress display.
This class represents the abstract base class of a signal to noise estimator.
Definition: SignalToNoiseEstimator.h:56
SignalToNoiseEstimatorMeanIterative()
default constructor
Definition: SignalToNoiseEstimatorMeanIterative.h:92
std::map< PeakType, double, typename PeakType::PositionLess > stn_estimates_
stores the noise estimate for each peak
Definition: SignalToNoiseEstimator.h:207
IntensityThresholdCalculation
method to use for estimating the maximal intensity that is used for histogram calculation ...
Definition: SignalToNoiseEstimatorMeanIterative.h:76
double max_intensity_
maximal intensity considered during binning (values above get discarded)
Definition: SignalToNoiseEstimatorMeanIterative.h:419
void setName(const String &name)
Mutable access to the name.
double stdev_
multiplier for the stdev of intensities
Definition: SignalToNoiseEstimatorMeanIterative.h:431
void setMinFloat(const String &key, double min)
Sets the minimum value for the floating point or floating point list parameter key.
void defaultsToParam_()
Updates the parameters after the defaults have been set in the constructor.
Definition: SignalToNoiseEstimatorMeanIterative.h:76