简体   繁体   English

如何通过 pytorch 有效地求解二次方程组?

[英]How can I efficiently solve a quaduatic equation system via pytorch?

I need to solve a non-linear equation system shown below:我需要求解如下所示的非线性方程组:

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

The dimention of C is about ten, and this equation system would be solved up to a billion of times, so it's nice to be implemented via torch so GPU could be utilized. C的尺寸约为10,这个方程组最多可以求解十亿次,所以用torch实现很好,所以可以使用GPU。 Is there any methods better than gradient descent?有没有比梯度下降更好的方法?

PyTorch only natively supports solving systems of linear equations (eg torch.solve , torch.linalg.solve ). PyTorch 仅原生支持求解线性方程组(例如torch.solvetorch.linalg.solve )。 But you can try eg:但是您可以尝试例如:

locuslab/qpth轨迹实验室/qpth

A fast and differentiable QP solver for PyTorch. PyTorch 的快速且可微分的 QP 求解器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM