1

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 !

0 Answers0