高斯分布和均勻分布之間的映射關系


step1 生成服從U(0,1)分布的u1,u2;

step2 令 y = [-2*ln(u1)]^0.5*sin(2*pi*u2);

step3 令 x = miu + y*delta,其中miu為均值,delta為標准差

 

代碼:

 

clear all;
close all;
xaxis = -5:0.1:5;
%均值為1方差為1
miu = 1;
delta = 1;
PDFGaussian = 1/sqrt(2*pi*delta^2)*exp(-1/2*((xaxis - miu)/delta).^2);
CDFGaussian = 1/2*(1 + erf((xaxis - miu)/(sqrt(2)*delta)));
PDFGaussian_0 = 1/sqrt(2*pi*delta^2);
plot(xaxis,CDFGaussian,'LineWidth',2);
hold on
plot(xaxis,PDFGaussian,'LineWidth',2);
plot([xaxis(1),xaxis(end)],[0.5 0.5],'r:','LineWidth',2);
plot([miu,miu],[0,1],'r:','LineWidth',2);
plot([xaxis(1),xaxis(end)],[PDFGaussian_0,PDFGaussian_0],'r:','LineWidth',2);
title('Gaussian Distribution')
xlabel('Random variable')
ylabel('PDF and CDF')
N = 100000
u1 = rand(1,N);
u2 = rand(1,N);
y = (-2*log(u1)).^0.5.*sin(2*pi*u2);

var = miu + delta*y;
[sum,loc] = hist(var,100);
prob = sum/N;
prob = [0, prob, 0];
step = loc(2) - loc(1);
loc = [loc(1)-step/2, loc, loc(end)-step/2];
prob = cumsum(prob);
plot(loc,prob,'g*');
legend('Theoretical CDF','Theoretical PDF','data','data','data','Simulated CDF');

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM