3

好吧,我想知道通常哈希函数会创建一个唯一的数字。是否还有可用于近似比较的哈希函数?

所以例如

6 7 8  9 10 11 23 40 10 
5 8 10 9  9 12 24 40 20   would match

25 7 12  9 10 12 90 90    would not match

我想知道这是因为我正在考虑模式识别。我想知道是否有一些数学可以给出你想要找到的匹配百分比。使用 C# 作为编程语言。

一些澄清,首先让我解释一下我喜欢捕捉的同义词。想象一下水滴落下,但它不是恒定流动的。测量工具也不完美。所以现在我正在计时液滴掉落之间的差异,这是一个系列的测量,比如在 19 到 25 个液滴之间,实际上我可以一次测量这样的系列,例如如果我有相机并拍摄它。

现在我想弄清楚下一个系列开始时有这个“系列”是不同还是相同,系列之间可能存在随机时间间隔,并且测量工具不会检测系列的开始或结束,他们一次只进行 19 或 25 次测量。

我不确定该朝哪个方向发展,也许是模糊逻辑,神经网络模式检测,距离向量..有很多方法有接缝,但我想知道会更简单(我在想像哈希之类的东西,但也许应该是别的东西)。

4

1 回答 1

0

Hash functions can be used for (not uniquely) identifying certain values. They are not guaranteed to be unique (better said, it is guaranteed that some different values will have identical hash codes). A small deviation in the value usualy results in a completely different hash code (As @Bobson already has mentioned.) Another use of hash codes is to find in-equality of two values in constant time.

It might be possible to design a hash code function that will do what you want, specialy if you know the domain your values are living in. But that will need a mathematical background to do.

As far as I know there is no hash function for the example you gave.

Here is another idea for integers, use modulo 10 operations and calculate the absolute difference betweeen each digit. This way you calculate the 'distance' between two number, not the 'difference'. I did something similar once on strings to find strings close to each other.

Some pseudo code:

int Distance(int x, int y)
{
    int result = 0;
    while ((x > 0) && (y > 0))
    {
        result += abs(x%10 - y%10);
        x /= 10;
        y /= 10;
    }
    return result;
}

void Caller()
{
    int distance = Distance(123, 456);

    if (distance == 0) write("x and y are equal");
    else write("the relative distance between x and y = " + distance.ToString())'
}
于 2012-11-02T17:25:35.477 回答