Unmesha SreeVeni - 18 days ago 5x

Java Question

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?

Answer

You are computing a matricial product. Say `A = [a, b, c]`

(horizontal vector), you get an obviously symetric matrix by :

M =

^{t}A . 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 ...
}
}
```

Source (Stackoverflow)

Comments