为什么减去0.5再乘以2? [英] Why subtract 0.5 and then multiply by 2?

查看:159
本文介绍了为什么减去0.5再乘以2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本网站的部分内容

(使用C#和R使用MapReduce样式特征提取聚类相似图像)

by jakedrew

为什么减去0.5,然后乘以2?



在JAKEDREW LUMINOUSITY直方图中计算相似度函数?

////最大化尺度
偏差=(0.5 - 偏差)* 2; ?????













私有静态双倍CalculateProjectionSimilarity(double [] source,double [] compare)

{

if(source.Length!= compare.Length)

{

抛出新的ArgumentException();

}



var frequency = new Dictionary();



////计算频率
for(var i = 0; i< source.Length; i ++)

{

var diffe rence = source [i] - compare [i];

difference = Math.Round(difference,2);

difference = Math.Abs​​(difference);

if(frequency.ContainsKey(差异))

{

频率[差异] =频率[差异] + 1;

}

其他

{

frequency.Add(差异,1);

}

}



var偏差=频率.Sum(值=> (value.Key * value.Value));



////计算加权平均值

//// http: //en.wikipedia.org/wiki/Weighted_mean

偏差/ = source.Length;



////最大化规模

偏差=(0.5 - 偏差)* 2;



返回偏差;

}



我尝试了什么:



理解代码为什么减去0.5再乘以2?

解决方案

在您正在讨论的文章底部的论坛中发布您的问题。 Jake刚刚在一般论坛中发生的问题变化非常低。


Quote:

为什么减去0.5然后乘以2?

可能因为需要它!

使用debuhher来查看如何构建偏差检查定义。



你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]


part of that in this site
(Clustering Similar Images Using MapReduce Style Feature Extraction with C# and R)
by jakedrew
why subtract 0.5 and then multiply by 2?

IN A JAKEDREW LUMINOUSITY HISTOGRAM CALCULATE SIMILARITY FUNCTION?
////Maximize scale
deviation = (0.5 - deviation) * 2;?????






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;
}

What I have tried:

UNDERSTAND THE CODE why subtract 0.5 and then multiply by 2?

解决方案

Post your question in the forum at the bottom of the article you're talking about. The changes of Jake just happening by your question in the general forums is extremely low.


Quote:

Why subtract 0.5 and then multiply by 2?

Probably because it is needed !
Use the debuhher to see how deviation is built and check against definition.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]


这篇关于为什么减去0.5再乘以2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆