概率和百分比的解释 [英] Interpretations of probabilities and percentages

查看:894
本文介绍了概率和百分比的解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常感谢您为我的模型编码提供帮助,

Thank you very much for your help for coding my model,

如果您不介意的话,我想问您有关编码的一些解释 抱歉,我不是数学专家

If you do not mind please, I want to ask you about some interpretations in the coding I am sorry I am not expert in mathematics

to move
ask turtles with [gender = "male" ]
[ if ( random-float 1) <= 0.025]

为什么是< =以及此代码的解释是什么

why it is <= and what is the interpretation of this code,

以及百分比

 ask turtles

  [ if random 100 <= 50
       [become-fat]]

同样的问题,为什么< =如果我们总是说组中的50%会很胖,为什么我们要放这个符号呢???

the same question why <= if we always say 50 % in the group will be fat why we put this sign???

以及随机浮点数和随机浮点数有什么区别

and what is the different between random and random float

抱歉打扰

推荐答案

两个原语之间的区别在于:

The difference between the two primitives is that:

  • random gives you only integer numbers, e.g.: 0, 1, 2, 3, etc.
  • random-float gives you floating point numbers, e.g.: 0.0, 0.125, 0.528476587245, 3.66, etc.

在NetLogo中,这两种方法都可以使概率发生的事情.我将从使用random开始,这更容易理解.

Both can be used to make things happen probabilistically in NetLogo. I'll start with the use of random, which is slightly easier to understand.

文档中所述,如果您传递的是正数到random,它将为您提供一个大于或等于0,但严格小于该数字的数字.

As stated in the documentation, if you pass a positive number to random, it will give you a number that is greater or equal to 0, but strictly less than that number.

例如,random 2始终会为您提供0或1.您可以使用它来模拟硬币的翻转:

For example, random 2 will always give you either 0 or 1. You could use that to simulate the flipping of a coin:

ifelse random 2 = 0 [ print "heads" ] [ print "tail" ].

那将打印50%的时间(当random 2给你0时)和"tail" 50%的时间(当random 2给你1时).

That will print "heads" 50% of the time (when random 2 gives you 0), and "tail" 50% of the time (when random 2 gives you 1).

现在,使用random 100而不是random 2可以很容易地将其概括为以百分比表示的概率.我将以50%的示例为例,但是很可能是25%,80%甚至1%或100%.

Now it's easy to generalize this to probabilities expressed in percentages by using random 100 instead of random 2. I'll use an example with 50%, but it could very well be 25%, 80% or even 1% or 100%.

现在,由于random 100为您提供一个介于0和99之间的数字,这意味着它可以为您提供的前50个数字为:0、1、2、3 ...一直到49. 50是:50、51、52、53 ...一直到99.如果您愿意,可以想象一个标记为0到99的100面骰子.

Now since random 100 gives you a number between 0 and 99 inclusively, it means that the first 50 numbers it can give you are: 0, 1, 2, 3... all the way to 49. And the next 50 are: 50, 51, 52, 53... all the way to 99. You can imagine a 100-sided dice labeled from 0 to 99 if you wish.

如果您希望海龟50%的时间变胖",则可以执行以下操作:

If you want your turtles to "become fat" 50% of the time, you can do:

ask turtles [ if random 100 < 50 [become-fat] ]

请注意,我使用<(严格小于)符号代替了<=(小于或等于)符号.这是因为我只希望当骰子"落在前50个面之一(从0到49)中时,海龟会变胖.

Notice that I used the < (strictly less) sign instead of the <= (less or equal) sign. This is because I only want the turtles to become fat if the "dice" lands on one of the first 50 faces, from 0 to 49.

(如果您使用的是random 100 <= 50,就像上面发布的代码一样,它们实际上有51%的可能性变胖,有49%的可能性变胖.现在,您应该还能够弄清楚为什么if random 100 = 50之类的东西没有意义:只有当骰子"恰好落在50上时才是正确的,这仅发生1%的时间.)

(If you used random 100 <= 50, like in the code you posted above, they would actually have a 51% probability of becoming fat and a 49% probability to not become fat. You should now also be able to figure out why something like if random 100 = 50 doesn't make sense: it would only be true if the "dice" lands exactly on 50, which happens only 1% of the time.)

如果您希望海龟仅20%的时间变胖,则希望使用骰子的前20个面(从0到19):

If you wanted your turtles to become fat only 20% of the time, you'd want to use the first 20 faces of the dice, from 0 to 19:

ask turtles [ if random 100 < 20 [become-fat] ]

在NetLogo中处理概率时,通常使用random 100就足够了.

It is often enough to use random 100 when dealing with probabilities in NetLogo.

但是,有时您需要更高的精度.面向数学的工作通常将概率表示为介于0.0(对于0%)和1.0(对于100%)之间的数字.在这些情况下,random-float 1会派上用场.再次,如文档中 所述,random-float将给出您在0(含)和您传递给它的数字(含)之间的数字.因此,random-float 1为您提供一个介于0.0和1.0之间的数字(但绝不完全是1.0).

Sometimes, however, you need a little more precision. And mathematically oriented work often expresses probabilities as numbers between 0.0 (for 0%) and 1.0 (for 100%). In those cases, random-float 1 comes handy. Again, as stated in the documentation, random-float will give you a number between 0 (inclusively) and the number you pass to it (exclusively). Thus, random-float 1 gives you a number between 0.0 and 1.0 (but never exactly 1.0).

此表达式:

random-float 1 < 0.025

2.5%的时间内为真.

will be true 2.5% of the time.

骰子隐喻不适用于random-float,但是您可以想象轮盘赌轮(或命运之轮).询问random-float 1 < 0.025是否就像画一个占车轮周长2.5%的扇形切片",旋转车轮,并检查球(或箭头,或其他)是否落在该切片中.

The dice metaphor doesn't work for random-float, but you can imagine a roulette wheel (or a wheel of fortune). Asking if random-float 1 < 0.025 is like painting a "pie slice" that's 2.5% of the circumference of the wheel, spinning the wheel, and checking if the ball (or the arrow, or whatever) falls in that slice.

现在,如果将<=而不是<random-float一起使用,是否有关系?不是很多.如果车轮恰好落在将您的馅饼切片与车轮其余部分分开的线上 ,并且发生的可能性非常小,那只会有所不同.

Now does it matter if you use <= instead of < with random-float? Not a whole lot. It would only make a difference if the wheel falls exactly on the line that separates your pie slice from the rest of the wheel, and the probability of that happening is very very small.

这篇关于概率和百分比的解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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