Force NNLS result

痴心易碎 提交于 2019-12-13 20:03:43

问题


I am using scipy.optimize.nnls to compute non-negative least square fit with a coefficients sum to 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)

And I get :

[9.99992794e-01 7.27824399e-06 0.00000000e+00]

Is it possible to set some result column to a specific value for the nnls algorithm and to force it to generate the remaining result columns ?

For instance if my result is : [0.3 0.3 0.4]. I want to force the first column to 0.9 and the nnls should generate the other columns, like this :

 [0.9 0.06 0.04]

Any help will be appreciated !

来源:https://stackoverflow.com/questions/50591532/force-nnls-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!