寻找最接近的匹配

发布于 2024-09-04 18:32:10 字数 895 浏览 6 评论 0原文

我有一个带有一组参数的对象,例如:

var obj = new {Param1 = 100; Param2 = 212; Param3 = 311; param4 = 11; Param5 = 290;}

在另一边,我有一个对象列表:

var obj1  = new {Param1 = 1221 ; Param2 = 212 ; Param3 = 311 ; param4 = 11  ; Param5 = 290 ; }
var obj3  = new {Param1 = 35   ; Param2 = 11  ; Param3 = 319 ; param4 = 211 ; Param5 = 790 ; }
var obj4  = new {Param1 = 126  ; Param2 = 218 ; Param3 = 2   ; param4 = 6   ; Param5 = 190 ; }
var obj5  = new {Param1 = 213  ; Param2 = 121 ; Param3 = 61  ; param4 = 11  ; Param5 = 29  ; }
var obj7  = new {Param1 = 161  ; Param2 = 21  ; Param3 = 71  ; param4 = 51  ; Param5 = 232 ; }
var obj9  = new {Param1 = 891  ; Param2 = 58  ; Param3 = 311 ; param4 = 21  ; Param5 = 590 ; }
var obj11 = new {Param1 = 61   ; Param2 = 212 ; Param3 = 843 ; param4 = 89  ; Param5 = 210 ; }

在列出的对象中找到第一个 obj 最接近的匹配的最佳(最简单)算法是什么?

I Have an object with a set of parameters like:

var obj = new {Param1 = 100; Param2 = 212; Param3 = 311; param4 = 11; Param5 = 290;}

On the other side i have a list of object:

var obj1  = new {Param1 = 1221 ; Param2 = 212 ; Param3 = 311 ; param4 = 11  ; Param5 = 290 ; }
var obj3  = new {Param1 = 35   ; Param2 = 11  ; Param3 = 319 ; param4 = 211 ; Param5 = 790 ; }
var obj4  = new {Param1 = 126  ; Param2 = 218 ; Param3 = 2   ; param4 = 6   ; Param5 = 190 ; }
var obj5  = new {Param1 = 213  ; Param2 = 121 ; Param3 = 61  ; param4 = 11  ; Param5 = 29  ; }
var obj7  = new {Param1 = 161  ; Param2 = 21  ; Param3 = 71  ; param4 = 51  ; Param5 = 232 ; }
var obj9  = new {Param1 = 891  ; Param2 = 58  ; Param3 = 311 ; param4 = 21  ; Param5 = 590 ; }
var obj11 = new {Param1 = 61   ; Param2 = 212 ; Param3 = 843 ; param4 = 89  ; Param5 = 210 ; }

What is the best (easiest) algorithm to find the closest match for the first obj in the listed objects?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千紇 2024-09-11 18:32:11

在尝试查找之前,您必须定义术语最接近的匹配

1-许多人使用的一种方法是均方误差(或欧几里得距离) :

计算所有对象的均方误差:

Sqr(obj.Param1-obj1.Param1) + Sqr(obj.Param2-obj1.Param2) + ..... // for obj1
Sqr(obj.Param1-obj2.Param1) + Sqr(obj.Param2-obj2.Param2) + ..... // for obj2

并选择具有最小值的一个...

2-您还可以使用最小绝对误差:

Abs(obj.Param1-obj1.Param1) + Abs(obj.Param2-obj1.Param2) + ..... // for obj1
Abs(obj.Param1-obj2.Param1) + Abs(obj.Param2-obj2.Param2) + ..... // for obj2

并选择最小值...

3-您还可以根据您拥有的任何条件应用k-最近邻上面选择的

这一切都取决于这些参数的属性...

有关更多阅读,您可以查看 分类列表算法

You must define the term closest match before trying to find it!!

1- One way many people use is Mean Squared Error (or Euclidean Distance) :

Calculate mean square error for all objects:

Sqr(obj.Param1-obj1.Param1) + Sqr(obj.Param2-obj1.Param2) + ..... // for obj1
Sqr(obj.Param1-obj2.Param1) + Sqr(obj.Param2-obj2.Param2) + ..... // for obj2

and choose the one with the minimum value...

2- You may also use Minimum absolute error :

Abs(obj.Param1-obj1.Param1) + Abs(obj.Param2-obj1.Param2) + ..... // for obj1
Abs(obj.Param1-obj2.Param1) + Abs(obj.Param2-obj2.Param2) + ..... // for obj2

and choose the one with the minimum value...

3- Also you can apply k-nearest neighbour with any criteria you have chosen above

It all depends on the properties of these parameters...

For more reading you may look at List of Classification algorithms

猛虎独行 2024-09-11 18:32:11

我想,要看情况。我想到了几种可能性:

  • SAD:计算每对参数(您测试的参数和每个候选参数)的绝对差并将它们相加。最小的数字最接近
  • L2-Norm:计算每对参数的差,将它们平方,求和,取平方根 余弦
  • :将每个参数与另一个参数相乘,然后求和。将结果除以两个对象的长度(L2-范数)的乘积

当然,还有数千种可能性,因此您必须指定您到底想要什么!

Depends, i guess. Several possibilities come to my mind:

  • SAD: calculate the absolute difference of each pair of parameters (the one you test and each of your candidates) and sum them up. Lowest number is closest
  • L2-Norm: Calculate the difference of each pair of parameters, square them, sum them up, take square root
  • Cosine: Multiply each parameter with the other parameter, sum up. Divide result by product of length (L2-Norm) of both objects

of course, there are thousand more possibilities, therefore you have to specify, what you want exactly!

对不⑦ 2024-09-11 18:32:11

您还可以使用欧几里得距离

本质上,您假设每个对象都是 5 维中的一个点,并寻找最近的点(即:距离最短)。

You could also use the Euclidean Distance.

Essentially you pretend each object is a point in 5 dimensions and look for the point that's closest (i.e.: has the shortest distance).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文