Skip to content

Instantly share code, notes, and snippets.

@ShuaiGuo16
Last active January 22, 2021 10:00
Show Gist options
  • Save ShuaiGuo16/41986813fa80210f032dc9ba5fbdd674 to your computer and use it in GitHub Desktop.
Save ShuaiGuo16/41986813fa80210f032dc9ba5fbdd674 to your computer and use it in GitHub Desktop.
Compute correlation matrix between feature matrics
def Corr(self, X1, X2, theta):
"""Construct the correlation matrix between X1 and X2
Input
-----
X1, X2: 2D arrays, (n_samples, n_features)
theta: array, correlation legnths for different dimensions
Output
------
K: the correlation matrix
"""
K = np.zeros((X1.shape[0],X2.shape[0]))
for i in range(X1.shape[0]):
K[i,:] = np.exp(-np.sum(theta*(X1[i,:]-X2)**2, axis=1))
return K
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment