当已经选择了一些变量时如何求解方程组?

发布于 2025-01-09 16:57:30 字数 871 浏览 1 评论 0原文

我正在使用 scipy.optimize 来最小化成本函数。

Python 将 M 个变量传递到成本函数中,并根据这些变量计算其他 N 个变量。现在,我有一个 M+N 联立方程组,必须满足该方程组才能使解有效。

我想象做这样的事情:

def cost(someTuple):
    # This function calculates the cost
    return k1 * someTuple[0] + k2 * someTuple[1] + ... kN * someTuple[N-1]

def cost_wrapper(x):
    # ************ The following line is what I don't know how to do *************
    big_tuple = solveSystemOfEquations(x, f(x))
    return cost(big_tuple)

if __name__=="__main__":
    from scipy.optimize import minimize
    minimize(cost_wrapper, *otherParams)

solveSystemOfEquations() 的重要之处在于它返回的变量比给它的变量多。如果给定的变量与任何可能的解决方案相距甚远,solveSystemOfEquations() 必须返回一个带有梯度的大数,这将引导优化器找到有意义的解决方案。

我们还假设该系统是近似可解的。请注意,无法保证解的 MMSE 误差有界。

是否有任何算法允许您选择一些(不是全部)变量,并求解其他变量?或者说这根本就不是一件事吗?

I'm using scipy.optimize to minimize a cost function.

Python passes M variables into the cost function, and N other variables are calculated based on those. Now, I have a system of M+N simultaneous equations which must be satisfied for a solution to be valid.

I imagine doing something like this:

def cost(someTuple):
    # This function calculates the cost
    return k1 * someTuple[0] + k2 * someTuple[1] + ... kN * someTuple[N-1]

def cost_wrapper(x):
    # ************ The following line is what I don't know how to do *************
    big_tuple = solveSystemOfEquations(x, f(x))
    return cost(big_tuple)

if __name__=="__main__":
    from scipy.optimize import minimize
    minimize(cost_wrapper, *otherParams)

What is important about solveSystemOfEquations() is that it returns more variables than are given to it. If the variables given to it are far removed from any possible solution, solveSystemOfEquations() has to return a large number with a gradient that will lead the optimizer towards a meaningful solution.

Let's also assume that the system is approximately solvable. Note that boundedness of MMSE error of a solution cannot be guaranteed.

Is there any algorithm which allows you to choose some (not all) variables, and solve for the others? Or is that not a thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文