MATLAB Answers

Non-linear Multivariate regression using genetic algorithm

50 views (last 30 days)
Tad2020 on 19 Jan 2020
Commented: Tad2020 on 28 Jan 2020 at 11:35
I would like to perform non-linear multivariate regression using genetic algorithm in matlab.
I have five independent variables and one response. How can I do non-linear regression by minimizing the mean square error in matlab using genetic algorithm?
R = f (x1, x2, x3, x4)
I want to fit the data to the equation similar to the following:
Thus, my objective is to find the constants C1, C2, C3,..., C21 using the GA in matlab by minimizing the difference between the actual response and the response from the model.


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 19 Jan 2020
One (very basic) approach:
xd = rand(10,1); % Create Dependent Variable
xi = rand(10,4); % Create Independent Variable Matrix
R = @(b,x) b(1).*sin(b(2).*x(:,1)) + b(3).*exp(b(4).*x(:,2)) + b(5).*cos(b(6).*x(:,3)) - b(7).*x(:,4); % Objective Function
ftnsfcn = @(b) norm(xd - R(b,xi)); % Fitness Function
B = ga(ftnsfcn, 7); % Genetic Algorithm Call
The idea is to create a matrix of the independent variables, then refer to them by their respective columns (my preference).
There are many ways to customise the ga population and other parameters to get interim outputs and create a specific initial population, among others. The ga function will search the parameter space for the best set, so being rigorous about defining a range for them is only necessary if they are widely varying in their expected amplitudes.


Show 7 older comments
Star Strider
Star Strider on 21 Jan 2020
I will give it a try with ga a bit later, since the requires a bit of time to run.
This is going to be extremely difficult to fit with a gradient-descent algorithm such as nlinfit.
Follow-up — (21 Jan 2020 at 21:21)
I thought that was a different objective function. It is the same objective function I used to get the result I posted earlier, with ga.
For nlinfit, use the ‘C parameters’ I posted as your ‘B0’. You may be able to refine the parameter estimates beyond those the ga function was able to estimate, providing even better parameter estimates, and allowing you to estimate the parameter confidence intervals, as well as confidence intervals on the fit. (The ga function option described in When to Use a Hybrid Function allows parameter estimates to ‘fine-tune’ its parameter estimates. I do not routinely use that option.)
Tad2020 on 26 Jan 2020 at 15:15
Dear Star Srider,
Hope you are doing great.
Please, how to use ga if I want to minimize two variables at the same time.
Examaple: determining the values of the parameters C1,C2, C3,... by minimizing the mean square error and at the same time the ratio of the predicted to the measured data of the response.
Star Strider
Star Strider on 26 Jan 2020 at 15:23
Minimising the mean squared error should do both.

Sign in to comment.

More Answers (1)

Alex Sha
Alex Sha on 28 Jan 2020 at 10:59
The GA toolbox in Matlab is not an ideal tool for curve fitting with the goal of global optimizatiom result. Refer the result below, it should be the global solution which GA may never get.
Root of Mean Square Error (RMSE): 0.00114090675219561
Sum of Squared Residual: 0.000298082021740069
Correlation Coef. (R): 1
R-Square: 1
Adjusted R-Square: 1
Determination Coef. (DC): 1
Chi-Square: 1.30802089664868E-6
F-Statistic: 1.9563957244377E19
Parameter Best Estimate
---------- -------------
c1 1.21488501004067
c2 1.45076972134303
c3 2.07995659264768
c4 1.69518420103036
c5 1.97997575301966
c6 1.97999531406562
c7 6.30000528873042
c8 9.02324638354842


Tad2020 on 28 Jan 2020 at 11:03
Dear Alex Sha,
Many thanks. Could you please let me know the software or method you have used so that I can use it.
Many thanks again.
Alex Sha
Alex Sha on 28 Jan 2020 at 11:27
This comment was flagged by 2 contributors
Hi, Tad2020, the result above was obtained by using a software package named "1stOpt", it is a global optimization package, idea for problems such as equation solving and curve fitting.
Tad2020 on 28 Jan 2020 at 11:35
Thanks again. I will try to get the software if it is available.

Sign in to comment.

Sign in to answer this question.