我开始使用Python scipy进行基于仿真的优化 . 这是一个简单的例子,在实际情况中,x是模拟模型的输入(随时间变化的常量变量),它有一个下限和上限(40和80) . t_sim是x和时间的函数 . 该模型模拟43200秒,目标是在模拟时间内最小化t_sim .

import numpy as np
from scipy import optimize

def cost(x):
    # in the real case, x is an input to the simulation and  
    #  t_sim is based on a simulation result (t_sim(x))
    TimeInput = np.array([0.,43200.])
    t_sim = np.array([x[0],x[0]])

    obj = np.trapz(t_sim, TimeInput)

    return obj
x0 = np.array([70])
bnds = ((40, 80),)
res = optimize.minimize(cost, x0, method='TNC', bounds=bnds)
print res.fun
print res.x

选择函数的值应该在几个数量级?在这个简单的例子中它是1728000.目标应该缩放到1吗?这与我的第二个问题有关:求解器设置的默认值(例如终止容差,用于数字jacobian的步长,线搜索的最大步长等)是否基于目标函数的某个数量级?