<p>这里有几个问题对你不利。底线在前面:</p>
<ol>
<li>你的代码没有达到你所说的意图</李>
<li>你目前没有衡量你的结果是否与理论答案相符的标准;及</li>
<li>你对正确答案的期望是不正确的</李>
</ol>
<p>我觉得您的代码对于您描述的任务来说过于复杂,所以我从头开始编写了自己的版本。我计算出了滚动六个10面骰子的基本实验,并通过创建一个由10面骰子滚动组成的长度为6的列表来检查结果是否都相等。我无耻地借用BoarGules的评论,将结果放入一个只存储唯一元素的集合中,并计算集合的大小。当且仅当集合的大小为1时,骰子的值都相同。当不同元素的数量大于1时,我不断重复这一点,记录所需的试验次数,并在获得相同的模辊后返回试验次数</p>
<p>然后,对任何所需数量的复制运行该基本实验,并将结果放入numpy数组中。结果数据由numpy和scipy处理,得出平均试验次数和平均值的95%置信区间。置信区间使用结果的估计可变性来构造平均值的下限和上限。如果基本假设得到满足,以这种方式生成的边界应包含以这种方式生成的95%估计值的真实平均值,并解决我的BLUF中的第二点</p>
<p>代码如下:</p>
<pre class="lang-python prettyprint-override"><code>import random
import scipy.stats as st
import numpy as np
NUM_DIGITS = 6
SAMPLE_SIZE = 1000
def expt():
num_trials = 1
while(len(set([random.randrange(10) for _ in range(NUM_DIGITS)])) > 1):
num_trials += 1
return num_trials
data = np.array([expt() for _ in range(SAMPLE_SIZE)])
mu_hat = np.mean(data)
ci = st.t.interval(alpha=0.95, df=SAMPLE_SIZE-1, loc=mu_hat, scale=st.sem(data))
print(mu_hat, ci)
</code></pre>
<p>从10面模具中产生6个特定值的相同结果的概率为10<sup>-6</sup>,但有10个可能的特定值,因此产生所有重复的总概率为10*10<sup>-6</sup>,或10<sup>-5</sup>。因此,在获得一组复制品之前,预期的试验次数为10次<sup>5次<sup>。上面的代码在我的计算机上运行了5分钟多一点,并生成了<code>102493.559 (96461.16185897154, 108525.95614102845)</code>作为输出。四舍五入到整数,这意味着平均试验次数为102493次,我们有95%的信心认为真实平均数介于96461和108526之间。该特定范围包含10<sup>5</sup>,即与预期值一致。重新运行程序将产生不同的数字,但95%的运行也应该包含预期值,不包含预期值的少数应该仍然很接近</p>