Using Multistart in an unconstrained optimization
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, suprisingly working with this model I have imposed nonlinear and upper/lower bounds in a separate script and have come up with a better fit. I am surprised to find that the unconstrained case, the code I have here, is not giving me correct solutions. I tried messing with ms.XTolerance and the functionTolerance but nothing helped (since I have only seen an exit flag of 2). It does not seem like multistart is minimizing my objective function, as the error for a solution is a massive number.
Is there anything you all see wrong, or an explanation as to why this is happening? (I would preferably use lsqnonlin, not lsqcurvefit just to stay consistent)
D = readmatrix('Treloar_Data.xlsx');
x = D(:,1);
y = D(:,2);
% Define Ogden Function
ogden_funct1 = @(c) (c(1).*(x.^(c(4)-1)-x.^(-1/2*c(4)-1)) + ...
c(2).*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3).*(x.^(c(6)-1)-x.^(-1/2*c(6)-1))) - y;
% Initial_Guess
Initial_Guess1 = [1 1 1 1 1 1];
lb =[];
ub=[];
%Run multistart
problem1 = createOptimProblem('lsqnonlin', 'objective', ogden_funct1, 'x0', Initial_Guess1, 'lb', lb ,'ub', ub);
ms = MultiStart; ms.XTolerance =1*10.^(-13); ms.FunctionTolerance =1*10.^(-13);
[xmultinonlin,errormultinonlin] =run(ms,problem1, 1000)
% Plot Our Data
ogden_plot_func =@(c) c(1).*(x.^(c(4)-1)-x.^((-1)/2*c(4)-1)) + ...
c(2).*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3).*(x.^(c(6)-1)-x.^((-1)/2*c(6)-1));
plot(x, y, 'ko', x, ...
ogden_plot_func(xmultinonlin), '-b')
legend('Data', 'lsqnonlin-Unconstrained')
title('Ogden Model Unconstrained')
xlabel('Stretch')
ylabel('Stress')
댓글 수: 0
채택된 답변
Alan Weiss
2022년 7월 20일
편집: Alan Weiss
2022년 7월 20일
This type of problem is well-known to be numerically touchy, and to have multiple local minima. You really should give bounds, the tightest ones you can. Otherwise, MultiStart has way too large a space to search. And let MultiStart run for more iterations than I show (I gave 500 as a limit because of the limitations of online publishing, 50 second time limit).
x = [1.0000
1.0100
1.1200
1.2400
1.3900
1.6100
1.8900
2.1700
2.4200
3.0100
3.5800
4.0300
4.7600
5.3600
5.7600
6.1600
6.4000
6.6200
6.8700
7.0500
7.1600
7.2700
7.4300
7.5000
7.6100];
y = [ 0
0.0300
0.1400
0.2300
0.3200
0.4100
0.5000
0.5800
0.6700
0.8500
1.0400
1.2100
1.5800
1.9400
2.2900
2.6700
3.0200
3.3900
3.7500
4.1200
4.4700
4.8500
5.2100
5.5700
6.3000];
% Define Ogden Function
ogden_funct1 = @(c) (c(1).*(x.^(c(4)-1)-x.^(-1/2*c(4)-1)) + ...
c(2).*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3).*(x.^(c(6)-1)-x.^(-1/2*c(6)-1))) - y;
% Initial_Guess
Initial_Guess1 = [1 1 1 1 1 1];
lb =-5*Initial_Guess1;
ub=5*Initial_Guess1;
rng(1)
%Run multistart
problem1 = createOptimProblem('lsqnonlin', 'objective', ogden_funct1, 'x0', Initial_Guess1, 'lb', lb ,'ub', ub);
ms = MultiStart;
% ms.XTolerance =1*10.^(-13); ms.FunctionTolerance =1*10.^(-13);
[xmultinonlin,errormultinonlin] =run(ms,problem1, 500)
% Plot Our Data
ogden_plot_func =@(c) c(1).*(x.^(c(4)-1)-x.^((-1)/2*c(4)-1)) + ...
c(2).*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3).*(x.^(c(6)-1)-x.^((-1)/2*c(6)-1));
plot(x, y, 'ko', x, ...
ogden_plot_func(xmultinonlin), '-b')
legend('Data', 'lsqnonlin+Bounds')
title('Ogden Model With Bounds')
xlabel('Stretch')
ylabel('Stress')
Alan Weiss
MATLAB mathematical toolbox documentation
추가 답변 (1개)
Torsten
2022년 7월 19일
편집: Torsten
2022년 7월 19일
D = [1.00 0.00
1.01 0.03
1.12 0.14
1.24 0.23
1.39 0.32
1.61 0.41
1.89 0.50
2.17 0.58
2.42 0.67
3.01 0.85
3.58 1.04
4.03 1.21
4.76 1.58
5.36 1.94
5.76 2.29
6.16 2.67
6.40 3.02
6.62 3.39
6.87 3.75
7.05 4.12
7.16 4.47
7.27 4.85
7.43 5.21
7.50 5.57
7.61 6.30];
x = D(:,1);
y = D(:,2);
% Define Ogden Function
ogden_funct1 = @(c) (c(1).*(x.^(c(4)-1)-x.^(-1/2*c(4)-1)) + ...
c(2).*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3).*(x.^(c(6)-1)-x.^(-1/2*c(6)-1))) - y;
% Initial_Guess
Initial_Guess1 = [-1.7720e+01 4.7842e-02 6.7178e-01 -1.7202e-01 3.5402e+00 -3.7330e+00];
lb =[];
ub=[];
options = optimset('MaxFunEvals',10000);
c = lsqnonlin(ogden_funct1,Initial_Guess1,lb,ub,options)
plot(x, y, 'ko', x, ...
ogden_funct1(c)+y, '-b')
댓글 수: 7
Alex Sha
2022년 7월 21일
Hi, Reed, it is ture that the results provided above are not from Matlab.
Matlab is a great and popular math software product, including me, widely used around the world. However, in some areas, for example, the global optimization algorithms or the tool of global optimization, the improvements are relatively minor and no longer have an advantage over some other products, this makes some of Matlab function or toolboxes (lsqcurvefit, gatool, fsolve, vpasolve, cftool...) to be difficult to get optimal results for some problems, for example, the curve fitting problem in this topic, even the result given by Alan Weiss is not correct.
Because of forum rules, it is not appropriate to discuss software other than matlab here, so only giving the right answer, and hope Mathworks will keep to improve Matlab more powerful.
참고 항목
카테고리
Help Center 및 File Exchange에서 Global or Multiple Starting Point Search에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!