python - parameters constraint in numpy lstsq -
i'm fitting set of data numpy.lstsq()
:
numpy.linalg.lstsq(a,b)[0]
returns like:
array([ -0.02179386, 0.08898451, -0.17298247, 0.89314904])
note fitting solution mix of positive , negative float.
unfortunately, in physical model, fitting solutions represent mass: consequently i'd force lstsq()
return set of positive values solution of fitting. possible this?
i.e.
solution = {a_1, ... a_i, ... a_n} a_i > 0 = {1, ..., n}
non-negative least squares implemented in scipy.optimize.nnls
.
from scipy.optimize import nnls solution = nnls(a, b)[0]
Comments
Post a Comment