【发布时间】:2019-02-04 19:50:21
【问题描述】:
我正在尝试根据一些向量求和来最小化最小二乘之和。简而言之,我正在创建一个方程,它采用理想向量,用确定的系数对它们进行加权,然后对加权向量求和。一旦将该总和与为某些观察找到的实际矢量测量值进行比较,就会得到最小二乘之和。
举个例子:
# Observation A has the following measurements:
A = [0, 4.1, 5.6, 8.9, 4.3]
# How similar is A to ideal groups identified by the following:
group1 = [1, 3, 5, 10, 3]
group2 = [6, 3, 2, 1, 10]
group3 = [3, 3, 4, 2, 1]
# Let y be the predicted measurement for A with coefficients s1, s2, and s3:
y = s1 * group1 + s2 * group2 + s3 * group3
# y will be some vector of length 5, similar to A
# Now find the sum of least squares between y and A
sum((y_i - A_i)** 2 for y_i in y for A_i in A)
必要的界限和约束
0
s1 + s2 + s3 = 1
y = s1 * group1 + s2 * group2 + s3 * group3
y 和 A 的最小二乘之和是我想要最小化以获得系数 s1、s2、s3 的值,但我很难确定 scipy.optimize 中的正确选择可能是什么。那里用于最小化最小二乘和的函数似乎不能处理代数变量约束。我正在使用的数据是通过这些矢量化测量获得的数千个观察结果。任何想法或想法将不胜感激!
【问题讨论】:
标签: python python-3.x mathematical-optimization