tpapp / SymmetricProducts.jl

Calculate A*A', wrapping the result in the narrowest type.
Other
1 stars 1 forks source link

Use cases #2

Open antoine-levitt opened 6 years ago

antoine-levitt commented 6 years ago

Common cases I can think of:

A'A
A*A'
A'B+B'A
A'*B*A
A*B*A'
A*B+B*A

the last three with symmetric/hermitian B, and the last with symmetric/hermitian A

tpapp commented 6 years ago

I am not sure what the issue is.

antoine-levitt commented 6 years ago

To support them all, of course. From the title of the package I thought it was about more than A*A'.

tpapp commented 6 years ago

No, it is also about A'*A :wink:

Regarding the use cases:

  1. symprod(A') and symprod(A) already takes care of the first two,

  2. something like symsum(A'*B) can handle A'*B+ B'*A and similarly A*B'+B*A',

  3. symprod(A, B::T) where T is some symmetric type could handle A*B*A',

  4. A*B+B*A is not actually symmetric in general.

antoine-levitt commented 6 years ago

I use A'A much more than A*A' so it would make more sense to me to have symprod(A) = A'A, but that comes down to personal preferences.

Some alternative names that people sometimes use: overlap/gram/covariance for A'A, outer for A*A'. Inner/outer would make a nice symmetric pair, but inner usually refers to tr(A'A) instead.

tpapp commented 6 years ago

AFAICT when the outer product is generalized to matrices, the kronecker product is used.

Covariance is already widely used, and using it for something else (although related) would be confusing.

AFAIK the Gram matrix is transpose(A)*A, which only coincides with A'*A when A isa AbstractMatrix{<: Real}.

I also use A'*A more commonly, but I find that the extra ' makes the semantics cleaner for me.

antoine-levitt commented 6 years ago

Good point on outer products for matrices.

Covariance is already widely used, and using it for something else (although related) would be confusing.

Actually I didn't see before, but cov(A) already does A'A (but doesn't make it symmetric)

AFAIK the Gram matrix is transpose(A)A, which only coincides with A'A when A isa AbstractMatrix{<: Real}.

Usually the Gram matrix is made of inner products and is therefore A'A (see wikipedia)

I like overlap (and actually have overlap(A,B) = Hermitian(A'*B*A) defined somewhere)