我在 x = 1 和 y = 9 之间有一组(浮点)数:
$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
如何计算给定间隔内数字 A 和数字 B 之间的接近度指标?
我试过的
max - min
如果上述集合9 - 1 = 8
的振幅(n - min) / (max - min)
(
(1 - 1) / (9 - 1) = 0
(2 - 1) / (9 - 1) = 0.125
(3 - 1) / (9 - 1) = 0.25
(4 - 1) / (9 - 1) = 0.375
(5 - 1) / (9 - 1) = 0.5
(6 - 1) / (9 - 1) = 0.625
(7 - 1) / (9 - 1) = 0.75
(8 - 1) / (9 - 1) = 0.875
(9 - 1) / (9 - 1) = 1
将最小相对值(在 A 和 B 之间)除以最大相对值(也在 A 和 B 之间),似乎产生了我正在寻找的那种度量。这里有一些例子:
var_dump(min(0.875, 0.25) / max(0.875, 0.25)); // 0.286 between 8 and 3
var_dump(min(0.875, 0.375) / max(0.875, 0.375)); // 0.429 between 8 and 4
var_dump(min(0.875, 0.75) / max(0.875, 0.75)); // 0.857 between 8 and 7
var_dump(min(0.875, 0.875) / max(0.875, 0.875)); // 1 between 8 and 8
var_dump(min(0.25, 0.25) / max(0.25, 0.25)); // 1 between 3 and 3
问题
每当集合的最小值开始起作用时,结果将始终是0
:
var_dump(min(0.875, 0) / max(0.875, 0)); // 0 between 8 and 1
var_dump(min(0.125, 0) / max(0.125, 0)); // 0 between 2 and 1
var_dump(min(0, 0) / max(0, 0)); // 0 between 1 and 1 (ERR!)
关于如何解决这个问题的任何想法?