r*****t 发帖数: 4793 | 1 也就是一条趋势线吧
应该很好算,可是我的数学都还老师了
在纸上画了半天没搞出来
我需要一个公式,因为要大量计算这样的一些斜率
是不是用点什么sin,arcsin之类 | R******o 发帖数: 1572 | 2 least square with constraint
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 也就是一条趋势线吧 : 应该很好算,可是我的数学都还老师了 : 在纸上画了半天没搞出来 : 我需要一个公式,因为要大量计算这样的一些斜率 : 是不是用点什么sin,arcsin之类
| r*****t 发帖数: 4793 | 3 看不懂啊老大,我需要一个公式,比如设两点为a(x1,y1),b(x2,y2), then....
【在 R******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : least square with constraint
| s*****c 发帖数: 753 | 4 sumofdist =(abs(x1*cos(t)-y1*sin(t))+abs(x2*cos(t)-y2*sin(t)))
where t range from 0 to pi.
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 看不懂啊老大,我需要一个公式,比如设两点为a(x1,y1),b(x2,y2), then....
| r*****t 发帖数: 4793 | 5 多谢!还是不太明白,这个t是啥?
【在 s*****c 的大作中提到】![](/moin_static193/solenoid/img/up.png) : sumofdist =(abs(x1*cos(t)-y1*sin(t))+abs(x2*cos(t)-y2*sin(t))) : where t range from 0 to pi.
| s*****c 发帖数: 753 | 6 The angle between the line that go through the 0,0 and x axis.
The line is expressed by
x=a*cos(t)
y=a*sin(t)
The distance is a cross product between two vectors.
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 多谢!还是不太明白,这个t是啥?
| r*****t 发帖数: 4793 | | z*********g 发帖数: 37 | 8 用最小二乘,那个斜率等于
(x_1y_1+x_2y_2)/(x_1^2+x_2^2)
那两个点是(x_1, y_1), (x_2, y_2). | s*****c 发帖数: 753 | 9 right. So this problem is t=argmin(distance).
don't know how to find the minimum? derivative = 0?
Are you simply asking for a solution or are trying to solve it?
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 但是这个t正是我要算的东西也就是该直线的斜率啊
| s*****c 发帖数: 753 | 10 he is asking for minimizing sum distance, not sum squared distance. Big
difference.
【在 R******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : least square with constraint
| | | r*****t 发帖数: 4793 | 11 谢谢!
这个最小二乘看来靠谱
x_1y_1(还有x_2y_2)表示的是二者相乘是吗?
【在 z*********g 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 用最小二乘,那个斜率等于 : (x_1y_1+x_2y_2)/(x_1^2+x_2^2) : 那两个点是(x_1, y_1), (x_2, y_2).
| z*********g 发帖数: 37 | 12
对的
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 谢谢! : 这个最小二乘看来靠谱 : x_1y_1(还有x_2y_2)表示的是二者相乘是吗?
| s*****c 发帖数: 753 | 13 Just a final reminder, this is least square, L2 norm, your were asking for
L1 norm.
Well, if it fits your need, that is fine with me.
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 谢谢! : 这个最小二乘看来靠谱 : x_1y_1(还有x_2y_2)表示的是二者相乘是吗?
| r*****t 发帖数: 4793 | 14 不太懂啊老大
主要是我不明白这些英语数学名词啥意思
【在 s*****c 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Just a final reminder, this is least square, L2 norm, your were asking for : L1 norm. : Well, if it fits your need, that is fine with me.
| B********e 发帖数: 10014 | 15 hehe,
求 x^2+y^2的最小值
和
求|x|+|y|的最小值不同
不过都可以试着求导=0
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 不太懂啊老大 : 主要是我不明白这些英语数学名词啥意思
| r*****t 发帖数: 4793 | 16 |x|+|y|的最小值 和x^2+y^2的最小值,含意上有什么不同?
我觉得求|x|+|y|的最小值就够了啊
为什么要求x^2+y^2的最小值?为什么是2次方,不是3,4或更高次方? | B********e 发帖数: 10014 | 17 你要的是距离,点(x,y)到origin的距离在欧几意义下定义为 sqrt(x^2+y^2)。
一般的应用都用的是这个定义,也就是2次方(再取2次根以维持正线性)。
如果欧式空间抽象化为度量空间,或banach空间,欧氏距离就抽象化为度量,或者范数。
那样的话,任何n>=1,n次方(再取n次根)都定义一个度量,或范数。
简单点就是,你要啥得啥,还不满足么?
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : |x|+|y|的最小值 和x^2+y^2的最小值,含意上有什么不同? : 我觉得求|x|+|y|的最小值就够了啊 : 为什么要求x^2+y^2的最小值?为什么是2次方,不是3,4或更高次方?
| B********e 发帖数: 10014 | 18
说'一般'有点绝对。很多其他的定义也有应用,比如在动态规划和图形学里。
数。
【在 B********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 你要的是距离,点(x,y)到origin的距离在欧几意义下定义为 sqrt(x^2+y^2)。 : 一般的应用都用的是这个定义,也就是2次方(再取2次根以维持正线性)。 : 如果欧式空间抽象化为度量空间,或banach空间,欧氏距离就抽象化为度量,或者范数。 : 那样的话,任何n>=1,n次方(再取n次根)都定义一个度量,或范数。 : 简单点就是,你要啥得啥,还不满足么?
| n*******l 发帖数: 2911 | 19 Least square is to minimize the L2 norm of the errors, that is,
k=argmin{ (y1-k x1)^2 + (y2-k x2)^2 }.
这基本上是描述这两个点在 y方向上离这条直线的距离,跟楼主原文里的要求不是一回
事。
【在 R******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : least square with constraint
| B****n 发帖数: 11290 | 20 你說的是對的 而且LZ問的是距離和最短 不是距離平方和最短
I guess the most useful answer for LZ is to give him the code for whatever
software he uses.
【在 n*******l 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Least square is to minimize the L2 norm of the errors, that is, : k=argmin{ (y1-k x1)^2 + (y2-k x2)^2 }. : 这基本上是描述这两个点在 y方向上离这条直线的距离,跟楼主原文里的要求不是一回 : 事。
| | | s*****c 发帖数: 753 | 21 First, you have to make sure |x|+|y|的最小值 is what you want, and you don't
want x^2+y^2的最小值.
If you do need "the slope that gives you the minimal distance sum", then:
For your two points P1(x1, y1), P2(x2, y2)
convert to polar coordinate system.
P1: (r1, t1), P2: (r2, t2)
where
x1=r1*cos(t1), y1=r1*sin(t1), x2=r2*cos(t2), y2=r2*sin(t2).
从原点到P1的线和从原点到P2的线有个夹角。范围从0到180.
如果夹角小于90, 你要的直线必定是两者之间。
let t2>t1, and t2-t1<90degrees
for the straight line you want y=k*x, or x=r*cos(t), y=r*sin(t). t1
Its distance to P1 is r1*sin(t-t1)
Its distance to P2 is r2*sin(t2-t)
sumDistance = r1*sin(t-t1)+ r2*sin(t2-t)
Take derivative to t and let it equal to 0
r1*cos(t-t1)-r2*cos(t2-t)=0
You should be able to solve to get t.
从原点到P1的线和从原点到P2的线有个夹角。范围从0到180.
如果夹角大于90,change P1 from (x1, y1) to P1'(-x1, -y1). Now P1' and P2
should satisfy the 夹角小于90 condition. you can follow the derivation
above.
【在 r*****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : |x|+|y|的最小值 和x^2+y^2的最小值,含意上有什么不同? : 我觉得求|x|+|y|的最小值就够了啊 : 为什么要求x^2+y^2的最小值?为什么是2次方,不是3,4或更高次方?
| g****t 发帖数: 31659 | 22 因为不是点到直线的y方向距离和最小,所以在课本上不是很常见。
GooG: absolute least square
First, you have to make sure |x|+|y|的最小值 is what you want, and you don't
want x^2+y^2的最小值.
If you do need "the slope that gives you the minimal distance sum", then:
For your two points P1(x1, y1), P2(x2, y2)
convert to polar coordinate system.
P1: (r1, t1), P2: (r2, t2)
where
x1=r1*cos(t1), y1=r1*sin(t1), x2=r2*cos(t2), y2=r2*sin(t2).
从原点到P1的线和从原点到P2的线有个夹角。范围从0到180.
如果夹角小于90, 你要的直线必定是两者之间。
let t2>t1, and t2-t1<90degrees
for the straight line you want y=k*x, or x=r*cos(t), y=r*sin(t). t1
Its distance to P1 is r1*sin(t-t1)
Its distance to P2 is r2*sin(t2-t)
sumDistance = r1*sin(t-t1)+ r2*sin(t2-t)
Take derivative to t and let it equal to 0
r1*cos(t-t1)-r2*cos(t2-t)=0
You should be able to solve to get t.
从原点到P1的线和从原点到P2的线有个夹角。范围从0到180.
如果夹角大于90,change P1 from (x1, y1) to P1'(-x1, -y1). Now P1' and P2
should satisfy the 夹角小于90 condition. you can follow the derivation
above.
【在 s*****c 的大作中提到】![](/moin_static193/solenoid/img/up.png) : First, you have to make sure |x|+|y|的最小值 is what you want, and you don't : want x^2+y^2的最小值. : If you do need "the slope that gives you the minimal distance sum", then: : For your two points P1(x1, y1), P2(x2, y2) : convert to polar coordinate system. : P1: (r1, t1), P2: (r2, t2) : where : x1=r1*cos(t1), y1=r1*sin(t1), x2=r2*cos(t2), y2=r2*sin(t2). : 从原点到P1的线和从原点到P2的线有个夹角。范围从0到180. : 如果夹角小于90, 你要的直线必定是两者之间。
| n*******l 发帖数: 2911 | 23 The line is determined by the point that is farther away from
the origin.
Let P, Q be two points forming a sharp angle. Let r1=|OP|
and r2=|OQ| and r1<=r2. Let L1 be a line inside the cone
POQ. Then the sum of distances from P, Q to L1 is
r1*sin(a) +r2*sin(b) >=r1*sin(a) +r1*sin(b)
>= r1*sin(a+b)= distance from P to line OQ.
For any lines L outside of the cone POQ, the sum of
distances from P and Q to L is bigger than r1*sin(a+b).
The slightly nontrivial case is a line L2 as shown in the
graph. Here the dashed red and blue lines are perpendicular
to the solid red and blue lines, respectively.
The sum of distances to L2 is
r1*sin(.5*pi-c) + r2*sin(.5*pi-d)
>=r1*sin(.5*pi-c) +r1*sin(.5*pi-d)
>= r1*sin(pi-c-d)
=r1*sin(c+d)
=r1*sin(a+b).
't
【在 s*****c 的大作中提到】![](/moin_static193/solenoid/img/up.png) : First, you have to make sure |x|+|y|的最小值 is what you want, and you don't : want x^2+y^2的最小值. : If you do need "the slope that gives you the minimal distance sum", then: : For your two points P1(x1, y1), P2(x2, y2) : convert to polar coordinate system. : P1: (r1, t1), P2: (r2, t2) : where : x1=r1*cos(t1), y1=r1*sin(t1), x2=r2*cos(t2), y2=r2*sin(t2). : 从原点到P1的线和从原点到P2的线有个夹角。范围从0到180. : 如果夹角小于90, 你要的直线必定是两者之间。
| s*****c 发帖数: 753 | 24 you are right.
【在 n*******l 的大作中提到】![](/moin_static193/solenoid/img/up.png) : The line is determined by the point that is farther away from : the origin. : Let P, Q be two points forming a sharp angle. Let r1=|OP| : and r2=|OQ| and r1<=r2. Let L1 be a line inside the cone : POQ. Then the sum of distances from P, Q to L1 is : r1*sin(a) +r2*sin(b) >=r1*sin(a) +r1*sin(b) : >= r1*sin(a+b)= distance from P to line OQ. : For any lines L outside of the cone POQ, the sum of : distances from P and Q to L is bigger than r1*sin(a+b). : The slightly nontrivial case is a line L2 as shown in the
|
|