Cross-covariance of 2 sample sets.

asked 2019-04-29 13:37:23 -0600

Kibouo gravatar image

updated 2019-05-01 07:41:11 -0600

calcCovarMarix works great for calculating the auto-covariance matrix of a given sample set.

Now, how does one calculate the cross-covariance of 2 sample sets?

Example: every row of a matrix is a sample. Samples are random vectors with possibly differing amount of variables:

Mat A = [[1, 2],
         [2, 3]]

Mat B = [[3, 4, 5],
         [4, 5, 6]]

In MATLAB one can simply do cov(A, B). How would one do it in C++ OpenCV?

edit retag flag offensive close merge delete

Comments

1

Did you miss https://docs.scipy.org/doc/numpy/refe...

Or are you using C++?

sjhalayka gravatar imagesjhalayka ( 2019-04-29 19:33:56 -0600 )edit

My bad, I'm using C++. Edited Q.

Kibouo gravatar imageKibouo ( 2019-04-30 07:04:41 -0600 )edit

I found this as well: https://www.mathworks.com/help/matlab...

Go to the section More About > Covariance.

Also check out: https://en.wikipedia.org/wiki/Cross-c...

Is that what you're looking for? If so, please let me know, and I'll see what I can do about writing some C++ code for you.

sjhalayka gravatar imagesjhalayka ( 2019-04-30 11:07:41 -0600 )edit

Yes, those resources are relevant.

The thing is, I could implement it myself from scratch using the definition found at https://en.wikipedia.org/wiki/Cross-c... .

However, it would probably be slow. And I expected something 'basic' as this to be present in OpenCV. Especially since calcCovarMatrix exists.

Kibouo gravatar imageKibouo ( 2019-04-30 11:12:37 -0600 )edit

again, please explain your use case, and your expectations.

berak gravatar imageberak ( 2019-05-01 02:08:56 -0600 )edit

The expectation should be pretty clear: I want the cross-covariance matrix of 2 sample sets, calculated using C++ OpenCV.

Kibouo gravatar imageKibouo ( 2019-05-01 07:40:09 -0600 )edit