Zero-centering a kernel matrix?

856 Views Asked by At

I'm trying to implement the algorithm in this paper. As you can see at page 4, it is explained how to 0-centering a pxp symmetric Kernel matrix K as (where e are vector of ones):

enter image description here

However, in the matlab code provided this formula is expressed as:

K = K - (1/p)*(K*ones(p,1))*ones(1,p) - (1/p)*ones(p,1)*(ones(1,p)*K) + (1/p^2)*sum(sum(K))

As you can see, in the third term the matlab formula has an extra K. My question is: which one is the correct one?