Created
July 26, 2021 21:35
-
-
Save gatoniel/c01acbe866480ec1f4f3ec7fc8ac7ec9 to your computer and use it in GitHub Desktop.
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
num_points = 10000 | |
num_dims = 200 | |
def norm(x, keepdims=False): | |
return np.linalg.norm(x, ord=2, axis=-1, keepdims=keepdims) | |
def normalize(x): | |
return x / norm(x, True) | |
points = normalize(np.exp(np.random.randn(num_points, num_dims))) | |
def loss(x, points): | |
x = normalize(x) | |
return np.sum(np.inner(x, points)**2, axis=-1) | |
def minimum(points): | |
A = np.matmul(points.T, points) | |
w, v = np.linalg.eigh(A) | |
ind1 = np.all(v > 0, axis=0) | |
ind2 = np.all(v < 0, axis=0) | |
if np.any(ind1): | |
ind = ind1 | |
elif np.any(ind2): | |
ind = ind2 | |
else: | |
raise RuntimeError | |
return w[ind], np.abs(v[:, ind]) | |
w, v = minimum(points) | |
print(w)#, v) | |
print(loss(v.T, points)) | |
print(loss(points, points).max()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment