欠定系统的非负最小二乘 [英] Non-negative least squares for underdetermined system

查看:62
本文介绍了欠定系统的非负最小二乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下问题:

查找: x_1,x_2,x_3>0 这样

67.5 = 60*x_1 +  90*x_2 + 120*x_3  
60   = 30*x_1 + 120*x_2 +  90*x_3

有没有办法在Python中解决这个问题?也许使用 scipy.nnls()?

Is there a way to solve this equation in Python? Perhaps with scipy.nnls()?

推荐答案

使用sympy象征性地求解方程组

Using sympy to solve the equation set symbolically

from sympy import * 

x_1, x_2, x_3 = symbols('x_1 x_2 x_3')

res = solve([Eq(60*x_1+90*x_2+120*x_3, 67.5),
             Eq(30*x_1+120*x_2+90*x_3, 60)],
             [x_1, x_2, x_3])
print res
#{x_1: -1.4*x_3 + 0.6, x_2: -0.4*x_3 + 0.35}

使用 scipy.optimize.nnls

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import nnls 

A = np.array([[60, 90, 120], 
              [30, 120, 90]])

b = np.array([67.5, 60])

x, rnorm = nnls(A,b)

print x
#[ 0.          0.17857143  0.42857143]
print rnorm
#0.0

尽管如此,这仅承诺提供一个参数为 x> = 0 的解决方案,因此您可以像本例中那样获得零.

Altough this only promises a solution where the parameters are x>=0 so you can get zeros, as you did for this example.

这篇关于欠定系统的非负最小二乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆