SaS稳定分布函数(symmetric D -stable distribution)

来源:互联网 发布:12306订票软件 编辑:程序博客网 时间:2024/05/21 10:25

alpha为指数参数,beta为对称参数,gamma为尺度参数或分度参数(dispersion parameter),delta为本地参数
stblrnd(alpha,beta,gamma,delta,varargin)

function r = stblrnd(alpha,beta,gamma,delta,varargin)%STBLRND alpha-stable random number generator.% R = STBLRND(ALPHA,BETA,GAMMA,DELTA) draws a sample from the Levy % alpha-stable distribution with characteristic exponent ALPHA, % skewness BETA, scale parameter GAMMA and location parameter DELTA.% ALPHA,BETA,GAMMA and DELTA must be scalars which fall in the following % ranges :%    0 < ALPHA <= 2%    -1 <= BETA <= 1  %    0 < GAMMA < inf %    -inf < DELTA < inf%%% R = STBLRND(ALPHA,BETA,GAMMA,DELTA,M,N,...) or % R = STBLRND(ALPHA,BETA,GAMMA,DELTA,[M,N,...]) returns an M-by-N-by-... % array.   % %% References:% [1] J.M. Chambers, C.L. Mallows and B.W. Stuck (1976) %     "A Method for Simulating Stable Random Variables"  %     JASA, Vol. 71, No. 354. pages 340-344  %% [2] Aleksander Weron and Rafal Weron (1995)%     "Computer Simulation of Levy alpha-Stable Variables and Processes" %     Lec. Notes in Physics, 457, pages 379-392%if nargin < 4    error('stats:stblrnd:TooFewInputs','Requires at least four input arguments.'); end% Check parametersif alpha <= 0 || alpha > 2 || ~isscalar(alpha)    error('stats:stblrnd:BadInputs',' "alpha" must be a scalar which lies in the interval (0,2]');endif abs(beta) > 1 || ~isscalar(beta)    error('stats:stblrnd:BadInputs',' "beta" must be a scalar which lies in the interval [-1,1]');endif gamma < 0 || ~isscalar(gamma)    error('stats:stblrnd:BadInputs',' "gamma" must be a non-negative scalar');endif ~isscalar(delta)    error('stats:stblrnd:BadInputs',' "delta" must be a scalar');end% Get output size[err, sizeOut] = genOutsize(4,alpha,beta,gamma,delta,varargin{:});if err > 0    error('stats:stblrnd:InputSizeMismatch','Size information is inconsistent.');end%---Generate sample----% See if parameters reduce to a special case, if so be quick, if not % perform general algorithmif alpha == 2                  % Gaussian distribution     r = sqrt(2) * randn(sizeOut);elseif alpha==1 && beta == 0   % Cauchy distribution    r = tan( pi/2 * (2*rand(sizeOut) - 1) ); elseif alpha == .5 && abs(beta) == 1 % Levy distribution (a.k.a. Pearson V)    r = beta ./ randn(sizeOut).^2;elseif beta == 0                % Symmetric alpha-stable    V = pi/2 * (2*rand(sizeOut) - 1);     W = -log(rand(sizeOut));              r = sin(alpha * V) ./ ( cos(V).^(1/alpha) ) .* ...        ( cos( V.*(1-alpha) ) ./ W ).^( (1-alpha)/alpha ); elseif alpha ~= 1                % General case, alpha not 1    V = pi/2 * (2*rand(sizeOut) - 1);     W = - log( rand(sizeOut) );           const = beta * tan(pi*alpha/2);    B = atan( const );    S = (1 + const * const).^(1/(2*alpha));    r = S * sin( alpha*V + B ) ./ ( cos(V) ).^(1/alpha) .* ...       ( cos( (1-alpha) * V - B ) ./ W ).^((1-alpha)/alpha);else                             % General case, alpha = 1    V = pi/2 * (2*rand(sizeOut) - 1);     W = - log( rand(sizeOut) );              piover2 = pi/2;    sclshftV =  piover2 + beta * V ;     r = 1/piover2 * ( sclshftV .* tan(V) - ...        beta * log( (piover2 * W .* cos(V) ) ./ sclshftV ) );                end    % Scale and shiftif alpha ~= 1   r = gamma * r + delta;else   r = gamma * r + (2/pi) * beta * gamma * log(gamma) + delta;  endend%====  function to find output size ======%function [err, commonSize, numElements] = genOutsize(nparams,varargin)    try        tmp = 0;        for argnum = 1:nparams            tmp = tmp + varargin{argnum};        end        if nargin > nparams+1            tmp = tmp + zeros(varargin{nparams+1:end});        end        err = 0;        commonSize = size(tmp);        numElements = numel(tmp);    catch        err = 1;        commonSize = [];        numElements = 0;    endend




0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 猫走了财运变差怎么办 特别在意别人的眼光怎么办 入职两个月没有业绩怎么办 在学舞蹈中孩子怕疼怎么办 我生二胎怕疼怎么办 孩子的执行力差怎么办 怀孕三个月不想要孩子怎么办 生完孩子老是掉头发怎么办 5岁半宝宝有狐臭怎么办? 4岁宝宝脾气倔怎么办 小孩子摔到后脑勺吐了怎么办 学生报告册丢了怎么办 错过宝宝语言敏感期怎么办 父亲骂我很难听怎么办 90后父母催婚怎么办 和隔壁邻居吵架了怎么办 教师上课期间孩子出问题责任怎么办 孩子一考试妈妈就焦虑怎么办 妈妈爱发脾气孩子也发脾气怎么办 孩子对家人有抵触情绪怎么办 孩子因为没耐心哭闹怎么办 宝宝哭闹真是没耐心怎么办 对自己孩子没耐心怎么办 跳了把腰伤了怎么办 爸爸对妈妈家暴怎么办 逆反心强23岁怎么办 觉得自己心理有问题怎么办 小孩心理脆弱过于敏感怎么办? 父母老是骂打我怎么办 爸妈打架闹离婚怎么办 夫妻离婚后孩子户口怎么办 离婚后孩子户口怎么办落户 50岁父母要离婚怎么办 父母离婚小孩没有出生证该怎么办 离婚。父母一直在劝说该怎么办 老婆跟人跑了怎么办啊 父母50了要离婚怎么办 父母吵架了我该怎么办 父母看孩子总是吵架怎么办 20岁父母离婚我怎么办 碰到没素质的人怎么办