Go to the documentation of this file.00001
00002
00003 #ifndef clsfy_classifier_base_h_
00004 #define clsfy_classifier_base_h_
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vcl_string.h>
00016 #include <vcl_vector.h>
00017 #include <vnl/vnl_vector.h>
00018 #include <mbl/mbl_data_wrapper.h>
00019 #include <vsl/vsl_binary_io.h>
00020 #include <vcl_iostream.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029 class clsfy_classifier_base
00030 {
00031 public:
00032
00033
00034 clsfy_classifier_base() {}
00035
00036
00037 virtual ~clsfy_classifier_base() {}
00038
00039
00040
00041 virtual unsigned classify(const vnl_vector<double> &input) const;
00042
00043
00044
00045 virtual void class_probabilities(vcl_vector<double> &outputs, const vnl_vector<double> &input) const = 0;
00046
00047
00048 virtual void classify_many(vcl_vector<unsigned> &outputs, mbl_data_wrapper<vnl_vector<double> > &inputs) const;
00049
00050
00051
00052
00053 virtual double log_l(const vnl_vector<double> &input) const = 0;
00054
00055
00056 virtual unsigned n_classes() const = 0;
00057
00058
00059 virtual unsigned n_dims() const = 0;
00060
00061
00062 virtual vcl_string is_a() const;
00063
00064
00065 virtual bool is_class(vcl_string const& s) const;
00066
00067
00068 virtual clsfy_classifier_base* clone() const = 0;
00069
00070
00071 virtual void print_summary(vcl_ostream& os) const = 0;
00072
00073
00074 virtual void b_write(vsl_b_ostream& bfs) const = 0;
00075
00076
00077 virtual void b_read(vsl_b_istream& bfs) = 0;
00078 };
00079
00080
00081 void vsl_add_to_binary_loader(const clsfy_classifier_base& b);
00082
00083
00084 void vsl_b_write(vsl_b_ostream& bfs, const clsfy_classifier_base& b);
00085
00086
00087 void vsl_b_read(vsl_b_istream& bfs, clsfy_classifier_base& b);
00088
00089
00090 vcl_ostream& operator<<(vcl_ostream& os, const clsfy_classifier_base& b);
00091
00092
00093 vcl_ostream& operator<<(vcl_ostream& os, const clsfy_classifier_base* b);
00094
00095
00096 inline void vsl_print_summary(vcl_ostream& os, const clsfy_classifier_base& b)
00097 { os << b;}
00098
00099
00100 inline void vsl_print_summary(vcl_ostream& os, const clsfy_classifier_base* b)
00101 { os << b;}
00102
00103
00104
00105
00106
00107 double clsfy_test_error(const clsfy_classifier_base &classifier,
00108 mbl_data_wrapper<vnl_vector<double> > & test_inputs,
00109 const vcl_vector<unsigned> & test_outputs);
00110
00111
00112
00113 double clsfy_test_error(const clsfy_classifier_base &classifier,
00114 mbl_data_wrapper<vnl_vector<double> > & test_inputs,
00115 const vcl_vector<unsigned> & test_outputs,
00116 unsigned test_class);
00117
00118
00119 #endif // clsfy_classifier_base_h_