$R^n$超平面约束下的向量列

原向量: x → \overset{\rightarrow}{x} x

x → \overset{\rightarrow}{x} x法向相同的法向量(与 x → \overset{\rightarrow}{x} x同向) ( x → ⋅ n → ∣ n → ∣ 2 ) n → (\frac{\overset{\rightarrow}x\cdot\overset{\rightarrow}n}{|\overset\rightarrow n|^2})\overset\rightarrow n (n2xn)n(即原向量在法向的投影)

投影到超平面的向量 x → − ( x → ⋅ n → ∣ n → ∣ 2 ) n → \overset{\rightarrow}{x}-(\frac{\overset{\rightarrow}x\cdot\overset{\rightarrow}n}{|\overset\rightarrow n|^2})\overset\rightarrow n x(n2xn)n(与 x → \overset{\rightarrow}{x} x同向)

(就是一个向量三角形)

比如 x → = ( x 1 , ⋯ x n ) \overset{\rightarrow}{x}=(x_1,\cdots x_n) x=(x1,xn),梯度约束在 x 1 + ⋯ + x n = 1 x_1+\cdots+x_n=1 x1++xn=1中,那么

grad = list(map(lambda x: x-tf.reshape(tf.reshape(x, [1,-1])@tf.ones([x.shape[0],1]),[])/(x.shape[0])*tf.ones([x.shape[0]]), grad))

要做一次投影,让梯度也满足约束,从而当初始点满足约束时,这样使用梯度下降可以使得点列一直满足约束

你可能感兴趣的:(平面,机器学习,人工智能)