我使用scipy.optimize.nnls计算非负最小二乘拟合,系数总和为1:
#! /usr/bin/env python3
import numpy as np
import scipy.optimize as soptimize
if __name__ == '__main__':
C = np.array([[112.771820, 174.429720, 312.175750, 97.348620],
[112.857010, 174.208300, 312.185270, 93.467580],
[114.897210, 175.661850, 314.275100, 99.015480]
]);
d = np.array([[112.7718, 174.4297, 312.1758, 97.3486]]);
for line in d:
ret , _= soptimize.nnls(C.T, line)
print(ret)
我得到了:
[9.99992794e-01 7.27824399e-06 0.00000000e+00]
是否可以将某些结果列设置为nnls算法的特定值并强制它生成剩余的结果列?
例如,如果我的结果是:[0.3 0.3 0.4]。我想强制第一列为0.9,nnls应生成其他列,如下所示:
[0.9 0.06 0.04]
任何帮助将不胜感激!