func_restricted_sampling.m

来自「This software is a Matlab implementation」· M 代码 · 共 28 行

M
28
字号
function x= func_restricted_sampling(x_mu, x_var, x_min, x_max);
% Matlab implementation of restricted sampling from Gaussian distribution
%
% Objective: sample x (column vector) from N(x_mu, x_var), restricted in
% x_min<=x<=x_max.
%
% input:    x_mu, x_var: the parameter of the pdf of x
%           x_min, x_max: the range of x
% output:   x: the sample
% 
% Acknowledge
% Peter J. Acklam's toolbox for the inverse normal cumulative distribution function
% http://home.online.no/~pjacklam/notes/invnorm/index.html
%
%
% Jing Tian
% Contact me : scuteejtian@hotmail.com
% This program is written in Oct.2004 during my postgraduate studying in 
% NTU, Singapore.

r =  rand(size(x_mu, 1), 1);
y_min = (x_min - x_mu) ./ sqrt(x_var);
y_max = (x_max - x_mu) ./ sqrt(x_var);

nerfcMin = ltpnorm(y_min);
nerfcMax = ltpnorm(y_max);
temp = nerfcMin + (nerfcMax-nerfcMin) .* r;
x = ltqnorm(temp) .* sqrt(x_var) + x_mu;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?