如何模拟通过电线传输错误位?

发布于 2024-11-29 23:35:26 字数 296 浏览 0 评论 0原文

所以我有以下作业,但我不明白具体的过程是什么。有没有人以前见过这个问题或者真正理解逻辑应该是什么?我不需要代码,我知道如何编程,但我不完全知道在这里做什么。

考虑一条数据通过其逐位传输的线路。有时,一点或一群 连续位传输不正确。如果前一位传输正确,则 当前位传输错误的概率为 0.1。如果前一位是 传输错误,当前位也传输错误的概率 是0.3。编写一个名为BitError.java的程序,模拟传输一百万 位并打印出错误传输的位的百分比。 (提示:根据理论,预期答案是12.5%。)

So I have the following homework, but I don't understand exactly what the process is. Has anyone seen this question before or actually understands what the logic should be? I don't want code, I know how to program, but I don't exactly know what to do here.

Consider a wire across which data is transmitted bit-by-bit. Occasionally, a bit or a group of
consecutive bits is transmitted incorrectly. If the previous bit was transmitted correctly, the
probability that the current bit is transmitted incorrectly is 0.1. If the previous bit was
transmitted incorrectly, the probability that the current bit is also transmitted incorrectly
is 0.3. Write a program called BitError.java that simulates the transmission of one million
bits and prints out the percentage of bits transmitted incorrectly.
(Hint: According to theory, the expected answer is 12.5%.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南城追梦 2024-12-06 23:35:26

您按如下方式测试事件发生的概率

  1. 生成 0 到 1 之间的均匀随机数
  2. 如果生成的数字小于事件发生的概率,则事件发生

您的代码应如下所示

// Generate random bit either a 0 or a 1
int bit = RandInt(0,1)

// Assume first bit was correct
bool bPreviousWasCorrect = false;

Loop 1 million times
    double probBitIsCorrect = RandUnif(0,1) // get a random number between 0 and 1
    if bPreviousWasWrong then
        // if an error has occured then a 2nd error occurs with prob 0.3
        if (probBitIsCorrect < 0.3)  then
           Set bPreviousWasWrong to true
           increment number of wrong bits
        else
           Set bPreviousWasWrong to false
           increment number of correct bits
        end if
    else
        if (probBitIsCorrect < 0.1)  then
           Set bPreviousWasWrong to true
           increment number of wrong bits
        else
           Set bPreviousWasWrong to false
           increment number of correct bits
        end if

Display results when done

You test for the probability of an event happening as follows

  1. Generate a uniform random number between 0 and 1
  2. If the number generated is less than the prob an event happening then the event happend

Your code should look something like this

// Generate random bit either a 0 or a 1
int bit = RandInt(0,1)

// Assume first bit was correct
bool bPreviousWasCorrect = false;

Loop 1 million times
    double probBitIsCorrect = RandUnif(0,1) // get a random number between 0 and 1
    if bPreviousWasWrong then
        // if an error has occured then a 2nd error occurs with prob 0.3
        if (probBitIsCorrect < 0.3)  then
           Set bPreviousWasWrong to true
           increment number of wrong bits
        else
           Set bPreviousWasWrong to false
           increment number of correct bits
        end if
    else
        if (probBitIsCorrect < 0.1)  then
           Set bPreviousWasWrong to true
           increment number of wrong bits
        else
           Set bPreviousWasWrong to false
           increment number of correct bits
        end if

Display results when done
誰ツ都不明白 2024-12-06 23:35:26

他们希望你写一个模拟器。您创建一个循环,进行一百万次迭代,每次迭代代表一位的传输。每次您根据这两个规则随机决定该位传输是否正确,并保持计数。

最后,您的模拟将告诉您正确传输了多少位(显然应该接近 87.5%)。

They want you to write a simulator. You make a loop which does one million iterations, each iteration representing the transmission of one bit. Every time you decide randomly if the bit gets transmitted correctly or incorrectly, based on the two rules, and keep count.

At the end, your simulation will tell you how many bits were transmitted correctly (which should apparently be close to 87.5%).

蓝眸 2024-12-06 23:35:26

好的,所以您需要一点一点地“传输”数据,并在每次迭代时计算概率。

让我们考虑第一个比特的传输与前面正确传输的比特的概率有关。这意味着下一次迭代正确传输第一位的概率为 0.9


如果位 1 传输正确,则正确概率为 0.9,否则为 0.7

ok, so you need to "transmit" the data bit by bit and on each iteration calculate the probability.

let's consider that the transmission of the first bit is with the probability of a bit with a preceding correct transmission. this means that the first bit's probability to be transmitted correctly is 0.9

next iteration:
if bit 1 was transmitted correctly, do probability 0.9 for correct, otherwise 0.7

一身软味 2024-12-06 23:35:26

这就是为什么它被称为家庭作业……它的设计目的是让你不知道该怎么做。

该问题涉及递归和迭代。 Google:递归。给定当前状态(无论前一个位是否正确传输),您可以计算当前位正确传输的概率。之后,通过简单概率(例如乘法)即可得到 12.5%。您甚至可以在不循环所有位的情况下完成此操作,具体取决于您了解多少统计数据。

最后你应该了解所有关于递归的知识。这就是任务的真正目的。您的基本情况是什么(即第一位)以及您的递归步骤是什么(即此后的每一位)?一旦理解了这一点,编写 Java 就应该很容易了。

That's why it's called homework.... It's deigned so that you don't exactly know what to do.

The problem relates to recursion and iteration. Google: Recursion. Given the current state (whether or not the previous bit was transmitted correctly or not) you can calculate the probability that the current bit is transmitted correctly. After that, it's simple probability (e.g. multiplication) to get 12.5%. You may even be able to do it without looping through all the bits, depending on how much statistics you know.

At the end you should know all about recursion. That's what the assignment is really about. What is your base case (i.e. the first bit) and what is your recursive step (i.e. each bit thereafter)? Once you understand that, writing the Java should be easy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文