运行scipy优化会产生属性错误

时间:2018-12-31 10:11:08

标签: python

我正在尝试将scipy优化与最小化函数一起使用,以找到使该函数最小化的两个猜想变量的值,我目前正在这样运行它:

def function_to_min(theta):
    respons = responsibilities()[0][0][0]
    sequence_to_foc = sequence[0][0][0]
    pis = calculating_pis()[0]
    return np.nan_to_num((-1)*(respons * np.log(pis*get_emission(theta[0], sequence_to_foc, theta[1]))))

theta2 = np.array([mu_initial2, sigma_guess])

res = minimize(function_to_min, theta2, method='nelder-mead',
options = {'xtol': 2, 'disp': True})
print(res.theta)

我还没有发布所有可以打印值结果的代码,所有当前值都是单值(没有数组)。为什么我不断提高AttributeError(name) AttributeError:theta吗?

1 个答案:

答案 0 :(得分:0)

我猜想代码末尾的

res.theta会导致这种情况。根据scipy文件。优化的回报是docs.scipy.org/doc/scipy/reference/generation/…。这意味着您应该改为打印(res.x)。