使用具有中心极限定理的Matlab的偏心模具的PDF和CDF [英] PDF and CDF for Biased die using Matlab with Central Limit Theorem

查看:182
本文介绍了使用具有中心极限定理的Matlab的偏心模具的PDF和CDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用中心极限定理(CLT)绘制10 ^ 4个样品的偏斜模具辊的PDF和CDF.

I am trying to plot the PDF and CDF for a biased die roll for 10^4 samples using Central Limit Theorem.(CLT)

死亡是有偏见的或不公平的,偶数面的可能性是奇数面的两倍.这是diefaces = [1,3,2,4,6,2].在这种情况下,对于CLT,在Sn = X1 + X2 + ... + Xn的情况下,我可以在Matlab中使用什么查找奇数的概率n = 40.

The die is biased or unfair where even sides are twice as likely as odd sides. Here is the diefaces = [1,3,2,4,6,2].What can I use in Matlab to find probability of an odd number in this case with CLT where Sn = X1 + X2 + ... + Xn , n = 40.

这是到目前为止我尝试过的.我正在努力的部分正在通过样本,在这种情况下,样本为10 ^ 4,n = 40.感谢任何帮助....

Here is what I have tried so far. The part that I am struggling with is passing the samples which in this case is 10^4 and n=40. Appreciate any help....

clear
% Roll the dice "numberOfRolls" times
numberOfRolls = 10000; % Number of times you roll the dice.
% Biased die with even sides twice as likely as a odd number
diefaces = [1,3,2,4,6,2];
n = 1; % Number of dice.
maxFaceValue = 6;
% Pick a random number from diefaces along with the number of rolls which
% is not working :(
x = diefaces(randperm(numel(diefaces),1),10000)


    S1 = cumsum(x)
    hist1= histogram(S1(1,:),'Normalization','pdf','EdgeColor', 'blue', 'FaceColor',  'blue')

推荐答案

定义模具并获得有效的自定义模具的概率质量函数(PMF).您可以通过确保sum(Prob)等于1来验证PMF.请注意,可以通过将RelChance设置为[1 1 1 1 1 1]来获得公平的模头.

Define your die and obtain a valid probability mass function (PMF) for your custom die. You can verify the PMF by ensuring sum(Prob) equals 1. Note that a fair die is obtained by setting RelChance to [1 1 1 1 1 1].

下面的骰子面概率为[1/9 2/9 1/9 2/9 1/9 2/9].

Die = [1 2 3 4 5 6];
RelChance = [1 2 1 2 1 2];            % Relative Chance
Prob = RelChance./sum(RelChance);     % probability mass function for die

您可以使用 datasample() 模拟滚动广告的结果死亡(需要统计工具箱).如果绝对有必要通过几种方法对硬代码进行编码,这很容易.

You can use datasample() to simulate the outcome of rolling the die (requires Statistics toolbox). This is easy enough to hard code if absolutely necessary through several methods.

下面的代码从 Die 中多次读取 sample NumRolls 次,并且具有概率 Prob(ii) Die(ii).

The code below reads sample NumRolls many times from Die with the probability Prob(ii) representing the probability of Die(ii).

% MATLAB R2019a
NumRolls = 13;                        % Number of rolls 
Rolls = datasample(Die,NumRolls,'Weights',Prob);

现在,要使用它来完成所述目标.与本文类似,创建一个数组X,该数组的第一行是X1的实现,第二行是X2的实现,依此类推.不必花哨.

Now, to use this to accomplish the stated goal. Similar to this post, create an array X that has the first row as realizations of X1, the second row realizations of X2, and so on. This doesn't have to be fancy.

然后再次使用 cumsum() 来获取累积值沿列求和.这意味着第一行是S1=X1的实现,第二行是S2=X1+X2的实现,第40行是S40 = X1 + X2 + ... + X40的经验样本.

And again, use cumsum() to get the cumulative sum along the columns. This means the first row is realizations from S1=X1, second row is realizations from S2=X1+X2, and the 40th row is empirical samples from S40 = X1 + X2 + ... + X40.

n_max = 40;
NumRolls = 10000;
X = zeros(n_max,NumRolls);
for n = 1:n_max
    X(n,:) = datasample(Die,NumRolls,'Weights',Prob);
end
Sn = cumsum(X);

如何绘制?在这一点上,由于我们的变量名与过程匹配,因此其余步骤(绘图)与概率密度函数(PDF)的引用已重新标记为

How to Plot? At this point, since our variable names match the process, the remaining steps (plotting) are identical to this post but with a few minor modifications. Since this is discrete (not continuous) data, I generated the plot below using the 'Normalization','probability' option for histogram(). References to a probability density function (PDF) have been relabeled probability mass function (PMF) accordingly.

中央极限定理的连续版本发布在此处.

Continuous version of the Central Limit Theorem is posted here.

这篇关于使用具有中心极限定理的Matlab的偏心模具的PDF和CDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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