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

Method predict

src/openms/source/ANALYSIS/SVM/SimpleSVM.cpp:174–213  ·  view source on GitHub ↗

predict on (subset) of training data

Source from the content-addressed store, hash-verified

172
173// predict on (subset) of training data
174void SimpleSVM::predict(vector<Prediction>& predictions, vector<Size> indexes) const
175{
176 if (model_ == nullptr)
177 {
178 throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
179 "SVM model has not been trained (use the "
180 "'setup' method)");
181 }
182
183 Size n_obs = nodes_.size();
184 if (indexes.empty())
185 {
186 indexes.reserve(n_obs);
187 for (Size i = 0; i < n_obs; indexes.push_back(i++)){};
188 }
189 Size n_classes = svm_get_nr_class(model_);
190 vector<int> outcomes(n_classes);
191 svm_get_labels(model_, &(outcomes[0]));
192 vector<double> probabilities(n_classes);
193 predictions.clear();
194 predictions.reserve(indexes.size());
195 for (vector<Size>::iterator it = indexes.begin(); it != indexes.end(); ++it)
196 {
197 if (*it >= n_obs)
198 {
199 String msg = "Invalid index for prediction; there are only " +
200 String(n_obs) + " observations.";
201 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
202 msg, String(*it));
203 }
204 Prediction pred;
205 pred.outcome = svm_predict_probability(model_, &(nodes_[*it][0]),
206 &(probabilities[0]));
207 for (Size i = 0; i < n_classes; ++i)
208 {
209 pred.probabilities[outcomes[i]] = probabilities[i];
210 }
211 predictions.push_back(pred);
212 }
213}
214
215void scaleDataUsingTrainingRanges(SimpleSVM::PredictorMap& predictors, const map<String, pair<double, double>>& scaling)
216{

Callers 5

quantifyFraction_Method · 0.45
classifyFeatures_Method · 0.45
SimpleSVM_test.cppFile · 0.45
START_SECTIONFunction · 0.45

Calls 9

StringClass · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

START_SECTIONFunction · 0.36