Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the alignment similarity between two matrices
ResourceFunction["KernelMatrixAlignment"][k1,k2] computes the alignment similarity between matrices k1 and k2. |
| "Centered" | False | whether the kernel matrices are centered before computing the alignment |
Calculate the alignment between two matrices:
| In[1]:= |
| Out[1]= |
The alignment between identical matrices is 1:
| In[2]:= |
| Out[3]= |
Create two kernel matrices:
| In[4]:= | ![]() |
Show scaling invariance:
| In[5]:= |
| Out[5]= |
Create two kernel matrices:
| In[6]:= | ![]() |
Use the "Centered" option to return the centered alignment value:
| In[7]:= |
| Out[7]= |
Start with some 2-dimensional data:
| In[8]:= | ![]() |
| Out[10]= |
Define a radial basis function (RBF) kernel:
| In[11]:= |
Evaluate the kernel on the data for three different γ values:
| In[12]:= | ![]() |
Compare the alignment values between kernel 1 and the other two:
| In[13]:= |
| Out[13]= |
Larger alignment values correspond to more similar decision boundaries induced by the kernels:
| In[14]:= | ![]() |
| Out[14]= | ![]() |
Create two kernel matrices with different amounts of noise:
| In[15]:= | ![]() |
Use the "Centered" option to return the centered alignment value:
| In[16]:= |
| Out[16]= |
Compare this to the default uncentered alignment:
| In[17]:= |
| Out[17]= |
The uncentered alignment is close to 1 because both matrices share a large constant component, even though their noise structures are unrelated.
Define two kernel matrices:
| In[18]:= | ![]() |
Use the "Centered" option to return the centered alignment:
| In[19]:= |
| Out[19]= |
Setting "Centered"->True is equivalent to centering the two kernel matrices before calculating the alignment. The matrices can be centered with the resource function CenteringMatrix as follows:
| In[20]:= |
Confirm that the centered kernel has zero row and column means (double centered):
| In[21]:= |
| Out[21]= |
After centering the matrices explicitly, the alignment value is the same as above:
| In[22]:= |
| Out[22]= |
Kernel matrices must be of equal size:
| In[23]:= |
| Out[23]= |
This work is licensed under a Creative Commons Attribution 4.0 International License