Ask Your Question

sree's profile - activity

2017-07-10 13:45:44 -0600 commented answer Within-classes scatter calculation in lda.cpp

Thank you berak I got it. One more thing regarding the above calculation. Should we arrange the content of the "mean corrected" data matrix in a way to separate the classes before applying the mulTransposed operation? What I feel is that, if we don't arrange the content of data matrix, then there will be between classes products in the calculation. Is this correct?

2017-07-09 11:14:16 -0600 received badge  Editor (source)
2017-07-09 11:13:01 -0600 asked a question Within-classes scatter calculation in lda.cpp

Hi,

Below is the partial code from lda.cpp.

// calculate sums
    for (int i = 0; i < N; i++) {
        Mat instance = data.row(i);
        int classIdx = mapped_labels[i];
        add(meanTotal, instance, meanTotal);
        add(meanClass[classIdx], instance, meanClass[classIdx]);
        numClass[classIdx]++;
    }
    // calculate total mean
    meanTotal.convertTo(meanTotal, meanTotal.type(), 1.0 / static_cast<double> (N));
    // calculate class means
    for (int i = 0; i < C; i++) {
        meanClass[i].convertTo(meanClass[i], meanClass[i].type(), 1.0 / static_cast<double> (numClass[i]));
    }
    // subtract class means
    for (int i = 0; i < N; i++) {
        int classIdx = mapped_labels[i];
        Mat instance = data.row(i);
        subtract(instance, meanClass[classIdx], instance);
    }
    // calculate within-classes scatter
    Mat Sw = Mat::zeros(D, D, data.type());
    mulTransposed(data, Sw, true);

As you can see, the last two lines are the one which calculates the within-class scatter. My doubt is, is this correct? From my understanding, within-class scatter is calculated after finding the difference of class elements with its mean value. But here the mulTransposed is applied to data which is the data samples before finding difference about the mean value. Should it be instance instead of data? Please correct me if I am wrong. I am new to this.

Thanks!

2017-07-09 07:19:13 -0600 commented question How to add a new member function to the existing LDA class and recompile it?

Thank you berak. I will try to implement that way. I was trying to locate the class definition of LDA class but was unable to find it in lda.cpp. Is there any other file dependency for LDA class? Thank you

2017-07-09 06:49:46 -0600 asked a question How to add a new member function to the existing LDA class and recompile it?

Hi,

I am new to OpenCV. The version I use is OpenCV 3.1 My question has two parts.

  1. How to add a new member function to the existing LDA class?

I am trying to modify the lda.cpp source file in /modules/core/src/ My objective is to create a new member function in order to execute additional functions to the Sw and Sb matrices.

  1. How to recompile OpenCV after source file modification?

In order to confirm the procedure for recompiling, I added 'cout' command inside the source file for one of the matrices. What are the steps to recompile successfully, so that when I run my code (which uses the LDA class) I will get the prints of the matrix as specified?

Thank you in advance.

Sree