1

I am trying to achieve multiplication in array for doing PCA in java

I calculated mean and substrtacted it from each x values.Next I need to find covarience

So inorder to find that I need to multiply all the combinations in a given array

 [a,b,c] --> (aa)(ab)(ac)(bb)(bc)(cc)

How to construct a matrix of all possible products?

Whether taking subset and multiplying solves the problem?

benten
  • 1,995
  • 2
  • 23
  • 38
USB
  • 6,019
  • 15
  • 62
  • 93
  • Can you explain in more detail what's the problem? How to construct a matrix of all possible products? – Emanuele Paolini Jul 15 '14 at 08:23
  • 1
    You can use an already implemented solution like: https://code.google.com/p/efficient-java-matrix-library/wiki/PrincipleComponentAnalysisExample which you can modify to your needs. – Eypros Jul 15 '14 at 08:24
  • 1
    yes how to construct a matrix of all possibilities – USB Jul 15 '14 at 08:24
  • 1
    I would Like to do it from the scratch for learning – USB Jul 15 '14 at 08:47

1 Answers1

1

You are computing a matricial product. Say A = [a, b, c] (horizontal vector), you get an obviously symetric matrix by :

M = tA . A

The upper part of the matrix is composed of all possible products.

aa ab ac
ba bb bc
ca cb cc

When computing, you can use the symetry :

for(int i=0; i<len; i++) {
    for (int j=0; j<=i; j++) { // do not go up to len but stop at i ...
        // computations ...
    }
}
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252