4.47059

4.5 | 17 ratings Rate this file 293 downloads (last 30 days) File Size: 23.63 KB File ID: #4222

A Collection of Fitting Functions

by Ohad Gal

 

05 Dec 2003 (Updated 29 Apr 2004)

Code covered by BSD License  

A collection of fitting functions for various distributions.

Download Now | Watch this File

File Information
Description

%
% 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 1D mixed-gaussian fitting, run: fit_mix_gaussian
% for demo of 2D mixed-gaussian fitting, run: fit_mix_2d_gaussian
%
% these routines fit and plot the results of the parameters of:
% random distribution of random amount of gaussians with random parameters
%

MATLAB release MATLAB 6.1 (R12.1)
Zip File Content  
Other Files
FitFunc/Create/build_mix_2D_gaussian.m,
FitFunc/Create/build_mix_gaussian.m,
FitFunc/fit_maxwell_pdf.m,
FitFunc/fit_mix_2D_gaussian.m,
FitFunc/fit_mix_gaussian.m,
FitFunc/fit_ML_laplace.m,
FitFunc/fit_ML_log_normal.m,
FitFunc/fit_ML_maxwell.m,
FitFunc/fit_ML_normal.m,
FitFunc/fit_ML_rayleigh.m,
FitFunc/fit_rayleigh_pdf.m,
FitFunc/Plot/plot_laplace.m,
FitFunc/Plot/plot_log_normal.m,
FitFunc/Plot/plot_maxwell.m,
FitFunc/Plot/plot_mix_gaussian.m,
FitFunc/Plot/plot_normal.m,
FitFunc/Plot/plot_rayleigh.m,
FitFunc/readme.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (21)
29 Jan 2004 Aaron Clarke

Works great and the graphs are aesthetically pleasing.

12 Mar 2004 Rafi Levi  
15 Jun 2004 P Z

1D Gaussian works great. 2D Gaussian gives significantly different (and more poorly fit) results than other EM implementations I've tried, e.g., Netlab and Weka.

06 Jul 2004 Fabio Labra

Works great and has neat graphics. First time I find a function for ML fitting of laplace distribution.

29 Jul 2004 M C

Great stuff! Seems really usable, at least the 1D functions.

19 Oct 2004 Richard Xiao

great tools for gaussian 1D fittings, thanks.

14 Nov 2004 Shane Lin

really good stuff. thanx

10 Jan 2005 seth man

I'm finished my take home test with this stuff

24 Jul 2005 J Lansey

Wow! thats perfect, the author is an EXPERT coder. Proffesionall i'd say.
Thanks!

13 Sep 2005 Leif Adelow

Missing subroutine or toolbox containing 'mvnrnd'.

??? Undefined function or variable 'mvnrnd'.

18 Oct 2005 pau soler

Thank you for such great routines.

06 Nov 2006 John Finan

I hit a snag that cost me an hour and I thought I would try to save someone else the time. Disclaimer: I have only been playing with this code for a few hours. I have NOT read it all and I don't fully understand it.

The snag involved plotting the output from a fit of mixed gaussians in one dimension. When I generated the data using build_mix_gaussian, a plot was created. Then, fit_mix_gaussian would plot into that figure without any trouble.

However, when I was using my own data, I didn't run build_mix_gaussian first and the output from fit_mix_gaussian got all messed up.

Here's the change I made in the very last line of fit_mix_gaussian to fix it.

% plot_mix_gaussian( u,sig,t );
plot_mix_gaussian( u,sig,t,X );

Comments from the author or other users are very welcome.

30 Jun 2007 venkatesh siva

thanks

11 Sep 2007 Yong-Jun Cho

thanks!

27 Nov 2007 Todd Arnold

The provided files are an excellent source for EM based Matlab work.

13 Dec 2007 Thomas Clark

This submission requires the statistics toolbox, in order to use the 2D gaussian fit (line 32, build_mix_2D_gaussian.m)

23 Dec 2007 mahdi poorakbari  
04 Jun 2008 Harish Viswanathan  
18 Jun 2008 Elli Dolev

Hello there,
I found your application very usfull and I winder if it is possible to use it and to ask you one question please.
Thank you,
Elli

01 Nov 2008 Om Ken

Guys, i use Randraw function to generate data randomly from a truncated normal distribution, but when i tested the generated data if they have come from a Normal distribution (not truncated), the hypothesis was rejected. which means that the data can not be assumed to have come from a Normal distribution, If I use the Normal distribution to fit my collected data using for example dfittool tool box, I get a mean and sigma values , when I use them to genera data from the randraw function with using (y = randraw('normaltrunc', [0, +inf, mu, sigma], 1, 1e5), the data obtained do not follw a normal distribution. so what i need is some kind of distribution fitting tool that can fit my original field collected data to a left Truncated normal distribution and give me the right parameters , i.e. mu and sigma
regards

05 Feb 2009 c a

Had similar problem to John Finan above and used same fix. However have other problem with fit_mix_gaussian: it seems to be sensitive to magnitude to data. Using data scaled from appr. -0.7 to 5 it gives me a fit which is incorrect (data is skewed in some manner I have not identified). Changing the magnitude of the input vector via multiplication by some constants causes it to not converge for > 50k iterations.

Rather than systematically determine the failure modes, is there any info on requirements on input vector, such as normalization, etc.? I see normalization required for LSE's but for gaussian?

Thanks

Please login to add a comment or rating.
Updates
29 Apr 2004

fixed normalization ratio of "fit_ML_normal.m" (and "plot_normal.m"), and added an example to it's help

make sure you have the paths set correct.

Tag Activity for this File
Tag Applied By Date/Time
approximation Ohad Gal 22 Oct 2008 07:10:13
interpolation Ohad Gal 22 Oct 2008 07:10:13
fit Ohad Gal 22 Oct 2008 07:10:13
normal Ohad Gal 22 Oct 2008 07:10:13
maxwell Ohad Gal 22 Oct 2008 07:10:13
mixedgaussian Ohad Gal 22 Oct 2008 07:10:13
lognormal Ohad Gal 22 Oct 2008 07:10:13
laplace Ohad Gal 22 Oct 2008 07:10:13
rayleigh Ohad Gal 22 Oct 2008 07:10:13
what about left truncated normal distribution Om Ken 01 Nov 2008 07:57:22
what about left truncated normal distribution Vijay Ganesh 15 Aug 2009 09:52:10
approximation C.S. Huang 12 Nov 2009 10:40:09
fit C.S. Huang 12 Nov 2009 10:40:10
interpolation C.S. Huang 12 Nov 2009 10:40:11
laplace C.S. Huang 12 Nov 2009 10:40:12
lognormal C.S. Huang 12 Nov 2009 10:40:14
maxwell C.S. Huang 12 Nov 2009 10:40:15
mixedgaussian C.S. Huang 12 Nov 2009 10:40:17
normal C.S. Huang 12 Nov 2009 10:40:19
rayleigh C.S. Huang 12 Nov 2009 10:40:20
what about left truncated normal distribution C.S. Huang 12 Nov 2009 10:40:22
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com