Computes the normalized Frobenius inner product between two symmetric matrices,
which measures the similarity between two kernels. Useful for model selection
and comparing different kernel parameterizations.
Arguments
- A
First symmetric matrix
- B
Second symmetric matrix (must have same dimensions as A)
Value
Scalar alignment score in [-1,1], where 1 indicates perfect positive
alignment, 0 indicates orthogonality, and -1 indicates perfect negative
alignment
Details
The kernel alignment is computed as: align(A,B) = <A,B>_F / (||A||_F * ||B||_F),
where <A,B>_F = sum(A * B) is the Frobenius inner product and ||A||_F is the
Frobenius norm. This provides a normalized measure of kernel similarity.
Examples
A <- matrix(c(2, 1, 0, 1, 2, 1, 0, 1, 2), 3, 3)
B <- matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1), 3, 3)
align_score <- kernel_alignment(A, B)
print(align_score) # alignment between A and identity matrix
#> [1] 0.8660254