TruncatedNormalRandom Class
Generate random numbers from a truncated normal distribution (bounded support)
Namespace: KLib.UtilitiesAssembly: KLib.Utilities (in KLib.Utilities.dll) Version: 1.0.0.0 (1.0.0.0)
public class TruncatedNormalRandom
- Inheritance
- Object TruncatedNormalRandom
Transcribed from a MATLAB file by Ken Hancock, Oct 2013. Original MATLAB comments follow:
%RTNORM Pseudorandom numbers from a truncated Gaussian distribution.
%
% X = RTNORM(A,B) returns a pseudorandom variable generated from a normal
% distribution with mean zero and variance one (i.e. standard normal
% distribution) truncated to the interval [A,B].
%
% X = RTNORM(A,B,MU,SIGMA) returns a pseudorandom variable generated from
% a normal distribution with mean MU and variance SIGMA truncated to the
% interval [A,B].
%
% [X,P] = RTNORM(...) also returns the vector of probabilities of X.
%
% This implements an extension of Chopin's algorithm detailed in
% N. Chopin, "Fast simulation of truncated Gaussian distributions", Stat
% Comput (2011) 21:275-288
%
%Copyright (C) 2012 Vincent Mazet (LSIIT, CNRS/Université de Strasbourg),
%Version 2012-07-04, vincent.mazet@unistra.fr
%18/06/2012:
% - first launch of rtnorm.m
%05/07/2012:
% - fix bug concerning the computing of the pdf when (mu,sigma) is
% different from (0,1).
% - fix bug about some indexes out of bounds when computing yl for some
% values of the input arguments.
%04/09/2012:
% - change condition in line 2628 to fix a bug.
%
%Licence: GNU General Public License Version 2
%This program is free software; you can redistribute it and/or modify it
%under the terms of the GNU General Public License as published by the
%Free Software Foundation; either version 2 of the License, or (at your
%option) any later version. This program is distributed in the hope that
%it will be useful, but WITHOUT ANY WARRANTY; without even the implied
%warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%GNU General Public License for more details. You should have received a
%copy of the GNU General Public License along with this program; if not,
%see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt