资源简介

% This folder contains a collection of "fitting" functions. % (Some has demo options - the third section) % The GENERAL input to the functions should be samples of the distribution. % % for example, if we are to fit a normal distribution ('gaussian') with a mean "u" and varaince "sig"^2 % then the samples will distribute like: % samples = randn(1,10000)*sig + u % %fitting with Least-Squares is done on the histogram of the samples. % fitting with Maximum likelihood is done directly on the samples. % % % Contents of this folder % ======================= % 1) Maximum likelihood estimators % 2) Least squares estimators % 3) EM algorithm for estimation of multivariant gaussian distribution (mixed gaussians) % 4) added folders: Create - which create samples for the EM algorithm test % Plot - used to plot each of the distributions (parametric plot) % % % % % % Maximum likelihood estimators % ============================= % fit_ML_maxwell - fit maxwellian distribution % fit_ML_rayleigh - fit rayleigh distribution % (which is for example: sqrt(abs(randn)^2+abs(randn)^2)) % fit_ML_laplace - fit laplace distribution % fit_ML_log_normal- fit log-normal distribution % fit_ML_normal - fit normal (gaussian) distribution % % NOTE: all estimators are efficient estimators. for this reason, the distribution % might be written in a different way, for example, the "Rayleigh" distribution % is given with a parameter "s" and not "s^2". % % % least squares estimators % ========================= % fit_maxwell_pdf - fits a given curve of a maxwellian distribution % fit_rayleigh_pdf - fits a given curve of a rayleigh distribution % % NOTE: these fit function are used on a histogram output which is like a sampled % distribution function. the given curve MUST be normalized, since the estimator % is trying to fit a normalized distribution function. % % % % % Multivariant Gaussian distribution % ================================== % for demo of 1

资源截图

代码片段和文件信息

function result = fit_maxwell_pdf( xyWhAx )
% fit_maxwell_pdf - Non Linear Least Squares fit of the maxwellian distribution.
%                   given the samples of the histogram of the samples finds the 
%                   distribution parameter that fits the histogram samples.
%
%    fits data to the probability of the form: 
%        p(r) = sqrt(2/pi)*(a^(-3/2))*(r^2)*exp(-(r^2)/(2*a))
%    with parameter: a
%
% format:   result = fit_maxwell_pdf( xyWhAx )
%
% input:    y   - vector samples of the histogram to be fitted
%           x   - vector position of the samples of the histogram (i.e. y = f(xa))
%           W   - matrix or scalar a square weighting matrix of the size NxN where
%                 N = length(y) or 0 to indicate no weighting is needed.
%           hAx - handle of an axis on which the fitted distribution is plotted
%                 if h is given empty a figure is created.
%
% output:   result  - structure with the fields
%                      a   - fitted parameter
%                      VAR - variance of the estimation
%                      type- weighted LS or not weighted LS
%                      iter- number of iteration for the solution
%

%
% Algorithm
% ===========
%
% We use the WLS algorithm to estimate the PDF from the samples.%
% The maxwell distribution is given by:
%
%    p(xa) = sqrt(2/pi)*(a^(-3/2))*(x.^2).*exp(-(x.^2)/(2*a))
%           = Const * (a^(-3/2)) .* exp(-(x.^2)/(2*a))
%
%    note that X is known and therefore considered a constant vector
%
% The non liner WLS estimator is given by:
%
%    a(n+1) = a(n) + inv(H‘*W*H)*(H‘) * (y-h) = a(n) + G * err

%    where:   h = p(xa)
%             H = diff( p(xa) ) with respect to “a“
%             W = weighting matrix of size NxN  (N = length(y))
%             a = a single parameter to be estimated
%
% The error estimation is given by:
%
%    VAR( a ) = G * VAR( err ) * (G‘)
%
%       or when W=I and the noise is a gaussian noise 
%
%    VAR( a ) = inv( H‘ * H )
%


if (nargin<3)
    error( ‘fit_maxwell_pdf - insufficient input arguments‘ );
end

a       = x(find(y==max(y)))^2;         % initial guess
y       = y(:);                         % both should be column vectors !
x       = x(:);
x2      = x.^2;                         % save computation time
C       = sqrt(2/pi)*x2;                % a constant vector
thresh  = 0.995;                        % convergence threshold for the loop
last_cnt= inf;
iter    = 0;

% check weight matrix input
if (size(W1)==length(y)) & (size(W2)==length(y))
    weights_flag    = 1;
    type            = ‘WLS‘;
else
    weights_flag    = 0;
    type            = ‘LS‘;
end


% Estimation
% =============
if (weights_flag)
    % loop for convergence (with weighting matrix)
    % =============================================
    while (1)
        iter    = iter + 1;
        h       = C*(a^(-1.5)).*exp(-x2/(2*a));
        H       = h.*( x2/(2*

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2009-05-25 05:13  FitFunc\
     目录           0  2004-04-28 13:53  FitFunc\Create\
     文件        1627  2003-11-26 15:15  FitFunc\Create\build_mix_2D_gaussian.m
     文件        1068  2003-11-24 16:53  FitFunc\Create\build_mix_gaussian.m
     文件        4798  2003-11-16 21:49  FitFunc\fit_maxwell_pdf.m
     文件        4276  2003-11-26 15:17  FitFunc\fit_mix_2D_gaussian.m
     文件        2842  2003-11-30 19:10  FitFunc\fit_mix_gaussian.m
     文件        3194  2003-11-17 21:28  FitFunc\fit_ML_laplace.m
     文件        3430  2003-11-17 21:02  FitFunc\fit_ML_log_normal.m
     文件        3017  2003-11-16 21:23  FitFunc\fit_ML_maxwell.m
     文件        3606  2004-04-28 14:16  FitFunc\fit_ML_normal.m
     文件        2867  2003-11-16 21:24  FitFunc\fit_ML_rayleigh.m
     文件        4436  2003-11-16 21:25  FitFunc\fit_rayleigh_pdf.m
     目录           0  2004-04-28 13:53  FitFunc\Plot\
     文件        2088  2003-11-17 21:28  FitFunc\Plot\plot_laplace.m
     文件        2257  2003-11-17 20:04  FitFunc\Plot\plot_log_normal.m
     文件        2105  2003-11-16 23:48  FitFunc\Plot\plot_maxwell.m
     文件        4525  2003-11-26 15:15  FitFunc\Plot\plot_mix_gaussian.m
     文件        2333  2004-04-28 14:11  FitFunc\Plot\plot_normal.m
     文件        2032  2003-11-16 23:48  FitFunc\Plot\plot_rayleigh.m
     文件        2356  2003-12-06 01:42  FitFunc\readme.m
     文件        1329  2009-05-25 05:13  license.txt

评论

共有 条评论