本文整理汇总了Python中openopt.NLP.d2f方法的典型用法代码示例。如果您正苦于以下问题:Python NLP.d2f方法的具体用法?Python NLP.d2f怎么用?Python NLP.d2f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openopt.NLP
的用法示例。
在下文中一共展示了NLP.d2f方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: matrix
# 需要导入模块: from openopt import NLP [as 别名]
# 或者: from openopt.NLP import d2f [as 别名]
"""
this is an example of using d2f - Hesse matrix (2nd derivatives)
d2c, d2h, d2l are intended to be implemented soon
and to be connected to ALGENCAN and/or CVXOPT
and/or other NLP solvers
//Dmitrey
"""
from openopt import NLP
from numpy import cos, arange, ones, asarray, abs, zeros, diag
N = 300
M = 5
ff = lambda x: ((x-M)**4).sum()
p = NLP(ff, cos(arange(N)))
p.df = lambda x: 4*(x-M)**3
p.d2f = lambda x: diag(12*(x-M)**2)
# other valid assignment:
# p = NLP(lambda x: ((x-M)**4).sum(), cos(arange(N)), df = lambda x: 4*(x-M)**3, d2f = lambda x: diag(12*(x-M)**2))
# or
# p = NLP(x0 = cos(arange(N)), f = lambda x: ((x-M)**4).sum(), df = lambda x: 4*(x-M)**3, d2f = lambda x: diag(12*(x-M)**2))
r = p.solve('scipy_ncg')
print('objfunc val: %e' % r.ff) # it should be a small positive like 5.23656378549e-08