A common interface for 1-out-of-N classifiers. More...
#include <clsfy_random_classifier.h>
Public Member Functions | |
clsfy_random_classifier () | |
virtual | ~clsfy_random_classifier () |
virtual void | class_probabilities (vcl_vector< double > &outputs, const vnl_vector< double > &input) const |
Return the probability the input being in each class. | |
virtual double | log_l (const vnl_vector< double > &input) const |
Log likelihood of being in class (binary classifiers only). | |
virtual unsigned | n_classes () const |
The number of possible output classes. | |
virtual unsigned | n_dims () const |
The dimensionality of input vectors. | |
virtual vcl_string | is_a () const |
Name of the class. | |
virtual bool | is_class (vcl_string const &s) const |
Name of the class. | |
virtual clsfy_classifier_base * | clone () const |
Create a copy on the heap and return base class pointer. | |
virtual void | print_summary (vcl_ostream &os) const |
Print class to os. | |
virtual void | b_write (vsl_b_ostream &bfs) const |
Save class to binary file stream. | |
virtual void | b_read (vsl_b_istream &bfs) |
Load class from binary file stream. | |
const vcl_vector< double > & | probs () const |
The probabilities of returning a value in each class. | |
void | set_probs (const vcl_vector< double > &) |
Set the prior probabilities of each class. | |
void | set_n_dims (unsigned) |
Set the number of dimensions the classifier reports that it uses. | |
double | confidence () const |
The mean confidence noise added to class probabilities. | |
void | set_confidence (double) |
Set the mean of confidence noise added to class probabilities. | |
virtual void | reseed (unsigned long) |
Reseeds the internal random number generator. | |
virtual unsigned | classify (const vnl_vector< double > &input) const |
Classify the input vector. | |
virtual void | classify_many (vcl_vector< unsigned > &outputs, mbl_data_wrapper< vnl_vector< double > > &inputs) const |
Classify many input vectors. | |
Private Member Functions | |
void | calc_min_to_win () |
Calculate the minimum value each class probability needs to be biased by to win. | |
Private Attributes | |
vcl_vector< double > | probs_ |
The probabilities of each class. | |
double | confidence_ |
The mean confidence noise added to class probabilities. | |
unsigned | n_dims_ |
The classifier may get asked this. | |
vnl_vector< double > | last_inputs_ |
Give the same answers if the same vector is presented twice in a row. | |
vcl_vector< double > | last_outputs_ |
The last class probabilities calculated. | |
vnl_random | rng_ |
The random number generator used to sample classes. | |
vcl_vector< double > | min_to_win_ |
The minimum value each class probability needs to be biased by to win. |
A common interface for 1-out-of-N classifiers.
This class takes a vector and classifies into one of N classes.
And derived classes with binary in the name indicates that the classifier works with only two classes, 0 and 1.
Definition at line 33 of file clsfy_random_classifier.h.
clsfy_random_classifier::clsfy_random_classifier | ( | ) |
Definition at line 25 of file clsfy_random_classifier.cxx.
virtual clsfy_random_classifier::~clsfy_random_classifier | ( | ) | [inline, virtual] |
Definition at line 40 of file clsfy_random_classifier.h.
void clsfy_random_classifier::b_read | ( | vsl_b_istream & | bfs | ) | [virtual] |
Load class from binary file stream.
Implements clsfy_classifier_base.
Definition at line 76 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual] |
Save class to binary file stream.
Implements clsfy_classifier_base.
Definition at line 65 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::calc_min_to_win | ( | ) | [private] |
Calculate the minimum value each class probability needs to be biased by to win.
Definition at line 121 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::class_probabilities | ( | vcl_vector< double > & | outputs, |
const vnl_vector< double > & | input | ||
) | const [virtual] |
Return the probability the input being in each class.
output(i) i<nClasses, contains the probability that the input is in class i
Implements clsfy_classifier_base.
Definition at line 181 of file clsfy_random_classifier.cxx.
unsigned clsfy_classifier_base::classify | ( | const vnl_vector< double > & | input | ) | const [virtual, inherited] |
Classify the input vector.
returns a number between 0 and nClasses-1 inclusive to represent the most likely class
Reimplemented in clsfy_binary_tree, clsfy_direct_boost, clsfy_simple_adaboost, clsfy_rbf_svm, clsfy_rbf_parzen, clsfy_binary_pdf_classifier, clsfy_k_nearest_neighbour, clsfy_binary_1d_wrapper, clsfy_binary_hyperplane, and clsfy_random_forest.
Definition at line 21 of file clsfy_classifier_base.cxx.
void clsfy_classifier_base::classify_many | ( | vcl_vector< unsigned > & | outputs, |
mbl_data_wrapper< vnl_vector< double > > & | inputs | ||
) | const [virtual, inherited] |
Classify many input vectors.
Definition at line 55 of file clsfy_classifier_base.cxx.
clsfy_classifier_base * clsfy_random_classifier::clone | ( | ) | const [virtual] |
Create a copy on the heap and return base class pointer.
Implements clsfy_classifier_base.
Definition at line 46 of file clsfy_random_classifier.cxx.
double clsfy_random_classifier::confidence | ( | ) | const |
The mean confidence noise added to class probabilities.
Definition at line 99 of file clsfy_random_classifier.cxx.
vcl_string clsfy_random_classifier::is_a | ( | ) | const [virtual] |
Name of the class.
Reimplemented from clsfy_classifier_base.
Definition at line 32 of file clsfy_random_classifier.cxx.
bool clsfy_random_classifier::is_class | ( | vcl_string const & | s | ) | const [virtual] |
Name of the class.
Reimplemented from clsfy_classifier_base.
Definition at line 39 of file clsfy_random_classifier.cxx.
double clsfy_random_classifier::log_l | ( | const vnl_vector< double > & | input | ) | const [virtual] |
Log likelihood of being in class (binary classifiers only).
class probability = 1 / (1+exp(-log_l)) Operation of this method is undefined for multiclass classifiers
class probability = 1 / (1+exp(-log_l)) Operation of this method is undefined for multiclass classifiers.
Implements clsfy_classifier_base.
Definition at line 216 of file clsfy_random_classifier.cxx.
unsigned clsfy_random_classifier::n_classes | ( | ) | const [virtual] |
The number of possible output classes.
Implements clsfy_classifier_base.
Definition at line 172 of file clsfy_random_classifier.cxx.
unsigned clsfy_random_classifier::n_dims | ( | ) | const [virtual] |
The dimensionality of input vectors.
Implements clsfy_classifier_base.
Definition at line 164 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::print_summary | ( | vcl_ostream & | os | ) | const [virtual] |
Print class to os.
Implements clsfy_classifier_base.
Definition at line 54 of file clsfy_random_classifier.cxx.
const vcl_vector< double > & clsfy_random_classifier::probs | ( | ) | const |
The probabilities of returning a value in each class.
Definition at line 114 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::reseed | ( | unsigned long | seed | ) | [virtual] |
Reseeds the internal random number generator.
To achieve quasi-random initialisation use
#include <vcl_ctime.h>
..
sampler.reseed(vcl_time(0));
Definition at line 226 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::set_confidence | ( | double | confidence | ) |
Set the mean of confidence noise added to class probabilities.
If the value is 0.0, then the probability of the winning class, will only be just large enough to guarantee the win. Larger values will allow more confident winning class probabilities - however each actual confidence increase is random.
Definition at line 106 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::set_n_dims | ( | unsigned | n_dims | ) |
Set the number of dimensions the classifier reports that it uses.
The classifier itself pays no attention to this value, but it may be useful for other error checking code which calls n_dims()
Definition at line 156 of file clsfy_random_classifier.cxx.
void clsfy_random_classifier::set_probs | ( | const vcl_vector< double > & | probs | ) |
Set the prior probabilities of each class.
The values are normalised to sum to 1.
Definition at line 141 of file clsfy_random_classifier.cxx.
double clsfy_random_classifier::confidence_ [private] |
The mean confidence noise added to class probabilities.
Definition at line 116 of file clsfy_random_classifier.h.
vnl_vector<double> clsfy_random_classifier::last_inputs_ [mutable, private] |
Give the same answers if the same vector is presented twice in a row.
Definition at line 122 of file clsfy_random_classifier.h.
vcl_vector<double> clsfy_random_classifier::last_outputs_ [mutable, private] |
The last class probabilities calculated.
Definition at line 125 of file clsfy_random_classifier.h.
vcl_vector<double> clsfy_random_classifier::min_to_win_ [private] |
The minimum value each class probability needs to be biased by to win.
Definition at line 131 of file clsfy_random_classifier.h.
unsigned clsfy_random_classifier::n_dims_ [private] |
The classifier may get asked this.
Definition at line 119 of file clsfy_random_classifier.h.
vcl_vector<double> clsfy_random_classifier::probs_ [private] |
The probabilities of each class.
The values will always sum to 1. If the vector is empty then the builder will use the prior probability
Definition at line 113 of file clsfy_random_classifier.h.
vnl_random clsfy_random_classifier::rng_ [mutable, private] |
The random number generator used to sample classes.
Definition at line 128 of file clsfy_random_classifier.h.