latest version v1.9 - last update 10 Apr 2010 |
This functor creates beautiful pictures. More...
#include <ltiClassifier2DVisualizer.h>
Classes | |
class | parameters |
the parameters for the class classifier2DVisualizer More... | |
Public Member Functions | |
classifier2DVisualizer () | |
classifier2DVisualizer (const classifier2DVisualizer &other) | |
virtual | ~classifier2DVisualizer () |
virtual const char * | getTypeName () const |
bool | apply (const supervisedInstanceClassifier &cls, image &result) const |
bool | apply (const supervisedInstanceClassifier &cls, const lti::dmatrix &highlights, image &result) const |
bool | apply (const supervisedInstanceClassifier &cls, const lti::dmatrix &highlights, image &result, const ivector &labels) const |
bool | apply (const supervisedInstanceClassifier &cls, const lti::dmatrix &highlights, image &result, const ivector &labels, const genericVector< bool > &htype) const |
classifier2DVisualizer & | copy (const classifier2DVisualizer &other) |
classifier2DVisualizer & | operator= (const classifier2DVisualizer &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
This functor creates beautiful pictures.
They additionally have the property that they show the classification properties of a supervisedInstanceClassifier for a 2D feature space. Its application is rather simple: You have to create a classifier for a 2D space, then you give it to one of the apply methods, together with the target image.
Example:
// number of training samples const int N=150; // number of classes const int K=3; const int width=400; const int height=200; // fill data and label matrix lti::dmatrix data(N,2); lti::ivector labels(N); int j=0; std::cerr << "Generating data..."; for (int k=0; k<K; k++) { // generate gaussian double sigma=double(k)/(K)*20.0+10; double mx=double(k)/K*(width-sigma)+sigma; double my=double(k)/K*(height-sigma)+sigma; lti::gaussianDistribution px(mx,sigma); lti::gaussianDistribution py(my,sigma); for (int i=0; i<N/K; i++) { data[j][0]=px.draw(); data[j][1]=py.draw(); labels[j]=k; j++; } } std::cerr << "\nTraining MLP..."; // train MLP lti::MLP s; lti::streamProgressInfo inf(std::cerr,"MLP"); s.setProgressObject(inf); lti::MLP::parameters p=s.getParameters(); s.setParameters(p); if (!s.train(data,labels)) { std::cerr << "Error: " << s.getStatusString() << "\n"; //return; } std::cerr << "\nVisualizing..."; // NOW COMES THE INTERESTING PART: // we need an image lti::image panel; lti::classifier2DVisualizer visual; lti::classifier2DVisualizer::parameters vp; // set the parameters vp.showBoundaries=true; vp.imgSize=point(width,height); vp.upperRight=dpoint(width,height); visual.setParameters(vp); // create the image if (!visual.apply(s,data,panel,labels)) { std::cerr << "Error: " << s.getStatusString() << "\n"; return; } // enjoy!
The visualization result of this example is shown in
lti::classifier2DVisualizer::classifier2DVisualizer | ( | ) |
default constructor
lti::classifier2DVisualizer::classifier2DVisualizer | ( | const classifier2DVisualizer & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::classifier2DVisualizer::~classifier2DVisualizer | ( | ) | [virtual] |
destructor
bool lti::classifier2DVisualizer::apply | ( | const supervisedInstanceClassifier & | cls, | |
const lti::dmatrix & | highlights, | |||
image & | result, | |||
const ivector & | labels, | |||
const genericVector< bool > & | htype | |||
) | const |
Applies the given classifier to the area defined in the parameters object.
The image will contain the visualization result. It also highlights the vectors given in highlights. The color of each highlight is determined by the corresponding value in labels. You can also distinguish between two classes of labels. The label class is determined by the vector htype.
cls | supervisedInstanceClassifier with the classifier to be visualized. The classifier must be able to classify a 2D feature set. | |
highlights | matrix with each row containing a vector that is to be highlighted. | |
result | will receive the visualization result. | |
labels | is a vector with the class labels for each row of highlights. | |
htype | is a vector with a flag denoting the highlight type. |
bool lti::classifier2DVisualizer::apply | ( | const supervisedInstanceClassifier & | cls, | |
const lti::dmatrix & | highlights, | |||
image & | result, | |||
const ivector & | labels | |||
) | const |
Applies the given classifier to the area defined in the parameters object.
The image will contain the visualization result. It also highlights the vectors given in highlights. The color of each highlight is determined by the corresponding value in labels.
cls | supervisedInstanceClassifier with the classifier to be visualized. The classifier must be able to classify a 2D feature set. | |
highlights | matrix with each row containing a vector that is to be highlighted. | |
result | will receive the visualization result. | |
labels | is a vector with the class labels for each row of highlights. |
bool lti::classifier2DVisualizer::apply | ( | const supervisedInstanceClassifier & | cls, | |
const lti::dmatrix & | highlights, | |||
image & | result | |||
) | const |
Applies the given classifier to the area defined in the parameters object.
The image will contain the visualization result. It also highlights the vectors given in highlights.
cls | supervisedInstanceClassifier with the classifier to be visualized. The classifier must be able to classify a 2D feature set. | |
highlights | matrix with each row containing a vector that is to be highlighted. | |
result | will receive the visualization result. |
bool lti::classifier2DVisualizer::apply | ( | const supervisedInstanceClassifier & | cls, | |
image & | result | |||
) | const |
Applies the given classifier to the area defined in the parameters object.
The image will contain the visualization result.
cls | supervisedInstanceClassifier with the classifier to be visualized. The classifier must be able to classify a 2D feature set. | |
result | will receive the visualization result. |
virtual functor* lti::classifier2DVisualizer::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Implements lti::functor.
classifier2DVisualizer& lti::classifier2DVisualizer::copy | ( | const classifier2DVisualizer & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
const parameters& lti::classifier2DVisualizer::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::functor.
virtual const char* lti::classifier2DVisualizer::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("classifier2DVisualizer")
Reimplemented from lti::functor.
classifier2DVisualizer& lti::classifier2DVisualizer::operator= | ( | const classifier2DVisualizer & | other | ) |