当前位置: 首页>>代码示例>>Python>>正文


Python NLP.f方法代码示例

本文整理汇总了Python中openopt.NLP.f方法的典型用法代码示例。如果您正苦于以下问题:Python NLP.f方法的具体用法?Python NLP.f怎么用?Python NLP.f使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openopt.NLP的用法示例。


在下文中一共展示了NLP.f方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: in

# 需要导入模块: from openopt import NLP [as 别名]
# 或者: from openopt.NLP import f [as 别名]
    r = p.solve(solver)
    for fn in ("h", "c"):
        if not r.evals.has_key(fn):
            r.evals[fn] = 0  # if no c or h are used in problem
    results[solver] = (
        r.ff,
        p.getMaxResidual(r.xf),
        r.elapsed["solver_time"],
        r.elapsed["solver_cputime"],
        r.evals["f"],
        r.evals["c"],
        r.evals["h"],
    )
    if PLOT:
        subplot(2, 1, 1)
        F0 = asscalar(p.f(p.x0))
        lines.append(plot([0, 1e-15], [F0, F0], color=colors[j]))

if PLOT:
    for i in range(2):
        subplot(2, 1, i + 1)
        legend(lines, solvers)

    subplots_adjust(bottom=0.2, hspace=0.3)

    xl = ["Solver                              f_opt     MaxConstr   Time   CPUTime  fEvals  cEvals  hEvals"]

    for i in range(len(results)):
        s = (
            ljust(lower(solvers[i]), 40 - len(solvers[i]))
            + "%0.3f" % (results[solvers[i]][0])
开发者ID:AlbertHolmes,项目名称:openopt,代码行数:33,代码来源:nlp_5.py

示例2: NLP

# 需要导入模块: from openopt import NLP [as 别名]
# 或者: from openopt.NLP import f [as 别名]
"""

p = NLP(x0=15, f=lambda x: x ** 2 - 0.4, df=lambda x: 2 * x, iprint=0, plot=1)

# after the problem is assigned, you could turn the parameters,
# along with some other that have been set as defaults:

p.x0 = 0.15
p.plot = 0


def f(x):
    return x if x > 0 else x ** 2


p.f = f

# At last, you can modify any prob parameters in minimize/maximize/solve/manage functions:

r = p.minimize("ralg", x0=-1.5, iprint=-1, plot=1, color="r")
# or
# r = p.manage('ralg', start = False, iprint = 0, x0 = -1.5)

"""
Note that *any* kwarg passed to constructor will be assigned
e.g. 
p = NLP(f, x0, myName='JohnSmith')
is equivalent to 
p.myName='JohnSmith'
It can be very convenient for user-supplied callback functions 
(see /examples/userCallback.py)
开发者ID:AlbertHolmes,项目名称:openopt,代码行数:33,代码来源:probAssign.py


注:本文中的openopt.NLP.f方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。