简体   繁体   English

谁能帮我解决一个算法? (设置一个大范围值的权重)

[英]Could anyone help me on solve an algorithm? (Set a weight of a big range value)

I was wondering how to set a weight for a computation of huge different values.我想知道如何为巨大的不同值的计算设置权重。 I will try to explain it better, or maybe in details.我会尝试更好地解释它,或者更详细地解释它。

The idea is: I would like to have as a result a value in this range [1,20] given: 1) first value: a 1a) with a format like 0.1 or 0.0001 or 0.00001 etc. 1b) maximum decimal length = 5 decimals 2) second value: b 2a) assumption that is less than a (if a=0.01, at least b=0.00999 etc.) 2b) with the same format 2c) maximum decimal length = 6 decimals (so 1 grater than a)这个想法是:我希望得到一个在这个范围 [1,20] 中的值:1) 第一个值:a 1a) 格式为 0.1 或 0.0001 或 0.00001 等 1b) 最大十进制长度 = 5小数 2) 第二个值:b 2a) 假设小于 a(如果 a=0.01,至少 b=0.00999 等) 2b) 具有相同格式 2c) 最大小数长度 = 6 位小数(因此比 a 大 1)

where, given for example a=0.01 and b=0.0001其中,例如给定 a=0.01 和 b=0.0001

x = a/b = 100

a second example a=0.01 and b=0.00001第二个例子 a=0.01 和 b=0.00001

x = a/b = 1000

I thought at something like this: If maximum could be (when a=0.1 and b=0.000001) = 100000 than it correspond to 20 (the new maximum scale) and if I count the difference of number of decimals I can say that: 'a' has 1 decimal 'b' has 6 decimal In general we can have a maximum difference of 5, so:我想过这样的事情:如果最大值可以是(当 a=0.1 和 b=0.000001 时)= 100000,那么它对应于 20(新的最大比例),如果我计算小数位数的差异,我可以说:' a' 有 1 位小数 'b' 有 6 位小数 一般来说,我们可以有 5 的最大差异,所以:

max = 5

So using this calculus:所以使用这个微积分:

diff=6-1=5

in order to correspond their fraction (a/b) as the maximum value (20) I can do: (diff*20)/max give me 20. That's ok.为了将它们的分数 (a/b) 对应为最大值 (20),我可以这样做: (diff*20)/max给我 20。没关系。 Now, If I have a=0.1 and b=0.000002 I can use the least significant number of 'b' (in this case '2' of 0.000002) and compare with the least significant of 'a', and I can say that现在,如果我有 a=0.1 和 b=0.000002,我可以使用 'b' 的最低有效数(在本例中为 0.000002 的 '2')并与 'a' 的最低有效数进行比较,我可以说

diff=6-1=5

Now subtract 0.2 (because the least significant number was 2) to have 4.8.现在减去 0.2(因为最低有效数是 2)得到 4.8。 Now recompute:现在重新计算:

4.8*20/max = 19.2

So for 0.1 and 0.000003 would be所以对于 0.1 和 0.000003 将是

diff=6-1=5
diff=diff-0.3 = 4.7
4.7*20/max = 18.8

And so on.等等。

The problem is that when I have a=0.3 and b=0.0002 (for example) I don't know how to manage it.问题是,当我有 a=0.3 和 b=0.0002(例如)时,我不知道如何管理它。

Could anyone suggest me a solution or a bunch of that even with a pseudo-code or procedure?即使使用伪代码或程序,任何人都可以向我建议解决方案或一堆解决方案吗? Maybe I will do the translation in java by myself.也许我会自己用java来翻译。

I don't know where to post my question, if so I really apologize if I wrong some rules of these website, otherwise everything is fine :-) Thank you all我不知道在哪里发布我的问题,如果是这样,如果我弄错了这些网站的某些规则,我真的很抱歉,否则一切都很好:-)谢谢大家

Have you looked at logarithms?你看过对数吗?

 d = (log(a) - log(b))/log(10)

should give the answer.应该给出答案。 In other words, log(a)/log(10) gives you换句话说, log(a)/log(10) 给你

0.1   -->  -1
0.01  -->  -2
0.001 -->  -3 

etc. So, you can calculate differences the way you want.等等。所以,你可以按照你想要的方式计算差异。 And in the end,最后,

exp(d*log(10))

is the actual ratio.是实际比例。 In java, use Math.log()在 java 中,使用Math.log()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以帮助我使用omniORB吗? - Could anyone help me with omniORB? 我尝试使用多态性,但我的代码不能像我预期的那样工作,有人可以帮我解决这个问题吗? - I try to use polymorphism but my code does not work as i excpected, could anyone help me solve this problem? 有人可以帮我用Arduino草图来控制电机操作吗? - Could anyone help me with an Arduino sketch to control motor operation? 有人可以帮我调试我的应用程序(不是很大)吗? - Could someone help me debug my app (not very big)? 遇到找不到或无法加载主类错误的情况,有人可以帮助我修复该错误吗? 我是Java新手 - Getting a could not find or load main class error, can anyone help me fix it? I'm new to java 谁能帮我找到一种方法来将新用户(新注册)的字段显示到 Android Studio 应用程序的活动中? - Could anyone help me find a way to show the fields of the a new user (newly registered) into an activity of an Android Studio app? 我无法在程序中使用PrinterWriter,有人可以帮我解决吗? - I can't use PrinterWriter in my program, could anyone help me figure it out? 任何人都可以帮助我如何使用接口? - Can anyone help me with how to use interfaces? 谁能帮我解决这个Java错误? - Can anyone help me with this java error ??? 有人可以通过Hibernate和JSF来帮助我解决这一缺点吗? - Can anyone help me with this drawback with Hibernate and JSF?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM