Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

python - 如何对一组数据点进行重新排序以最大程度减少另一组数据点的错误(How to reorder one set of data points to minimize error with another set of data points)

I have the following set of 15 data points:

(我有以下15个数据点集:)

[0.287 , 0.0691, 0.856, 0.731, 0.895, 0.76, 0.496, 0.749, 0.77, 0.684, 0.667, 0.386, 0.4, 0.334, 0.346]

And I would like the order of these data points to be changed so to minimize the error with the following set of 15 data points:

(我希望更改这些数据点的顺序,以便通过以下15个数据点集将错误最小化:)

[0.1, 0.3, 0.5, 0.7, 0.9, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.3, 0.2, 0.1]

I could just try all permutations of the first set of data points and see which one gives the smallest error but that would take forever...

(我可以尝试对第一组数据点进行所有排列,然后看看哪一个给出的误差最小,但这将永远花费...)

  ask by bki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm assuming by error you mean the summed absolute difference.

(我错误地假设您的意思是总和绝对差。)

It is not difficult to check that this error is minimized when a and b have the same rank order.

(当ab具有相同的等级顺序时,不难检查出此误差是否最小。)

The best reordering of a can thus be obtained using argsort

(因此,可以使用argsort获得a的最佳重新排序)

>>> a = np.array([0.287 , 0.0691, 0.856 , 0.731 , 0.895 , 0.76 , 0.496 , 0.749 , 0.77 , 0.684 , 0.667 , 0.386 , 0.4 , 0.334 , 0.346 ])
>>> b = np.array([0.1, 0.3, 0.5, 0.7, 0.9, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.3, 0.2, 0.1])
>>> 
>>> best_shuffle = np.empty(a.size,int)
>>> best_shuffle[b.argsort(kind="stable")] = a.argsort(kind="stable")
>>> 
>>> np.abs(b-a[best_shuffle]).sum()
1.3499000000000005

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...