MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / fit

Method fit

src/openms/source/MATH/STATISTICS/PosteriorErrorProbabilityModel.cpp:235–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233 }
234
235 bool PosteriorErrorProbabilityModel::fit(std::vector<double>& search_engine_scores, const String& outlier_handling)
236 {
237 // nothing to fit?
238 if (search_engine_scores.empty()) { return false; }
239
240 //-------------------------------------------------------------
241 // Initializing Parameters
242 //-------------------------------------------------------------
243 sort(search_engine_scores.begin(), search_engine_scores.end());
244
245 smallest_score_ = search_engine_scores[0];
246
247 vector<double> x_scores{search_engine_scores};
248
249 //transform to a positive range
250 for (double & d : x_scores)
251 {
252 d += fabs(smallest_score_) + 0.001;
253 }
254
255 processOutliers_(x_scores, outlier_handling);
256
257 negative_prior_ = 0.7;
258 if (param_.getValue("incorrectly_assigned") == "Gumbel")
259 {
260 incorrectly_assigned_fit_param_.x0 = Math::mean(x_scores.begin(), x_scores.begin() + ceil(0.5 * x_scores.size())) + x_scores[0];
261 incorrectly_assigned_fit_param_.sigma = Math::sd(x_scores.begin(), x_scores.end(), incorrectly_assigned_fit_param_.x0);
262 incorrectly_assigned_fit_param_.A = 1.0 / sqrt(2.0 * Constants::PI * pow(incorrectly_assigned_fit_param_.sigma, 2.0));
263 //TODO: Currently, the fit is calculated using the Gauss.
264 getNegativeGnuplotFormula_ = &PosteriorErrorProbabilityModel::getGumbelGnuplotFormula;
265 }
266 else
267 {
268 incorrectly_assigned_fit_param_.x0 = Math::mean(x_scores.begin(), x_scores.begin() + ceil(0.5 * x_scores.size())) + x_scores[0];
269 incorrectly_assigned_fit_param_.sigma = Math::sd(x_scores.begin(), x_scores.end(), incorrectly_assigned_fit_param_.x0);
270 incorrectly_assigned_fit_param_.A = 1.0 / sqrt(2.0 * Constants::PI * pow(incorrectly_assigned_fit_param_.sigma, 2.0));
271 getNegativeGnuplotFormula_ = &PosteriorErrorProbabilityModel::getGaussGnuplotFormula;
272 }
273 getPositiveGnuplotFormula_ = &PosteriorErrorProbabilityModel::getGaussGnuplotFormula;
274
275 Size x_score_start = std::min(x_scores.size() - 1, (Size) ceil(x_scores.size() * 0.7)); // if only one score is present, ceil(...) will yield 1, which is an invalid index
276 correctly_assigned_fit_param_.x0 = Math::mean(x_scores.begin() + x_score_start, x_scores.end()) + x_scores[x_score_start]; //(gauss_scores.begin()->getX() + (gauss_scores.end()-1)->getX())/2;
277 correctly_assigned_fit_param_.sigma = incorrectly_assigned_fit_param_.sigma;
278 correctly_assigned_fit_param_.A = 1.0 / sqrt(2.0 * Constants::PI * pow(correctly_assigned_fit_param_.sigma, 2.0));
279
280 //-------------------------------------------------------------
281 // create files for output
282 //-------------------------------------------------------------
283 bool output_plots = (String(param_.getValue("out_plot").toString()).trim().length() > 0);
284 TextFile file;
285 if (output_plots)
286 {
287 // create output directory (if not already present)
288 QDir dir(String(param_.getValue("out_plot").toString()).toQString());
289 if (!dir.cdUp())
290 {
291 OPENMS_LOG_ERROR << "Could not navigate to output directory for plots from '" << String(dir.dirName()) << "'." << std::endl;
292 return false;

Callers 1

Calls 15

sortFunction · 0.85
sdFunction · 0.85
sumFunction · 0.85
getGumbel_Function · 0.85
meanFunction · 0.50
StringClass · 0.50
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getValueMethod · 0.45
sizeMethod · 0.45
toStringMethod · 0.45

Tested by 1