CGAL 5.1.2 - Classification
|
#include <CGAL/Classification/Sum_of_weighted_features_classifier.h>
Classifier based on the sum of weighted features with user-defined effects on labels.
Public Types | |
enum | Effect { FAVORING = 0, NEUTRAL = 1, PENALIZING = 2 } |
Defines the effect of a feature on a type. More... | |
Constructor | |
Sum_of_weighted_features_classifier (const Label_set &labels, const Feature_set &features) | |
Instantiates the classifier using the sets of labels and features . More... | |
Weights and Effects | |
void | set_weight (Feature_handle feature, float weight) |
Sets the weight of feature (weight must be positive). | |
float | weight (Feature_handle feature) const |
Returns the weight of feature . | |
void | set_effect (Label_handle label, Feature_handle feature, Effect effect) |
Sets the effect of feature on label . | |
Effect | effect (Label_handle label, Feature_handle feature) const |
Returns the effect of feature on label . | |
Training | |
template<typename ConcurrencyTag , typename LabelIndexRange > | |
float | train (const LabelIndexRange &ground_truth, unsigned int nb_tests=300) |
Runs the training algorithm. More... | |
Input/Output | |
void | save_configuration (std::ostream &output) |
Saves the current configuration in the stream output . More... | |
bool | load_configuration (std::istream &input, bool verbose=false) |
Loads a configuration from the stream input . More... | |
CGAL::Classification::Sum_of_weighted_features_classifier::Sum_of_weighted_features_classifier | ( | const Label_set & | labels, |
const Feature_set & | features | ||
) |
Instantiates the classifier using the sets of labels
and features
.
bool CGAL::Classification::Sum_of_weighted_features_classifier::load_configuration | ( | std::istream & | input, |
bool | verbose = false |
||
) |
Loads a configuration from the stream input
.
A configuration is a set of weights and effects.
The input file should be in the XML format written by the save_configuration()
method. Labels and features are described in the XML file by their name and the corresponding Label
and Feature_base
object should therefore be given the same names as the ones they had when saving the configuration.
Feature_set
(Label_set
) provided by the user in the constructor, and if verbose
is set up to true
, a warning is displayed.NEUTRAL
for the effect).input | input stream. |
verbose | displays warning if set to true . The method is silent otherwise. |
true
if all weights and effects found in the configuration file were applicable to the feature set and label set of this classifier, false
otherwise. void CGAL::Classification::Sum_of_weighted_features_classifier::save_configuration | ( | std::ostream & | output | ) |
Saves the current configuration in the stream output
.
This allows to easily save and recover a specific classification configuration, that is to say:
The output file is written in an XML format that is readable by the load_configuration()
method.
float CGAL::Classification::Sum_of_weighted_features_classifier::train | ( | const LabelIndexRange & | ground_truth, |
unsigned int | nb_tests = 300 |
||
) |
Runs the training algorithm.
From the set of provided ground truth, this algorithm estimates the sets of weights and effects that produce the most accurate result with respect to this ground truth. Old weights and effects are discarded.
ground_truth | vector of label indices. It should contain for each input item, in the same order as the input set, the index of the corresponding label in the Label_set provided in the constructor. Input items that do not have a ground truth information should be given the value -1 . |
nb_tests | number of tests to perform. Higher values may provide the user with better results at the cost of a higher computation time. Using a value of at least 10 times the number of features is advised. |