Skip to content

Instantly share code, notes, and snippets.

@ranjiGT
Created May 12, 2021 11:56
Show Gist options
  • Save ranjiGT/072631151df2498fe4eb1a0ede1cc1f4 to your computer and use it in GitHub Desktop.
Save ranjiGT/072631151df2498fe4eb1a0ede1cc1f4 to your computer and use it in GitHub Desktop.
A piepline for creating polynomial degree 2 kernel matrix for and its vector norm
import numpy as np
X = np.array([[-0.5, 1], [-1, -1.5], [-1.5, 1.5], [1.5, -0.5], [0.5, -0.5]])
y = np.array([-1, 1, 1, 1, -1])
res = np.empty((5, 5))
def k(X):
for i in range(X.shape[0]):
for j in range(X.shape[0]):
res[i][j] = np.dot(X[i], X[j]) ** 2
return res
print(k(X))
def max_norm(X):
norms = []
for i in range(X.shape[0]):
norms.append(np.linalg.norm(X[i]))
print(norms)
return max(norms) ** 2
max_norm = max_norm(X)
print(max_norm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment