gpt4 book ai didi

python - 在 scipy.optimize.minimize 中使用 "infinite bounds"?

转载 作者:太空宇宙 更新时间:2023-11-04 10:35:02 28 4
gpt4 key购买 nike

我需要最大化一个 3 变量函数,它定义在以下空间中:

]0, ∞[ x ]1, ∞[ x [0, ∞[

我打算使用 scipy.optimize.minimize 中的 SLSQP 算法,我认为应该完成定义函数的边界。但我不知道如何在 python 或这个限制中写“无穷大”。也许应该使用约束来完成,但我找不到定义它的方法。

如果我能在这方面得到一些帮助,我会很高兴。

提前致谢!

最佳答案

scipy.optimize.minimize的文档指出:

bounds : sequence, optional

Bounds for variables (only for L-BFGS-B, TNC and SLSQP). (min, max) pairs for each element in x, defining the bounds on that parameter. Use None for one of min or max when there is no bound in that direction.

因此您不必表示无穷大,只需传递 None。传递浮点无穷大可能无法按预期工作。


在 Python 中表示无穷大的标准方法是使用 float('inf') 表示正无穷大,使用 float('-inf') 表示负无穷大。这些代表标准的 IEEE 754 无穷大值。

numpy 还提供了 numpy.inf

关于python - 在 scipy.optimize.minimize 中使用 "infinite bounds"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23844243/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com