Skip to content
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

Merged
merged 12 commits into from Mar 31, 2022

Conversation

betterpig
Copy link
Contributor

PR types

New features

PR changes

APIs

Describe

add api miminize_bfgs and miminize_lbfgs

@paddle-bot-old
Copy link

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.


import paddle
import paddle.nn.functional as F
import paddle.fluid as fluid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好不要用fluid

Copy link
Contributor Author

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()
Copy link
Contributor

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()

Copy link
Contributor Author

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paddle.static.Executor()

Copy link
Contributor Author

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():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个set_value在静态图下不能跑吗

Copy link
Contributor Author

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():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

静态图下不能跑吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如上

zhwesky2010
zhwesky2010 previously approved these changes Mar 22, 2022
Copy link
Contributor

@zhwesky2010 zhwesky2010 left a 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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derphi?

Copy link
Contributor Author

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数名字对于没有做你这个工作背景的读者,并不清楚,代码可读性较差。请增加注释:H0是什么?本函数是做什么用。(如果有数学公式,或许你可以放上去,从公式中展示H0是什么。)

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有更具体的页码或者网络链接吗?以及相应的数学公式方便直接打字到代码注释吗?这些可以帮助未来的软件维护者。

Copy link
Contributor Author

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'.
Copy link
Member

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不好。

Copy link
Contributor Author

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'.
Copy link
Member

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不好。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改。

zhhsplendid
zhhsplendid previously approved these changes Mar 29, 2022
Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Superjomn
Superjomn previously approved these changes Mar 29, 2022
Copy link
Contributor

@Superjomn Superjomn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

dingjiaweiww
dingjiaweiww previously approved these changes Mar 29, 2022
lanxianghit
lanxianghit previously approved these changes Mar 29, 2022
Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhwesky2010 zhwesky2010 merged commit e7928a0 into PaddlePaddle:develop Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants