New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New API]: miminize_bfgs and miminize_lbfgs #40710
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
import paddle | ||
import paddle.nn.functional as F | ||
import paddle.fluid as fluid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好不要用fluid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
dtype='float32'): | ||
dimension = x0.shape[0] | ||
paddle.enable_static() | ||
main = fluid.Program() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fluid的都改成paddle.static,这里用 paddle.static.Program()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
line_search_fn=line_search_fn, | ||
dtype=dtype) | ||
|
||
exe = fluid.Executor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle.static.Executor()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
H0 = I | ||
else: | ||
if isinstance(initial_inverse_hessian_estimate, | ||
np.ndarray) and in_dygraph_mode(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个set_value在静态图下不能跑吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set_value在静态图下会出现empty var not defined的错误。现在统一改为:限制输入的类型为tensor,参数不是tensor或variable时抛出异常。
paddle.static.nn.cond(is_symmetric, None, false_fn) | ||
paddle.linalg.cholesky(H0) | ||
|
||
if isinstance(initial_position, np.ndarray) and in_dygraph_mode(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
静态图下不能跑吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如上
…ption test together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
derphi_star (Tensor): derphi at alpha_star. | ||
""" | ||
|
||
def phi_and_derphi(alpha): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
derphi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
derivative phi,phi函数的导数。
name=name, dtype=dtype, shape=shape) | ||
|
||
|
||
def check_H0(H0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数名字对于没有做你这个工作背景的读者,并不清楚,代码可读性较差。请增加注释:H0是什么?本函数是做什么用。(如果有数学公式,或许你可以放上去,从公式中展示H0是什么。)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改为check_initial_inverse_hessian_estimate,与参数名称一致,便于理解。
"""Implements of line search algorithm that satisfies the strong Wolfe conditions using double zoom. | ||
|
||
Reference: | ||
Jorge Nocedal, Stephen J. Wright, Numerical Optimization, Second Edition, 2006. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有更具体的页码或者网络链接吗?以及相应的数学公式方便直接打字到代码注释吗?这些可以帮助未来的软件维护者。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑到版权问题,没有加书的链接。增加了算法的编号的页码。加上了算法主要逻辑与公式。
two iterations is smaller than this value. | ||
initial_inverse_hessian_estimate (Tensor): the initial inverse hessian approximation at initial_position. | ||
It must be symmetric and positive definite. | ||
line_search_fn (str): indicate which line search method to use, 'strong wolfe' or 'hager zhang'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看代码只实现了strong wolfe,写注释含有hager zhang是否不太合适?要不要写“现在只有strong wolfe,未来会增加hager zhang做法”。不然外面用户要是用了hager zhang不好。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改。
tolerance_change (Scalar): terminates if the change of function value/position/parameter between | ||
two iterations is smaller than this value. | ||
initial_inverse_hessian_estimate (Tensor): the initial inverse hessian approximation. | ||
line_search_fn (str): indicate which line search method to use, 'strong wolfe' or 'hager zhang'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看代码只实现了strong wolfe,写注释含有hager zhang是否不太合适?要不要写“现在只有strong wolfe,未来会增加hager zhang做法”。不然外面用户要是用了hager zhang不好。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改。
…e to limit test time in 15s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ebda0e6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
APIs
Describe
add api miminize_bfgs and miminize_lbfgs