-
-
Notifications
You must be signed in to change notification settings - Fork 3
sonar_tutorial_part2
Now let's backtrack a little bit. Somehow we have obtained an interesting individual, the accuracy and/or other performance measurements are promising and we would like to use it to make predictions.
Example examples/sonar02.cc explains how to proceed:
const auto predictor(s.predictor(result.best_individual)); const auto example(random::element(prob.data.selected())); const auto prediction(predictor->tag(example.input)); std::cout << "Correct class: " << src::label(example) << " Prediction: " << prediction.label << " Sureness: " << prediction.sureness << '\n';
The ultra::src::search class provides the predictor(individual) member function that returns a functor exploitable for symbolic regression and classification tasks.
The key definition is:
const auto predictor(s.predictor(result.best_individual));
The predictor object is a std::unique_ptr<some strange object> smart pointer but this isn't very important. Rather it accepts an example (src::example) and gives the predicted class ((*predictor)(example)).
Even better it has the tag member functions:
const auto prediction(predictor->tag(example.input));
prediction is a struct containing the predicted class (prediction.label) and the sureness of the prediction (prediction.sureness which varies in the [0, 1] interval):
std::cout << "Correct class: " << src::label(example) << " Prediction: " << prediction.label << " Sureness: " << prediction.sureness << '\n';
The model can be made persistent:
std::stringstream ss; src::serialize::save(ss, predictor); // save... // ... and reload it when needed. const auto predictor2(src::serialize::oracle::load(ss, prob.sset)); const auto prediction2(predictor2->tag(example.input)); std::cout << " Prediction: " << prediction2.label << " Sureness: " << prediction2.sureness << '\n'; assert(prediction2.label == prediction.label);