Scipy.优化COBYLA约束违反



我有一个约束的优化问题,但是COBYLA求解器似乎不尊重我指定的约束。

我的优化问题:

cons = ({'type':'ineq', 'fun':lambda t: t},) # all variables must be positive
minimize(lambda t: -stateEst(dict(zip(self.edgeEvents.keys(),t)), (0.1,)*len(self.edgeEvents), constraints=cons, method='COBYLA')

stateEst定义为:

def stateEst(t):
    val = 0
    for edge,nextState in self.edgeEvents.iteritems():
        val += edge_probability(self,edge,ts) * estimates[nextState]
        val += node_probability(self, edge.head, ts, edge_list=[edge])* cost
    for node,nextState in self.nodeEvents.iteritems():
        val += node_probability(self, node, ts) * 
            (estimates[nextState] + cost*len([e for e in node.incoming if e in self.compEdges])
    return val

概率函数仅定义为正t值。字典是必要的,因为概率是根据"命名的"t值计算的。

当我运行这个时,我注意到COBYLA对其中一个t值尝试了-0.025的值。为什么优化不尊重约束条件?

COBYLA从技术上讲是一个不可行的方法,这意味着迭代在您的约束条件下可能并不总是可行的!(这只是关于最终的收敛,可行性对这些算法很重要)。

使用没有到处定义的目标函数将会有问题。也许你被迫切换到一些可行的方法

或者你可以考虑推广你的目标,这样就会对负t进行惩罚。但这是问题依赖的,也可能引入其他问题(收敛性;数值稳定性)。

尝试使用L-BFGS-B,它仅限于绑定约束,这在这里不是问题(对于您当前的问题!)。

对于这么简单的事情,只需重新定义您的函数,通过取np.exp(t)甚至t**2来取任何实值,然后取解的对数(或平方根)

最新更新