OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 11 Apr 2016 08:03:10 -0500Why does LDA reduction give only one dimension for two classes?http://answers.opencv.org/question/92470/why-does-lda-reduction-give-only-one-dimension-for-two-classes/ Hi,
I'm trying to reduce data from two classes with the Linear Discriminant Analysis algorithm ([LDA opencv documentation here](http://docs.opencv.org/3.0.0/db/d59/classcv_1_1LDA.html)).
Here is a short example of what I'm trying to accomplish:
LDA lda(num_components);
lda.compute(someData, classesLabels); //Computes LDA algorithm to find the best projection
Mat reductedData = lda.project(someData); //Reduces input data
Let's say I've 100 dimensions per sample as input and I want to get 50 after reduction. If I'm correctly understanding the documentation ([here](http://docs.opencv.org/3.0.0/db/d59/classcv_1_1LDA.html#a6d654ebfab272bf734a6ffa35b3ce908)), num_components should be the number of kept dimensions.
However I'm obtaining only one dimension regardless of the number I give to the LDA constructor.
I looked at the LDA source code ([here](https://github.com/Itseez/opencv/blob/master/modules/core/src/lda.cpp#L984)) which explains this behaviour :
...
// number of unique labels
int C = (int)num2label.size();
...
...
// clip number of components to be a valid number
if ((_num_components <= 0) || (_num_components > (C - 1))) {
_num_components = (C - 1);
}
...
_eigenvalues = Mat(_eigenvalues, Range::all(), Range(0, _num_components));
_eigenvectors = Mat(_eigenvectors, Range::all(), Range(0, _num_components));
*Here are my questions:*
- The behaviour in the documentation and the code seem to be different, is it normal ? If so, could someone explain why the number of output dimensions should be linked to the number of classes ?
- How should I proceed to have more than one dimension with two classes ?
BloodyKeyboardMon, 11 Apr 2016 08:03:10 -0500http://answers.opencv.org/question/92470/