Last active
January 22, 2021 10:00
-
-
Save ShuaiGuo16/41986813fa80210f032dc9ba5fbdd674 to your computer and use it in GitHub Desktop.
Compute correlation matrix between feature matrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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