码迷,mamicode.com
首页 > 其他好文 > 详细

高斯分布和均匀分布之间的映射关系

时间:2016-08-11 17:49:18      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:

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‘);

  

 

高斯分布和均匀分布之间的映射关系

标签:

原文地址:http://www.cnblogs.com/waimen/p/5761777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!