简体   繁体   中英

Fitting sigmoid to data

There are many curve fitting and interpolation tools like polyfit (or even this nice logfit toolbox I found here ), but I can't seem to find anything that will fit a sigmoid function to my xy data.

Does such a tool exist or do I need to make my own?

If you have the Statistics Toolbox installed, you can use nonlinear regression with nlinfit :

sigfunc = @(A, x)(A(1) ./ (A(2) + exp(-x)));
A0 = ones(size(A)); %// Initial values fed into the iterative algorithm
A_fit = nlinfit(x, y, sigfunc, A0);

Here sigfunc is just an example for a sigmoid function, and A is the vector of the fitting coefficients.

nlinfit , and especially gatool , are big hammers for this problem. A sigmoid is not a specific function. Most commonly it is taken to be the same as the logistic function (also often the most efficient to calculate):

y = 1./(1+exp(-x));

or a generalized logistic. But all manner of curves can have sigmoidal shapes . If you know if your data corresponds to one in particular, fitting can be improved and more efficient methods can be applied. For example, the error function ( erf ) has a sigmoidal shape and shows up in the CDF of the normal distribution . If you know that your data is the result of a Gaussian process (ie, the data is the CDF) and you have the Stats toolbox, you can use the normfit function. This function is based on maximum likelihood estimation (MLE). If you end up needing to write a custom fitting function - say, for performance reasons - I'd investigate MLE techniques for the particular form of sigmoid that you'd like to fit.

I would suggest you use MATLAB's Global Optimization Toolbox , and in particular the Genetic Algorithm Solver , which you can use for your problem by optimizing (= finding the best fit for your data) the sigmoid function's parameters through genetic algorithm. It has a GUI that is easy to use.

The Genetic Algorithm Solver 's GUI, which you can call using gatool : 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM