为什么在该代码中减去0.5然后* 2 ......由JAKEDREW(http://www.jakemdrew.com/blog/RgbProjector.htm)

时间:2016-11-06 04:54:40

标签: c#

http://www.jakemdrew.com/blog/RgbProjector.htm

private static double CalculateProjectionSimilarity(double[] source, double[] compare)
{
    if (source.Length != compare.Length)
    {
        throw new ArgumentException();
    }

    var frequencies = new Dictionary();

    ////Calculate frequencies
    for (var i = 0; i < source.Length; i++)
    {
        var difference = source[i] - compare[i];
        difference = Math.Round(difference, 2);
        difference = Math.Abs(difference);
        if (frequencies.ContainsKey(difference))
        {
            frequencies[difference] = frequencies[difference] + 1;
        }
        else
        {
            frequencies.Add(difference, 1);
        }
    }

    var deviation = frequencies.Sum(value => (value.Key * value.Value));

    ////Calculate "weighted mean"
    ////http://en.wikipedia.org/wiki/Weighted_mean
    deviation /= source.Length;

    ////Maximize scale
    deviation = (0.5 - deviation) * 2;

    return deviation;
}

0 个答案:

没有答案