[英]How can I efficiently solve a quaduatic equation system via pytorch?
我需要求解如下所示的非线性方程组:
def trySolveEquation(V, L):
#The equation to solve is:
#{ (V . Ct) ^ 2 = 1
#{ (L + u) . Ct = 0
#C and u are the unknowns, C is a vector and u is a scalar, Ct is a vector transposed from C.
#V is a vector with dimension equal to Ct, L is a square matrix, they are known.
#u is Lagrange multiplier, and it's unknown.
#'.' means matrix multiply.
dim = V.shape[0]
assert L.shape[0] == dim and L.shape[1] == dim
C = torch.zeros((dim))
Ct = C.view((dim, 1))
u = 0
'*Solve the equation here.*'
print('C=', C)
print('u=', u)
return C, u
C的尺寸约为10,这个方程组最多可以求解十亿次,所以用torch实现很好,所以可以使用GPU。 有没有比梯度下降更好的方法?
PyTorch 仅原生支持求解线性方程组(例如torch.solve
、 torch.linalg.solve
)。 但是您可以尝试例如:
轨迹实验室/qpth
PyTorch 的快速且可微分的 QP 求解器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.