-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 oracle(s.oracle(result.best_individual));
const auto example(random::element(prob.data.selected()));
const auto prediction(oracle->tag(example.input));
std::cout << "Correct class: " << src::label(example)
<< " Prediction: " << prediction.label
<< " Sureness: " << prediction.sureness << '\n';
The ultra::src::search
class provides the oracle(individual)
member function that returns a functor exploitable for symbolic regression and classification tasks.
The key definition is:
const auto oracle(s.oracle(result.best_individual));
The oracle
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 ((*oracle)(example)
).
Even better it has the tag
member functions:
const auto prediction(oracle->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, oracle); // save...
// ... and reload it when needed.
const auto oracle2(src::serialize::oracle::load(ss, prob.sset));
const auto prediction2(oracle2->tag(example.input));
std::cout << " Prediction: " << prediction2.label
<< " Sureness: " << prediction2.sureness << '\n';
assert(prediction2.label == prediction.label);