sanity check for convex optimization book (https://web.stanford.edu/~boyd/cvxbook/) section 2.5.1 on separaing hyperplane theorem
Last active
December 4, 2021 09:47
-
-
Save silgon/e73f2c3c7777100a51003b9d27b0f010 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
import numpy as np | |
import matplotlib.pyplot as plt | |
n_steps = 50 | |
c, d= np.array([3,3]),np.array([1,2]) | |
a = c-d | |
b = (np.linalg.norm(c)**2-np.linalg.norm(d)**2)/2 | |
x = np.linspace(0, 4, n_steps) | |
y = np.linspace(0, 4, n_steps) | |
X, Y = np.meshgrid(x, y) | |
Z = np.c_[X.flatten(),Y.flatten()]@a-b | |
Z = Z.reshape(n_steps,n_steps) | |
fig = plt.figure(0) | |
ax = plt.subplot(111) | |
cs = ax.contour(X,Y,Z,levels=20, colors="#666666") | |
plt.clabel(cs, inline=1, fontsize=10) | |
plt.plot(c[0],c[1],"o", label="c") | |
plt.plot(d[0],d[1],"o", label="d") | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment